Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Environment Variable GITLAB_COMMENT_CUSTOM_LINKS for Custom Merge Request Links #189

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-queens-cover.md
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +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_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`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add more detail about those 2 variables in the documentation.
And add into the PR details why you add it

```

### Example workflow
Expand Down
17 changes: 14 additions & 3 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
</details>`
}

const useCustomLinks = env.GITLAB_COMMENT_CUSTOM_LINKS !== 'false'

const getAbsentMessage = (
commitSha: string,
addChangesetUrl: string,
Expand All @@ -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}__
`

Expand All @@ -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}__
`

Expand Down
6 changes: 6 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ 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',
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
Expand Down
7 changes: 7 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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
UPDATE_PACKAGE_LOCK_BEFORE_MR: LooseString<'false' | 'true'>
UPDATE_PACKAGE_LOCK_SCRIPT: string

HOME: string
NPM_TOKEN?: string
Expand Down