Skip to content

Commit

Permalink
Merge pull request #23358 from storybookjs/valentin/require-patch-no-…
Browse files Browse the repository at this point in the history
…patch-label

DangerJS: Require either 'patch:no', 'patch:yes' or 'patch:done' label
  • Loading branch information
valentinpalkovic authored Jul 11, 2023
2 parents a46cbb1 + a9a9119 commit e1350e2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
15 changes: 11 additions & 4 deletions scripts/dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +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 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)}`);
}
};

Expand Down
6 changes: 3 additions & 3 deletions scripts/release/__tests__/generate-pr-description.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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)"
`);
});
Expand All @@ -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\`"
`);
Expand Down
8 changes: 4 additions & 4 deletions scripts/release/__tests__/label-patches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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.",
]
`);
});
4 changes: 2 additions & 2 deletions scripts/release/generate-pr-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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}`;
};
Expand Down
8 changes: 4 additions & 4 deletions scripts/release/label-patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions scripts/release/pick-patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface PR {
}

const LABEL = {
PATCH: 'patch',
PICKED: 'picked',
PATCH: 'patch:yes',
PICKED: 'patch:done',
DOCUMENTATION: 'documentation',
} as const;

Expand Down
2 changes: 1 addition & 1 deletion scripts/release/unreleased-changes-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ program
'-F, --from <version>',
'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({
Expand Down
4 changes: 2 additions & 2 deletions scripts/release/utils/get-unpicked-prs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion scripts/release/write-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program
'write changelog based on merged PRs and commits. the <version> argument describes the changelog entry heading, but NOT which commits/PRs to include, must be a semver string'
)
.arguments('<version>')
.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 <tag>',
'Which tag or commit to generate changelog from, eg. "7.0.7". Leave unspecified to select latest released tag in git history'
Expand Down

0 comments on commit e1350e2

Please sign in to comment.