Skip to content

Commit

Permalink
Add publishStatusCommentOnAbort
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Mar 19, 2022
1 parent 10e0ca0 commit 80a741a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
11 changes: 7 additions & 4 deletions src/lib/github/v3/createStatusComment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@ describe('getCommentBody', () => {
} as BackportResponse,
});

it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
const params = getParams({ publishStatusCommentOnFailure: true });
it('posts a comment when `publishStatusCommentOnAbort = true`', () => {
const params = getParams({
publishStatusCommentOnAbort: true,
publishStatusCommentOnFailure: true,
});
expect(getCommentBody(params)).toMatchInlineSnapshot(`
"## ⚪ Backport skipped
The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
Expand All @@ -420,8 +423,8 @@ describe('getCommentBody', () => {
`);
});

it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
const params = getParams({ publishStatusCommentOnFailure: false });
it('does not post a comment when `publishStatusCommentOnAbort = false`', () => {
const params = getParams({ publishStatusCommentOnAbort: false });
expect(getCommentBody(params)).toBe(undefined);
});
});
Expand Down
27 changes: 9 additions & 18 deletions src/lib/github/v3/createStatusComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,7 @@ export async function createStatusComment({
options: ValidConfigOptions;
backportResponse: BackportResponse;
}): Promise<void> {
const {
githubApiBaseUrlV3,
repoName,
repoOwner,
accessToken,
publishStatusCommentOnFailure,
publishStatusCommentOnSuccess,
} = options;

if (
(!publishStatusCommentOnFailure && !publishStatusCommentOnSuccess) ||
options.dryRun
) {
return;
}
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken } = options;

try {
const octokit = new Octokit({
Expand Down Expand Up @@ -81,22 +67,27 @@ export function getCommentBody({
repoName,
repoOwner,
autoMerge,
publishStatusCommentOnSuccess,
publishStatusCommentOnAbort,
publishStatusCommentOnFailure,
publishStatusCommentOnSuccess,
} = options;

// TODO; add new cli args to specify whether to post comments for successful and failures
// eg. in addition to `--noStatusComment` add `--noFailureStatusComment` and `--noSuccessStatusComment` where the former will overwrite the two latter

const didAllBackportsSucceed =
backportResponse.status === 'success' &&
backportResponse.results.every((r) => r.status === 'success');

if (
// don't publish on dry-run
options.dryRun ||
// don't publish comment regardless if it succeeded or failed
(!publishStatusCommentOnFailure && !publishStatusCommentOnSuccess) ||
// dont publish comment if all backports suceeded
(didAllBackportsSucceed && !publishStatusCommentOnSuccess) ||
// dont publish comment if some failed
(!didAllBackportsSucceed && !publishStatusCommentOnFailure)
(!didAllBackportsSucceed && !publishStatusCommentOnFailure) ||
(backportResponse.status === 'aborted' && !publishStatusCommentOnAbort)
) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ type Options = Partial<{
prFilter: string;
projectConfigFile: string; // only available via cli and module options (not project or global config)
prTitle: string;
publishStatusCommentOnSuccess: boolean;
publishStatusCommentOnAbort: boolean;
publishStatusCommentOnFailure: boolean;
publishStatusCommentOnSuccess: boolean;
pullNumber: number;
repoForkOwner: string;
repoName: string;
Expand Down
1 change: 1 addition & 0 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ export function getOptionsFromCliArgs(processArgs: readonly string[]) {
noVerify: verify ?? noVerify,
publishStatusCommentOnSuccess: noStatusComment === true ? false : undefined,
publishStatusCommentOnFailure: noStatusComment === true ? false : undefined,
publishStatusCommentOnAbort: noStatusComment === true ? false : undefined,
interactive: nonInteractive === true ? false : undefined,
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ describe('getOptions', () => {
multipleBranches: true,
multipleCommits: false,
noVerify: true,
publishStatusCommentOnAbort: false,
publishStatusCommentOnSuccess: true,
publishStatusCommentOnFailure: true,
publishStatusCommentOnFailure: false,
repoForkOwner: 'john.diller',
repoName: 'kibana',
repoOwner: 'elastic',
Expand Down
3 changes: 2 additions & 1 deletion src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export const defaultConfigOptions = {
multipleBranches: true,
multipleCommits: false,
noVerify: true,
publishStatusCommentOnAbort: false,
publishStatusCommentOnSuccess: true,
publishStatusCommentOnFailure: true,
publishStatusCommentOnFailure: false,
resetAuthor: false,
reviewers: [] as Array<string>,
sourcePRLabels: [] as string[],
Expand Down

0 comments on commit 80a741a

Please sign in to comment.