From 5399a68c65a5205c9a7cddc154951827b4691ff5 Mon Sep 17 00:00:00 2001 From: Filipe Ferreira Date: Thu, 4 Jul 2024 12:55:48 +0100 Subject: [PATCH 1/3] fix: add GITLAB_COMMENT_CUSTOM_LINKS env variable --- README.md | 1 + src/comment.ts | 17 ++++++++++++++--- src/env.ts | 2 ++ src/types.ts | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 50683cf2..052373ab 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitl 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 GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI DEBUG_GITLAB_CREDENTIAL # optional, default `false` +GITLAB_COMMENT_CUSTOM_LINKS # optional, allow the linkS for the absent comment to be overwritten ``` ### Example workflow diff --git a/src/comment.ts b/src/comment.ts index 5dea359a..dcf6a083 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -65,6 +65,8 @@ const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => { ` } +const useCustomLinks = env.GITLAB_COMMENT_CUSTOM_LINKS !== 'false' + const getAbsentMessage = ( commitSha: string, addChangesetUrl: string, @@ -77,10 +79,15 @@ Merging this MR will not cause a version bump for any packages. If these changes ${getReleasePlanMessage(releasePlan)} +${ + useCustomLinks + ? env.GITLAB_COMMENT_CUSTOM_LINKS + : ` [Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md). [Click here if you're a maintainer who wants to add a changeset to this MR](${addChangesetUrl}) - +` +} __${generatedByBotNote}__ ` @@ -95,11 +102,15 @@ Latest commit: ${commitSha} **The changes in this MR will be included in the next version bump.** ${getReleasePlanMessage(releasePlan)} - +${ + useCustomLinks + ? env.GITLAB_COMMENT_CUSTOM_LINKS + : ` Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md). [Click here if you're a maintainer who wants to add another changeset to this MR](${addChangesetUrl}) - +` +} __${generatedByBotNote}__ ` diff --git a/src/env.ts b/src/env.ts index 4ac7b289..73b61b4a 100644 --- a/src/env.ts +++ b/src/env.ts @@ -19,6 +19,8 @@ export const env = { process.env.GITLAB_CI_USER_EMAIL || 'gitlab[bot]@users.noreply.gitlab.com', GITLAB_COMMENT_TYPE: process.env.GITLAB_COMMENT_TYPE ?? 'discussion', DEBUG_GITLAB_CREDENTIAL: process.env.DEBUG_GITLAB_CREDENTIAL ?? 'false', + GITLAB_COMMENT_CUSTOM_LINKS: + process.env.GITLAB_COMMENT_CUSTOM_LINKS ?? 'false', // only check for the token if we are explicitly using it // eslint-disable-next-line sonar/function-name diff --git a/src/types.ts b/src/types.ts index dd3932aa..9f2e75f1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,6 +22,7 @@ export type Env = GitLabCIPredefinedVariables & GITLAB_COMMENT_TYPE: LooseString<'discussion' | 'note'> GITLAB_ADD_CHANGESET_MESSAGE?: string DEBUG_GITLAB_CREDENTIAL: LooseString<'1' | 'true'> + GITLAB_COMMENT_CUSTOM_LINKS: string HOME: string NPM_TOKEN?: string From a5db1b4dc0ec2d9ba10bf0932a43ec10abd32ef3 Mon Sep 17 00:00:00 2001 From: Filipe Ferreira Date: Thu, 4 Jul 2024 12:56:58 +0100 Subject: [PATCH 2/3] chore: release --- .changeset/short-queens-cover.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/short-queens-cover.md diff --git a/.changeset/short-queens-cover.md b/.changeset/short-queens-cover.md new file mode 100644 index 00000000..ab9076e3 --- /dev/null +++ b/.changeset/short-queens-cover.md @@ -0,0 +1,5 @@ +--- +'changesets-gitlab': patch +--- + +Add the following environment variable `GITLAB_COMMENT_CUSTOM_LINKS` to allow user to specify custom links to add to the merge request message instead of the predefined ones. From 95b1def078f9c3357fd36900ba08771960e4bd53 Mon Sep 17 00:00:00 2001 From: Filipe Ferreira Date: Thu, 4 Jul 2024 17:49:40 +0100 Subject: [PATCH 3/3] fix: add ability to run install command to update locks --- README.md | 18 ++++++++++-------- src/env.ts | 4 ++++ src/run.ts | 7 +++++++ src/types.ts | 2 ++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 052373ab..728f905e 100644 --- a/README.md +++ b/README.md @@ -48,14 +48,16 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests GITLAB_HOST # optional, if you're using custom GitLab host, will fallback to `CI_SERVER_URL` if not provided -GITLAB_TOKEN # required, token with accessibility to push -GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token -GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API -GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com` -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 -GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI -DEBUG_GITLAB_CREDENTIAL # optional, default `false` -GITLAB_COMMENT_CUSTOM_LINKS # optional, allow the linkS for the absent comment to be overwritten +GITLAB_TOKEN # required, token with accessibility to push +GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token +GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API +GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com` +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 +GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI +DEBUG_GITLAB_CREDENTIAL # optional, default `false` +GITLAB_COMMENT_CUSTOM_LINKS # optional, allow the linkS for the absent comment to be overwritten +UPDATE_PACKAGE_LOCK_BEFORE_MR # optional, default `false` +UPDATE_PACKAGE_LOCK_SCRIPT # optional, default `npm install` ``` ### Example workflow diff --git a/src/env.ts b/src/env.ts index 73b61b4a..76517306 100644 --- a/src/env.ts +++ b/src/env.ts @@ -21,6 +21,10 @@ export const env = { DEBUG_GITLAB_CREDENTIAL: process.env.DEBUG_GITLAB_CREDENTIAL ?? 'false', GITLAB_COMMENT_CUSTOM_LINKS: process.env.GITLAB_COMMENT_CUSTOM_LINKS ?? 'false', + UPDATE_PACKAGE_LOCK_BEFORE_MR: + process.env.UPDATE_PACKAGE_LOCK_BEFORE_MR ?? 'false', + UPDATE_PACKAGE_LOCK_SCRIPT: + process.env.UPDATE_PACKAGE_LOCK_BEFORE_MR ?? 'npm install', // only check for the token if we are explicitly using it // eslint-disable-next-line sonar/function-name diff --git a/src/run.ts b/src/run.ts index a3522b97..d372d2ce 100644 --- a/src/run.ts +++ b/src/run.ts @@ -10,6 +10,7 @@ import resolveFrom from 'resolve-from' import semver from 'semver' import * as context from './context.js' +import { env } from './env.js' import * as gitUtils from './gitUtils.js' import readChangesetState from './readChangesetState.js' import { @@ -290,6 +291,12 @@ ${ await gitUtils.commitAll(finalCommitMessage) } + // Allow user to update their lockfiles before mr is created + if (env.UPDATE_PACKAGE_LOCK_BEFORE_MR === 'true') { + const script = env.UPDATE_PACKAGE_LOCK_SCRIPT + await exec(script) + } + await gitUtils.push(versionBranch, { force: true }) const searchResult = await api.MergeRequests.all({ diff --git a/src/types.ts b/src/types.ts index 9f2e75f1..bd30303d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,8 @@ export type Env = GitLabCIPredefinedVariables & GITLAB_ADD_CHANGESET_MESSAGE?: string DEBUG_GITLAB_CREDENTIAL: LooseString<'1' | 'true'> GITLAB_COMMENT_CUSTOM_LINKS: string + UPDATE_PACKAGE_LOCK_BEFORE_MR: LooseString<'false' | 'true'> + UPDATE_PACKAGE_LOCK_SCRIPT: string HOME: string NPM_TOKEN?: string