Skip to content

Commit 84d2931

Browse files
committed
fix: add newChangesetTemplateFallback for newer GitLab versions
close #178 related https://gitlab.com/gitlab-org/gitlab/-/issues/532221
1 parent f95aed5 commit 84d2931

File tree

6 files changed

+857
-1981
lines changed

6 files changed

+857
-1981
lines changed

.lintstagedrc.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nano-staged.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '@1stg/nano-staged/tsc'

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@gitbeaker/rest": "^42.2.0",
7474
"@manypkg/get-packages": "^1.1.3",
7575
"commander": "^13.1.0",
76-
"dotenv": "^16.4.7",
76+
"dotenv": "^16.5.0",
7777
"global-agent": "^3.0.0",
7878
"human-id": "^4.1.1",
7979
"markdown-table": "^3.0.4",
@@ -88,18 +88,18 @@
8888
"yaml": "^2.7.1"
8989
},
9090
"devDependencies": {
91-
"@1stg/common-config": "^12.0.0",
91+
"@1stg/common-config": "^13.0.1",
9292
"@changesets/changelog-github": "^0.5.1",
93-
"@changesets/cli": "^2.28.1",
93+
"@changesets/cli": "^2.29.0",
9494
"@commitlint/cli": "^19.8.0",
95-
"@pkgr/rollup": "^6.0.2",
95+
"@pkgr/rollup": "^6.0.3",
9696
"@types/global-agent": "^3.0.0",
9797
"@types/micromatch": "^4.0.9",
98-
"@types/web": "^0.0.216",
98+
"@types/web": "^0.0.218",
9999
"@vitest/coverage-istanbul": "3.1.1",
100100
"clean-pkg-json": "^1.2.1",
101101
"eslint": "^9.24.0",
102-
"lint-staged": "^15.5.0",
102+
"nano-staged": "^0.8.0",
103103
"npm-run-all2": "^7.0.2",
104104
"prettier": "^3.5.3",
105105
"simple-git-hooks": "^2.12.1",
@@ -113,7 +113,6 @@
113113
"yarn-deduplicate": "^6.0.2"
114114
},
115115
"resolutions": {
116-
"es5-ext": "npm:@unes/es5-ext@^0.10.64-1",
117116
"prettier": "^3.5.3"
118117
},
119118
"typeCoverage": {

src/comment.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const ADD_CHANGESET_URL_PLACEHOLDER_REGEXP = /\{\{\s*addChangesetUrl\s*\}\}/
7474
const getAbsentMessage = (
7575
commitSha: string,
7676
addChangesetUrl: string,
77+
newChangesetTemplateFallback: string,
7778
releasePlan: ReleasePlan | null,
7879
) => `### ⚠️ No Changeset found
7980
@@ -91,12 +92,15 @@ ${
9192
[Click here if you're a maintainer who wants to add a changeset to this MR](${addChangesetUrl})`
9293
}
9394
95+
${newChangesetTemplateFallback}
96+
9497
__${generatedByBotNote}__
9598
`
9699

97100
const getApproveMessage = (
98101
commitSha: string,
99102
addChangesetUrl: string,
103+
newChangesetTemplateFallback: string,
100104
releasePlan: ReleasePlan | null,
101105
) => `### 🦋 Changeset detected
102106
@@ -114,16 +118,20 @@ ${
114118
[Click here if you're a maintainer who wants to add another changeset to this MR](${addChangesetUrl})`
115119
}
116120
121+
${newChangesetTemplateFallback}
122+
117123
__${generatedByBotNote}__
118124
`
119125

120-
const getNewChangesetTemplate = (changedPackages: string[], title: string) =>
121-
encodeURIComponent(`---
126+
const getNewChangesetTemplate = (
127+
changedPackages: string[],
128+
title: string,
129+
) => `---
122130
${changedPackages.map(x => `"${x}": patch`).join('\n')}
123131
---
124132
125133
${title}
126-
`)
134+
`
127135

128136
const isMrNote = (
129137
discussionOrNote: DiscussionSchema | MergeRequestNoteSchema,
@@ -201,7 +209,8 @@ async function getNoteInfo(
201209
}
202210

203211
/**
204-
* The `username` used for commenting could be random, if we haven't tested the random `username`, then test it
212+
* The `username` used for commenting could be random, if we haven't tested
213+
* the random `username`, then test it
205214
*
206215
* @see https://docs.gitlab.com/ee/development/internal_users.html
207216
* @see https://github.com/un-ts/changesets-gitlab/issues/145#issuecomment-1860610958
@@ -286,25 +295,44 @@ export const comment = async () => {
286295
}),
287296
] as const)
288297

289-
const addChangesetUrl = `${env.CI_MERGE_REQUEST_PROJECT_URL}/-/new/${mrBranch}?file_name=.changeset/${humanId(
290-
{
291-
separator: '-',
292-
capitalize: false,
293-
},
294-
)}.md&file=${getNewChangesetTemplate(
298+
const newChangesetFileName = `.changeset/${humanId({
299+
separator: '-',
300+
capitalize: false,
301+
})}.md`
302+
303+
const newChangesetTemplate = getNewChangesetTemplate(
295304
changedPackages,
296305
env.CI_MERGE_REQUEST_TITLE,
297-
)}${
306+
)
307+
308+
const addChangesetUrl = `${env.CI_MERGE_REQUEST_PROJECT_URL}/-/new/${mrBranch}?file_name=${newChangesetFileName}&file=${encodeURIComponent(newChangesetTemplate)}${
298309
commitMessage
299310
? '&commit_message=' + encodeURIComponent(commitMessage)
300311
: ''
301312
}`
302313

314+
const newChangesetTemplateFallback = `
315+
If the above link doesn't fill the changeset template file name and content which is [a known regression on GitLab > 16.11](https://gitlab.com/gitlab-org/gitlab/-/issues/532221), you can copy and paste the following template into ${newChangesetFileName} instead:
316+
317+
\`\`\`yaml
318+
${newChangesetTemplate}
319+
\`\`\`
320+
`.trim()
321+
303322
const prComment =
304323
(hasChangeset
305-
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
306-
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan)) +
307-
errFromFetchingChangedFiles
324+
? getApproveMessage(
325+
latestCommitSha,
326+
addChangesetUrl,
327+
newChangesetTemplateFallback,
328+
releasePlan,
329+
)
330+
: getAbsentMessage(
331+
latestCommitSha,
332+
addChangesetUrl,
333+
newChangesetTemplateFallback,
334+
releasePlan,
335+
)) + errFromFetchingChangedFiles
308336

309337
switch (commentType) {
310338
case 'discussion': {

src/context.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* Simulate context in GitHub Actions
3-
*/
1+
// Simulate context in GitHub Actions
42

53
export const projectId = process.env.CI_PROJECT_ID!
64

0 commit comments

Comments
 (0)