Skip to content

Commit

Permalink
Show more neutral status when backport is skipped due to missing bran…
Browse files Browse the repository at this point in the history
…ches
  • Loading branch information
sorenlouv committed Jan 23, 2022
1 parent aca231b commit 326d76c
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 111 deletions.
5 changes: 2 additions & 3 deletions src/backportRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export type BackportResponse =
| {
status: 'failure';
commits: Commit[];
errorMessage: string;
error: Error;
error: Error | HandledError;
};

export async function backportRun(
Expand All @@ -37,6 +36,7 @@ export async function backportRun(

// don't show spinner for yargs commands that exit the process without stopping the spinner first
const spinner = ora();

if (!argv.help && !argv.version) {
spinner.start('Initializing...');
}
Expand Down Expand Up @@ -67,7 +67,6 @@ export async function backportRun(
const backportResponse: BackportResponse = {
status: 'failure',
commits,
errorMessage: e.message,
error: e,
};

Expand Down
2 changes: 2 additions & 0 deletions src/runSequentially.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ describe('runSequentially', () => {
This is an automatic backport to \`7.x\` of:
- #55
<!--- Backport version: 1.2.3 -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
"head": "sqren_authenticated:backport/7.x/pr-55",
Expand Down
2 changes: 0 additions & 2 deletions src/runSequentially.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type Result =
// only set for failure
status: 'failure';
targetBranch: string;
errorMessage: string;
error: HandledError;
};

Expand Down Expand Up @@ -56,7 +55,6 @@ export async function runSequentially({
results.push({
targetBranch,
status: 'failure',
errorMessage: e.message,
error: e,
});
consoleLog(e.message);
Expand Down
44 changes: 33 additions & 11 deletions src/services/HandledError.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
import { Commit } from './sourceCommit/parseSourceCommit';

type Meta = {
type: 'merge-conflict-due-to-missing-backports';
commitsWithoutBackports: {
formatted: string;
commit: Commit;
}[];
};
type ErrorAttributes =
| {
code: 'merge-conflict-exception';
commitsWithoutBackports: {
formatted: string;
commit: Commit;
}[];
}
| {
code: 'no-branches-exception' | 'abort-exception';
};

function getMessage(errorAttributes: ErrorAttributes | string): string {
if (typeof errorAttributes === 'string') {
return errorAttributes;
}

switch (errorAttributes.code) {
case 'merge-conflict-exception':
return `Commit could not be cherrypicked due to conflicts`;
case 'no-branches-exception':
return 'There are no branches to backport to. Aborting.';
case 'abort-exception':
return 'Aborted';
}
}

export class HandledError extends Error {
meta?: Meta;
constructor(message: string, meta?: Meta) {
super(message);
attributes?: ErrorAttributes;
constructor(errorAttributes: ErrorAttributes | string) {
super(getMessage(errorAttributes));
Error.captureStackTrace(this, HandledError);
this.name = 'HandledError';
this.meta = meta;

if (typeof errorAttributes !== 'string') {
this.attributes = errorAttributes;
}
}
}
8 changes: 8 additions & 0 deletions src/services/github/v3/createPullRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('getPullRequestBody', () => {
This is an automatic backport to \`7.x\` of:
- #55
<!--- Backport version: 1.2.3 -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
`);
Expand All @@ -47,6 +49,8 @@ describe('getPullRequestBody', () => {
This is an automatic backport to \`7.x\` of:
- My commit message (abcdefgh)
<!--- Backport version: 1.2.3 -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
`);
Expand Down Expand Up @@ -77,6 +81,8 @@ describe('getPullRequestBody', () => {
- #55
- Another commit message (qwertyui)
<!--- Backport version: 1.2.3 -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
`);
Expand Down Expand Up @@ -137,6 +143,8 @@ describe('getPullRequestBody', () => {
- #55
- Another commit message (qwertyui)
<!--- Backport version: 1.2.3 -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
Expand Down
3 changes: 3 additions & 0 deletions src/services/github/v3/createPullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Octokit } from '@octokit/rest';
import ora from 'ora';
import { ValidConfigOptions } from '../../../options/options';
import { getPackageVersion } from '../../../utils/getPackageVersion';
import { HandledError } from '../../HandledError';
import { logger } from '../../logger';
import { Commit } from '../../sourceCommit/parseSourceCommit';
Expand Down Expand Up @@ -104,6 +105,8 @@ export function getPullRequestBody({
This is an automatic backport to \`${targetBranch}\` of:
${commitMessages}
<!--- Backport version: ${getPackageVersion()} -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)`;

Expand Down
Loading

0 comments on commit 326d76c

Please sign in to comment.