Skip to content

Commit

Permalink
Add —noUnmergedBackportsHelp option (#522)
Browse files Browse the repository at this point in the history
* Add `—noUnmergedBackportsHelp` option

* Fix snapshots
  • Loading branch information
sorenlouv authored Jan 2, 2025
1 parent 8c27920 commit 3351856
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/lib/github/v3/createStatusComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function getCommentBody({
repoOwner,
autoMerge,
isRepoPrivate,
noUnmergedBackportsHelp,
publishStatusCommentOnAbort,
publishStatusCommentOnFailure,
publishStatusCommentOnSuccess,
Expand Down Expand Up @@ -171,7 +172,7 @@ ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
return [
'❌',
result.targetBranch,
unmergedBackportsSection
unmergedBackportsSection && !noUnmergedBackportsHelp
? `**${backportFailedLabel}**${unmergedBackportsSection}`
: backportFailedLabel,
];
Expand Down
5 changes: 3 additions & 2 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Options = Partial<{
cherrypickRef: boolean;
commitConflicts: boolean;
commitPaths: string[];
copySourcePRLabels: boolean;
copySourcePRReviewers: boolean;
details: boolean;
dir: string;
draft: boolean;
Expand Down Expand Up @@ -67,10 +69,9 @@ type Options = Partial<{
sha: string | string[];
signoff: boolean;
skipRemoteConfig: boolean;
noUnmergedBackportsHelp: boolean;
sourceBranch: string;
sourcePRLabels: string[];
copySourcePRLabels: boolean;
copySourcePRReviewers: boolean;
targetBranchChoices: TargetBranchChoiceOrString[];
targetBranches: string[];
targetPRLabels: string[];
Expand Down
5 changes: 5 additions & 0 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ export function getOptionsFromCliArgs(processArgs: readonly string[]) {
type: 'string',
})

.option('noUnmergedBackportsHelp', {
description: 'Do not list the unmerged backports in PR comment',
type: 'boolean',
})

.option('sourceBranch', {
description: `Specify a non-default branch (normally "master") to backport from`,
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ describe('getOptions', () => {
maxNumber: 10,
multipleBranches: true,
multipleCommits: false,
noUnmergedBackportsHelp: false,
noVerify: true,
publishStatusCommentOnAbort: false,
publishStatusCommentOnFailure: false,
Expand Down
13 changes: 9 additions & 4 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const defaultConfigOptions = {
reviewers: [] as Array<string>,
signoff: false,
sourcePRLabels: [] as string[],
noUnmergedBackportsHelp: false,
targetBranchChoices: [] as TargetBranchChoiceOrString[],
targetBranches: [] as string[],
targetPRLabels: [] as string[],
Expand Down Expand Up @@ -237,11 +238,15 @@ export function getActiveOptionsFormatted(options: ValidConfigOptions) {
customOptions.push(['pullNumber', `${options.pullNumber}`]);
}

if (options.author && options.author !== options.authenticatedUsername) {
if (options.sha) {
customOptions.push(['sha', `${options.sha}`]);
}

if (options.author) {
customOptions.push(['author', `${options.author}`]);
}

if (options.autoMerge !== defaultConfigOptions.autoMerge) {
if (options.autoMerge === true) {
customOptions.push(['autoMerge', `${options.autoMerge}`]);
}

Expand All @@ -259,7 +264,7 @@ export function getActiveOptionsFormatted(options: ValidConfigOptions) {

return (
customOptions
.map(([key, value]) => `${chalk.bold(key)}: ${value}`)
.join(' ') + `\n`
.map(([key, value]) => `${key}: ${chalk.bold(value)}`)
.join(' 🔹 ') + `\n`
);
}
6 changes: 3 additions & 3 deletions src/test/e2e/cli/date-filters.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('date filters (dateSince, dateUntil)', () => {
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/backport-e2e sourceBranch: master since: 2020-08-15T10:00:00.000Z until: 2020-08-15T10:30:00.000Z
"repo: backport-org/backport-e2e 🔹 sourceBranch: master 🔹 author: sorenlouv 🔹 since: 2020-08-15T10:00:00.000Z 🔹 until: 2020-08-15T10:30:00.000Z
? Select commit (Use arrow keys)
❯ 1. Bump to 8.0.0
Expand All @@ -42,7 +42,7 @@ describe('date filters (dateSince, dateUntil)', () => {
});

expect(outputWithoutPrFilter).toMatchInlineSnapshot(`
"repo: elastic/kibana sourceBranch: main autoMerge: true since: 2023-09-01T00:00:00.000Z until: 2023-10-01T00:00:00.000Z
"repo: elastic/kibana 🔹 sourceBranch: main 🔹 author: sorenlouv 🔹 autoMerge: true 🔹 since: 2023-09-01T00:00:00.000Z 🔹 until: 2023-10-01T00:00:00.000Z
? Select commit (Use arrow keys)
❯ 1. [APM] Add support for versioned APIs in diagnostics tool (#167050)
Expand All @@ -58,7 +58,7 @@ describe('date filters (dateSince, dateUntil)', () => {
);

expect(outputWithPrFilter).toMatchInlineSnapshot(`
"repo: elastic/kibana sourceBranch: main autoMerge: true since: 2023-09-01T00:00:00.000Z until: 2023-10-01T00:00:00.000Z
"repo: elastic/kibana 🔹 sourceBranch: main 🔹 author: sorenlouv 🔹 autoMerge: true 🔹 since: 2023-09-01T00:00:00.000Z 🔹 until: 2023-10-01T00:00:00.000Z
? Select commit (Use arrow keys)
❯ 1. [APM] Paginate big traces (#165584) 8.10"
Expand Down
6 changes: 3 additions & 3 deletions src/test/e2e/cli/different-merge-strategies.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('different-merge-strategies', () => {
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/different-merge-strategies sourceBranch: main maxNumber: 20
"repo: backport-org/different-merge-strategies 🔹 sourceBranch: main 🔹 author: sorenlouv 🔹 maxNumber: 20
? Select commit (Use arrow keys)
❯ 1. Downsides with "Rebase and merge"
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('different-merge-strategies', () => {
it('runs to completion without errors', () => {
expect(output).toMatchInlineSnapshot(`
"- Initializing...
repo: backport-org/different-merge-strategies sourceBranch: main pullNumber: 9
repo: backport-org/different-merge-strategies 🔹 sourceBranch: main 🔹 pullNumber: 9 🔹 author: sorenlouv
? Select pull request Merge pull request #9 from backport-org/many-merge-commits
✔ 100% Cloning repository from github.com (one-time operation)
Expand Down Expand Up @@ -191,7 +191,7 @@ View pull request: this-is-a-dry-run"
it('has the right output', async () => {
expect(output).toMatchInlineSnapshot(`
"- Initializing...
repo: backport-org/different-merge-strategies sourceBranch: main pullNumber: 9
repo: backport-org/different-merge-strategies 🔹 sourceBranch: main 🔹 pullNumber: 9 🔹 author: sorenlouv
? Select pull request Merge pull request #9 from backport-org/many-merge-commits
✔ 100% Cloning repository from github.com (one-time operation)
Expand Down
8 changes: 5 additions & 3 deletions src/test/e2e/cli/entrypoint.cli.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Options:
authenticated user [string]
--repo, --upstream Repo owner and name [string]
--sha, --commit Commit sha to backport [string]
--noUnmergedBackportsHelp Do not list the unmerged backports in PR
comment [boolean]
--sourceBranch Specify a non-default branch (normally
"master") to backport from [string]
--sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
Expand Down Expand Up @@ -150,7 +152,7 @@ Or contact me directly: "
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/backport-e2e sourceBranch: master
"repo: backport-org/backport-e2e 🔹 sourceBranch: master 🔹 author: sorenlouv
? Select commit (Use arrow keys)
❯ 1. Add sheep emoji (#9) 7.8
Expand Down Expand Up @@ -179,7 +181,7 @@ Or contact me directly: "
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/backport-e2e sourceBranch: master maxNumber: 6
"repo: backport-org/backport-e2e 🔹 sourceBranch: master 🔹 author: sorenlouv 🔹 maxNumber: 6
? Select commit (Use arrow keys)
❯ 1. Add sheep emoji (#9) 7.8
Expand All @@ -205,7 +207,7 @@ Or contact me directly: "
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/backport-e2e sourceBranch: 7.x maxNumber: 6
"repo: backport-org/backport-e2e 🔹 sourceBranch: 7.x 🔹 author: sorenlouv 🔹 maxNumber: 6
? Select commit (Use arrow keys)
❯ 1. Add 🍏 emoji (#5) (#6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('interactive error handling', () => {
stringAfter: '<BACKPORT_DIR>',
}),
).toMatchInlineSnapshot(`
"repo: backport-org/repo-with-conflicts sourceBranch: main pullNumber: 12
"repo: backport-org/repo-with-conflicts 🔹 sourceBranch: main 🔹 pullNumber: 12 🔹 author: sorenlouv
Backporting to 7.x:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('gracefully handle corrupted repo', () => {
// second run: backport should re-create remotes and branches correctly
expect(output).toMatchInlineSnapshot(`
"- Initializing...
repo: backport-org/integration-test sourceBranch: master
repo: backport-org/integration-test 🔹 sourceBranch: master 🔹 sha: 16cfd987b82f49a79ebc663506f5d215b7a81c5c 🔹 author: sorenlouv
? Select commit Bump to 8.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/repo-with-backportrc-removed sourceBranch: main
"repo: backport-org/repo-with-backportrc-removed 🔹 sourceBranch: main 🔹 author: sorenlouv
? Select commit (Use arrow keys)
❯ 1. Rename README.me to README.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('backport-org/repo-with-changing-branchLabelMapping', () => {
);

expect(output).toMatchInlineSnapshot(`
"repo: backport-org/repo-with-changing-branchLabelMapping sourceBranch: main pullNumber: 6
"repo: backport-org/repo-with-changing-branchLabelMapping 🔹 sourceBranch: main 🔹 pullNumber: 6 🔹 author: sorenlouv
? Select branch (Press <space> to select, <a> to toggle all, <i> to invert
selection, and <enter> to proceed)
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/cli/test-that-repo-can-be-cloned.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('test-that-repo-can-be-cloned', () => {
expect(output).toContain('Cloning repository from github.com');
expect(output).toMatchInlineSnapshot(`
"- Initializing...
repo: backport-org/test-that-repo-can-be-cloned sourceBranch: main pullNumber: 1
repo: backport-org/test-that-repo-can-be-cloned 🔹 sourceBranch: main 🔹 pullNumber: 1 🔹 author: sorenlouv
? Select pull request Beginning of a beautiful repo (#1)
✔ 100% Cloning repository from github.com (one-time operation)
Expand All @@ -56,7 +56,7 @@ View pull request: this-is-a-dry-run"
expect(output).not.toContain('Cloning repository from github.com');
expect(output).toMatchInlineSnapshot(`
"- Initializing...
repo: backport-org/test-that-repo-can-be-cloned sourceBranch: main pullNumber: 1
repo: backport-org/test-that-repo-can-be-cloned 🔹 sourceBranch: main 🔹 pullNumber: 1 🔹 author: sorenlouv
? Select pull request Beginning of a beautiful repo (#1)
Expand Down

0 comments on commit 3351856

Please sign in to comment.