Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion .lintstagedrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .nano-staged.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@1stg/nano-staged/tsc'
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@gitbeaker/rest": "^42.2.0",
"@manypkg/get-packages": "^1.1.3",
"commander": "^13.1.0",
"dotenv": "^16.4.7",
"dotenv": "^16.5.0",
"global-agent": "^3.0.0",
"human-id": "^4.1.1",
"markdown-table": "^3.0.4",
Expand All @@ -88,18 +88,18 @@
"yaml": "^2.7.1"
},
"devDependencies": {
"@1stg/common-config": "^12.0.0",
"@1stg/common-config": "^13.0.1",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.28.1",
"@changesets/cli": "^2.29.0",
"@commitlint/cli": "^19.8.0",
"@pkgr/rollup": "^6.0.2",
"@pkgr/rollup": "^6.0.3",
"@types/global-agent": "^3.0.0",
"@types/micromatch": "^4.0.9",
"@types/web": "^0.0.216",
"@types/web": "^0.0.218",
"@vitest/coverage-istanbul": "3.1.1",
"clean-pkg-json": "^1.2.1",
"eslint": "^9.24.0",
"lint-staged": "^15.5.0",
"nano-staged": "^0.8.0",
"npm-run-all2": "^7.0.2",
"prettier": "^3.5.3",
"simple-git-hooks": "^2.12.1",
Expand All @@ -113,7 +113,6 @@
"yarn-deduplicate": "^6.0.2"
},
"resolutions": {
"es5-ext": "npm:@unes/es5-ext@^0.10.64-1",
"prettier": "^3.5.3"
},
"typeCoverage": {
Expand Down
56 changes: 42 additions & 14 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const ADD_CHANGESET_URL_PLACEHOLDER_REGEXP = /\{\{\s*addChangesetUrl\s*\}\}/
const getAbsentMessage = (
commitSha: string,
addChangesetUrl: string,
newChangesetTemplateFallback: string,
releasePlan: ReleasePlan | null,
) => `### ⚠️ No Changeset found

Expand All @@ -91,12 +92,15 @@ ${
[Click here if you're a maintainer who wants to add a changeset to this MR](${addChangesetUrl})`
}

${newChangesetTemplateFallback}

__${generatedByBotNote}__
`

const getApproveMessage = (
commitSha: string,
addChangesetUrl: string,
newChangesetTemplateFallback: string,
releasePlan: ReleasePlan | null,
) => `### 🦋 Changeset detected

Expand All @@ -114,16 +118,20 @@ ${
[Click here if you're a maintainer who wants to add another changeset to this MR](${addChangesetUrl})`
}

${newChangesetTemplateFallback}

__${generatedByBotNote}__
`

const getNewChangesetTemplate = (changedPackages: string[], title: string) =>
encodeURIComponent(`---
const getNewChangesetTemplate = (
changedPackages: string[],
title: string,
) => `---
${changedPackages.map(x => `"${x}": patch`).join('\n')}
---

${title}
`)
`

const isMrNote = (
discussionOrNote: DiscussionSchema | MergeRequestNoteSchema,
Expand Down Expand Up @@ -201,7 +209,8 @@ async function getNoteInfo(
}

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

const addChangesetUrl = `${env.CI_MERGE_REQUEST_PROJECT_URL}/-/new/${mrBranch}?file_name=.changeset/${humanId(
{
separator: '-',
capitalize: false,
},
)}.md&file=${getNewChangesetTemplate(
const newChangesetFileName = `.changeset/${humanId({
separator: '-',
capitalize: false,
})}.md`

const newChangesetTemplate = getNewChangesetTemplate(
changedPackages,
env.CI_MERGE_REQUEST_TITLE,
)}${
)

const addChangesetUrl = `${env.CI_MERGE_REQUEST_PROJECT_URL}/-/new/${mrBranch}?file_name=${newChangesetFileName}&file=${encodeURIComponent(newChangesetTemplate)}${
commitMessage
? '&commit_message=' + encodeURIComponent(commitMessage)
: ''
}`

const newChangesetTemplateFallback = `
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:

\`\`\`yaml
${newChangesetTemplate}
\`\`\`
`.trim()

const prComment =
(hasChangeset
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan)) +
errFromFetchingChangedFiles
? getApproveMessage(
latestCommitSha,
addChangesetUrl,
newChangesetTemplateFallback,
releasePlan,
)
: getAbsentMessage(
latestCommitSha,
addChangesetUrl,
newChangesetTemplateFallback,
releasePlan,
)) + errFromFetchingChangedFiles

switch (commentType) {
case 'discussion': {
Expand Down
4 changes: 1 addition & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Simulate context in GitHub Actions
*/
// Simulate context in GitHub Actions

export const projectId = process.env.CI_PROJECT_ID!

Expand Down
Loading
Loading