Skip to content

Commit 3df541d

Browse files
committed
feat: add addChangesetUrl placeholder support for custom links
1 parent 4ca179c commit 3df541d

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

.changeset/short-queens-cover.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"changesets-gitlab": minor
33
---
44

5-
feat: add a new optional `GITLAB_COMMENT_CUSTOM_LINKS` environment variable to override the links content referenced in the cli bot comment
5+
feat: add a new optional `GITLAB_COMMENT_CUSTOM_LINKS` environment variable to override the links content referenced in the cli bot comment, use `{{ addChangesetUrl }}` placeholder for the dynamic URL to add a changeset

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ GITLAB_CI_USER_NAME # optional, username with accessibility t
5454
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
5555
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
5656
GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE # optional, automatically resolve added discussion when changeset is present, if you want to always resolve the discussion, you should actually use `GITLAB_COMMENT_TYPE=note` instead, default `true`
57-
GITLAB_COMMENT_CUSTOM_LINKS # optional, override the links content referenced in the cli bot comment
57+
GITLAB_COMMENT_CUSTOM_LINKS # optional, override the links content referenced in the cli bot comment, use {{ addChangesetUrl }} placeholder for the dynamic URL to add a changeset
5858
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
5959
DEBUG_GITLAB_CREDENTIAL # optional, whether to log when setting remote url with sensitive `token` displayed
6060
```

src/comment.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
6464
</details>`
6565
}
6666

67+
const customLinks = env.GITLAB_COMMENT_CUSTOM_LINKS?.trim()
68+
69+
const ADD_CHANGESET_URL_PLACEHOLDER_REGEXP = /\{\{\s*addChangesetUrl\s*\}\}/
70+
6771
const getAbsentMessage = (
6872
commitSha: string,
6973
addChangesetUrl: string,
@@ -77,8 +81,9 @@ Merging this MR will not cause a version bump for any packages. If these changes
7781
${getReleasePlanMessage(releasePlan)}
7882
7983
${
80-
env.GITLAB_COMMENT_CUSTOM_LINKS ||
81-
`[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
84+
customLinks
85+
? customLinks.replace(ADD_CHANGESET_URL_PLACEHOLDER_REGEXP, addChangesetUrl)
86+
: `[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
8287
8388
[Click here if you're a maintainer who wants to add a changeset to this MR](${addChangesetUrl})`
8489
}
@@ -99,8 +104,9 @@ Latest commit: ${commitSha}
99104
${getReleasePlanMessage(releasePlan)}
100105
101106
${
102-
env.GITLAB_COMMENT_CUSTOM_LINKS ||
103-
`Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
107+
customLinks
108+
? customLinks.replace(ADD_CHANGESET_URL_PLACEHOLDER_REGEXP, addChangesetUrl)
109+
: `Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
104110
105111
[Click here if you're a maintainer who wants to add another changeset to this MR](${addChangesetUrl})`
106112
}

0 commit comments

Comments
 (0)