From efffec830d29af416826cb6cc08e1332793f0357 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 7 Jul 2023 14:46:04 +0200 Subject: [PATCH 1/3] Require either 'patch' or 'no-patch' label --- scripts/dangerfile.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/dangerfile.ts b/scripts/dangerfile.ts index 1d80df10e0da..e6d2000c76a9 100644 --- a/scripts/dangerfile.ts +++ b/scripts/dangerfile.ts @@ -47,6 +47,13 @@ const checkRequiredLabels = (labels: string[]) => { } else if (foundLabels.length > 1) { fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`); } + + const patchLabels = ['patch:no', 'patch:yes', 'patch:done']; + if (isEmpty(intersection(patchLabels, labels))) { + fail(`PR is not labeled with one of: ${JSON.stringify(patchLabels)}`); + } else if (foundLabels.length > 1) { + fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`); + } }; const checkPrTitle = (title: string) => { From fbf7b85b54da9e551806d79ca1d14ef8b38d720a Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Tue, 11 Jul 2023 14:40:48 +0200 Subject: [PATCH 2/3] rename patch labels in release flow --- scripts/release/__tests__/generate-pr-description.test.ts | 6 +++--- scripts/release/__tests__/label-patches.test.ts | 8 ++++---- scripts/release/generate-pr-description.ts | 4 ++-- scripts/release/label-patches.ts | 8 ++++---- scripts/release/pick-patches.ts | 4 ++-- scripts/release/unreleased-changes-exists.ts | 2 +- scripts/release/utils/get-unpicked-prs.ts | 4 ++-- scripts/release/write-changelog.ts | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/release/__tests__/generate-pr-description.test.ts b/scripts/release/__tests__/generate-pr-description.test.ts index b96d466514ed..f833c430a08e 100644 --- a/scripts/release/__tests__/generate-pr-description.test.ts +++ b/scripts/release/__tests__/generate-pr-description.test.ts @@ -12,7 +12,7 @@ describe('Generate PR Description', () => { user: 'JReinhold', id: 'pr-id-42', title: 'Some PR title for a bug', - labels: ['bug', 'build', 'other label', 'patch'], + labels: ['bug', 'build', 'other label', 'patch:yes'], commit: 'abc123', pull: 42, links: { @@ -104,7 +104,7 @@ describe('Generate PR Description', () => { "- [ ] **🐛 Bug**: Some PR title for a bug [#42](https://github.com/storybookjs/storybook/pull/42) (will also be patched) - [ ] **✨ Feature Request**: Some PR title for a 'new' feature [#48](https://github.com/storybookjs/storybook/pull/48) - [ ] **⚠️ Direct commit**: Some title for a "direct commit" [22bb11](https://github.com/storybookjs/storybook/commit/22bb11) - - [ ] **📝 Documentation**: Another PR \`title\` for docs [#11](https://github.com/storybookjs/storybook/pull/11) (will also be patched) + - [ ] **📝 Documentation**: Another PR \`title\` for docs [#11](https://github.com/storybookjs/storybook/pull/11) - [ ] **❔ Missing Label**: Some PR title with a missing label [#77](https://github.com/storybookjs/storybook/pull/77)" `); }); @@ -116,7 +116,7 @@ describe('Generate PR Description', () => { "## 🍒 Manual cherry picking needed! The following pull requests could not be cherry-picked automatically because it resulted in merge conflicts. - For each pull request below, you need to either manually cherry pick it, or discard it by removing the "patch" label from the PR and re-generate this PR. + For each pull request below, you need to either manually cherry pick it, or discard it by replacing the "patch:yes" label with "patch:no" on the PR and re-generate this PR. - [ ] [#42](https://github.com/storybookjs/storybook/pull/42): \`git cherry-pick -m1 -x abc123\`" `); diff --git a/scripts/release/__tests__/label-patches.test.ts b/scripts/release/__tests__/label-patches.test.ts index 0ee57a2dbe0e..ddfc0be15c50 100644 --- a/scripts/release/__tests__/label-patches.test.ts +++ b/scripts/release/__tests__/label-patches.test.ts @@ -57,7 +57,7 @@ const pullInfoMock = { pull: 55, commit: '930b47f011f750c44a1782267d698ccdd3c04da3', title: 'Legal: Fix license', - labels: ['documentation', 'patch', 'picked'], + labels: ['documentation', 'patch:yes', 'patch:done'], links: { commit: '[`930b47f011f750c44a1782267d698ccdd3c04da3`](https://github.com/storybookjs/storybook/commit/930b47f011f750c44a1782267d698ccdd3c04da3)', @@ -73,7 +73,7 @@ beforeEach(() => { gitClient.git.log.mockResolvedValue(gitLogMock); gitClient.git.getRemotes.mockResolvedValue(remoteMock); githubInfo.getPullInfoFromCommit.mockResolvedValue(pullInfoMock); - github.getLabelIds.mockResolvedValue({ picked: 'pick-id' }); + github.getLabelIds.mockResolvedValue({ 'patch:done': 'pick-id' }); }); test('it should fail early when no GH_TOKEN is set', async () => { @@ -130,8 +130,8 @@ test('it should label the PR associated with cheery picks in the current branch' "Found latest tag: v7.2.1", "Looking at cherry pick commits since v7.2.1", "Found the following picks : Commit: 930b47f011f750c44a1782267d698ccdd3c04da3 PR: [#55](https://github.com/storybookjs/storybook/pull/55)", - "Labeling the PRs with the picked label...", - "Successfully labeled all PRs with the picked label.", + "Labeling the PRs with the patch:done label...", + "Successfully labeled all PRs with the patch:done label.", ] `); }); diff --git a/scripts/release/generate-pr-description.ts b/scripts/release/generate-pr-description.ts index 363520474e88..1a10ca89197f 100644 --- a/scripts/release/generate-pr-description.ts +++ b/scripts/release/generate-pr-description.ts @@ -90,7 +90,7 @@ export const mapToChangelist = ({ )[0] || 'unknown') as keyof typeof LABELS_BY_IMPORTANCE; return `- [ ] **${LABELS_BY_IMPORTANCE[label]}**: ${change.title} ${change.links.pull}${ - !unpickedPatches && change.labels.includes('patch') ? ' (will also be patched)' : '' + !unpickedPatches && change.labels.includes('patch:yes') ? ' (will also be patched)' : '' }`; }) .join('\n'); @@ -123,7 +123,7 @@ export const mapCherryPicksToTodo = ({ return dedent`## 🍒 Manual cherry picking needed! The following pull requests could not be cherry-picked automatically because it resulted in merge conflicts. - For each pull request below, you need to either manually cherry pick it, or discard it by removing the "patch" label from the PR and re-generate this PR. + For each pull request below, you need to either manually cherry pick it, or discard it by replacing the "patch:yes" label with "patch:no" on the PR and re-generate this PR. ${list}`; }; diff --git a/scripts/release/label-patches.ts b/scripts/release/label-patches.ts index a38f134856bd..dea8e62e469e 100644 --- a/scripts/release/label-patches.ts +++ b/scripts/release/label-patches.ts @@ -63,11 +63,11 @@ export const run = async (_: unknown) => { spinner2.succeed(`Found the following picks 🍒:\n ${commitWithPr.join('\n')}`); - const spinner3 = ora(`Labeling the PRs with the picked label...`).start(); + const spinner3 = ora(`Labeling the PRs with the patch:done label...`).start(); try { - const labelToId = await getLabelIds({ repo, labelNames: ['picked'] }); - await Promise.all(pullRequests.map((pr) => labelPR(pr.id, labelToId.picked))); - spinner3.succeed(`Successfully labeled all PRs with the picked label.`); + const labelToId = await getLabelIds({ repo, labelNames: ['patch:done'] }); + await Promise.all(pullRequests.map((pr) => labelPR(pr.id, labelToId['patch:done']))); + spinner3.succeed(`Successfully labeled all PRs with the patch:done label.`); } catch (e) { spinner3.fail(`Something went wrong when labelling the PRs.`); console.error(e); diff --git a/scripts/release/pick-patches.ts b/scripts/release/pick-patches.ts index fa19a1e347f1..8182ee3fad88 100644 --- a/scripts/release/pick-patches.ts +++ b/scripts/release/pick-patches.ts @@ -29,8 +29,8 @@ interface PR { } const LABEL = { - PATCH: 'patch', - PICKED: 'picked', + PATCH: 'patch:yes', + PICKED: 'patch:done', DOCUMENTATION: 'documentation', } as const; diff --git a/scripts/release/unreleased-changes-exists.ts b/scripts/release/unreleased-changes-exists.ts index c6ea25b80831..59adedbdbb0e 100644 --- a/scripts/release/unreleased-changes-exists.ts +++ b/scripts/release/unreleased-changes-exists.ts @@ -15,7 +15,7 @@ program '-F, --from ', 'Which version/tag/commit to go back and check changes from. Defaults to latest release tag' ) - .option('-P, --unpicked-patches', 'Set to only consider PRs labeled with "patch" label') + .option('-P, --unpicked-patches', 'Set to only consider PRs labeled with "patch:yes" label') .option('-V, --verbose', 'Enable verbose logging', false); const optionsSchema = z.object({ diff --git a/scripts/release/utils/get-unpicked-prs.ts b/scripts/release/utils/get-unpicked-prs.ts index bd8abeb57bc9..ade20ff68af3 100644 --- a/scripts/release/utils/get-unpicked-prs.ts +++ b/scripts/release/utils/get-unpicked-prs.ts @@ -16,7 +16,7 @@ export async function getUnpickedPRs(baseBranch: string, verbose?: boolean): Pro ` query ($owner: String!, $repo: String!, $state: PullRequestState!, $order: IssueOrder!) { repository(owner: $owner, name: $repo) { - pullRequests(states: [$state], labels: ["patch"], orderBy: $order, first: 50, baseRefName: "next") { + pullRequests(states: [$state], labels: ["patch:yes"], orderBy: $order, first: 50, baseRefName: "next") { nodes { id number @@ -60,7 +60,7 @@ export async function getUnpickedPRs(baseBranch: string, verbose?: boolean): Pro })); const unpickedPRs = prs - .filter((pr: any) => !pr.labels.includes('picked')) + .filter((pr: any) => !pr.labels.includes('patch:done')) .filter((pr: any) => pr.branch === baseBranch) .reverse(); diff --git a/scripts/release/write-changelog.ts b/scripts/release/write-changelog.ts index 7481c46e5468..f5521929732a 100644 --- a/scripts/release/write-changelog.ts +++ b/scripts/release/write-changelog.ts @@ -13,7 +13,7 @@ program 'write changelog based on merged PRs and commits. the argument describes the changelog entry heading, but NOT which commits/PRs to include, must be a semver string' ) .arguments('') - .option('-P, --unpicked-patches', 'Set to only consider PRs labeled with "patch" label') + .option('-P, --unpicked-patches', 'Set to only consider PRs labeled with "patch:yes" label') .option( '-F, --from ', 'Which tag or commit to generate changelog from, eg. "7.0.7". Leave unspecified to select latest released tag in git history' From a9a911997d00ad2f43f33f684fb77b0eefd447e5 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Tue, 11 Jul 2023 14:45:44 +0200 Subject: [PATCH 3/3] allow patch:done with patch:yes and patch:no labels --- scripts/dangerfile.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/dangerfile.ts b/scripts/dangerfile.ts index e6d2000c76a9..375f45f176bf 100644 --- a/scripts/dangerfile.ts +++ b/scripts/dangerfile.ts @@ -41,18 +41,18 @@ const checkRequiredLabels = (labels: string[]) => { ); } - const foundLabels = intersection(requiredLabels, labels); - if (isEmpty(foundLabels)) { + const foundRequiredLabels = intersection(requiredLabels, labels); + if (isEmpty(foundRequiredLabels)) { fail(`PR is not labeled with one of: ${JSON.stringify(requiredLabels)}`); - } else if (foundLabels.length > 1) { - fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`); + } else if (foundRequiredLabels.length > 1) { + fail(`Please choose only one of these labels: ${JSON.stringify(foundRequiredLabels)}`); } - const patchLabels = ['patch:no', 'patch:yes', 'patch:done']; - if (isEmpty(intersection(patchLabels, labels))) { - fail(`PR is not labeled with one of: ${JSON.stringify(patchLabels)}`); - } else if (foundLabels.length > 1) { - fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`); + const foundPatchLabels = intersection(['patch:no', 'patch:yes'], labels); + if (isEmpty(foundPatchLabels)) { + fail(`PR is not labeled with one of: ${JSON.stringify(foundPatchLabels)}`); + } else if (foundPatchLabels.length > 1) { + fail(`Please choose only one of these labels: ${JSON.stringify(foundPatchLabels)}`); } };