backport 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backportRun.js +7 -12
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.private.test.js +21 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +1 -3
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +6 -2
- package/dist/lib/child-process-promisified.js +5 -3
- package/dist/lib/env.d.ts +3 -1
- package/dist/lib/env.js +2 -2
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +1 -1
- package/dist/lib/getTargetBranches.test.js +11 -7
- package/dist/lib/git.js +1 -1
- package/dist/lib/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.js +1 -1
- package/dist/lib/github/v3/createPullRequest.js +6 -6
- package/dist/lib/github/v3/createStatusComment.js +6 -4
- package/dist/lib/github/v3/createStatusComment.test.js +108 -3
- package/dist/lib/github/v4/apiRequestV4.js +7 -7
- package/dist/lib/github/v4/validateTargetBranches.d.ts +9 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +20 -14
- package/dist/options/cliArgs.d.ts +6 -6
- package/dist/options/cliArgs.js +3 -3
- package/dist/options/cliArgs.test.js +10 -10
- package/dist/options/config/readConfigFile.d.ts +5 -5
- package/dist/options/options.d.ts +4 -4
- package/dist/runSequentially.d.ts +1 -3
- package/dist/runSequentially.js +2 -3
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +1 -1
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +7 -260
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +1 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +5 -5
- package/yarn.lock +60 -55
package/dist/lib/logger.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export declare function initLogger({ interactive, accessToken, logFilePath, }: {
|
|
|
7
7
|
}): winston.Logger;
|
|
8
8
|
export declare function consoleLog(message: string): void;
|
|
9
9
|
export declare function setAccessToken(accessToken: string): void;
|
|
10
|
+
export declare function redactAccessToken(str: string): string;
|
|
11
|
+
export declare type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug';
|
package/dist/lib/logger.js
CHANGED
|
@@ -23,9 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.setAccessToken = exports.consoleLog = exports.initLogger = exports.logger = void 0;
|
|
26
|
+
exports.redactAccessToken = exports.setAccessToken = exports.consoleLog = exports.initLogger = exports.logger = void 0;
|
|
27
27
|
const winston_1 = __importStar(require("winston"));
|
|
28
|
-
const redact_1 = require("../utils/redact");
|
|
29
28
|
const env_1 = require("./env");
|
|
30
29
|
let _accessToken;
|
|
31
30
|
let _interactive;
|
|
@@ -38,15 +37,27 @@ function initLogger({ interactive, accessToken, logFilePath, }) {
|
|
|
38
37
|
winston_1.format.metadata({
|
|
39
38
|
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
40
39
|
})),
|
|
41
|
-
transports:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
transports: logFilePath
|
|
41
|
+
? [fileTransport({ logLevel: 'debug', logFilePath })]
|
|
42
|
+
: [
|
|
43
|
+
fileTransport({ logLevel: 'info' }),
|
|
44
|
+
fileTransport({ logLevel: 'debug' }),
|
|
45
|
+
],
|
|
46
46
|
});
|
|
47
47
|
return exports.logger;
|
|
48
48
|
}
|
|
49
49
|
exports.initLogger = initLogger;
|
|
50
|
+
function fileTransport({ logFilePath, logLevel, }) {
|
|
51
|
+
return new winston_1.default.transports.File({
|
|
52
|
+
filename: (0, env_1.getLogfilePath)({ logFilePath, logLevel }),
|
|
53
|
+
level: logLevel,
|
|
54
|
+
format: winston_1.format.json({
|
|
55
|
+
replacer: (key, value) => {
|
|
56
|
+
return typeof value === 'string' ? redactAccessToken(value) : value;
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
50
61
|
// wrapper around console.log
|
|
51
62
|
function consoleLog(message) {
|
|
52
63
|
if (_interactive) {
|
|
@@ -62,13 +73,8 @@ exports.setAccessToken = setAccessToken;
|
|
|
62
73
|
function redactAccessToken(str) {
|
|
63
74
|
// `redactAccessToken` might be called before access token is set
|
|
64
75
|
if (_accessToken) {
|
|
65
|
-
return
|
|
76
|
+
return str.replaceAll(_accessToken, '<REDACTED>');
|
|
66
77
|
}
|
|
67
78
|
return str;
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
// - error
|
|
71
|
-
// - warn
|
|
72
|
-
// - info
|
|
73
|
-
// - verbose
|
|
74
|
-
// - debug
|
|
80
|
+
exports.redactAccessToken = redactAccessToken;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { ConfigFileOptions } from './ConfigOptions';
|
|
2
2
|
export declare type OptionsFromCliArgs = ReturnType<typeof getOptionsFromCliArgs>;
|
|
3
3
|
export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
|
|
4
|
-
|
|
4
|
+
cwd?: string | undefined;
|
|
5
|
+
fork?: boolean | undefined;
|
|
6
|
+
dir?: string | undefined;
|
|
7
|
+
interactive?: boolean | undefined;
|
|
5
8
|
accessToken?: string | undefined;
|
|
9
|
+
logFilePath?: string | undefined;
|
|
6
10
|
author?: string | null | undefined;
|
|
7
11
|
autoAssign?: boolean | undefined;
|
|
8
12
|
assignees?: string[] | undefined;
|
|
9
13
|
autoMerge?: boolean | undefined;
|
|
10
14
|
autoMergeMethod?: string | undefined;
|
|
11
15
|
cherrypickRef?: boolean | undefined;
|
|
12
|
-
cwd?: string | undefined;
|
|
13
16
|
projectConfigFile?: string | undefined;
|
|
14
17
|
globalConfigFile?: string | undefined;
|
|
15
|
-
dir?: string | undefined;
|
|
16
18
|
details?: boolean | undefined;
|
|
17
19
|
dryRun?: boolean | undefined;
|
|
18
20
|
editor?: string | undefined;
|
|
19
21
|
skipRemoteConfig?: boolean | undefined;
|
|
20
|
-
fork?: boolean | undefined;
|
|
21
22
|
gitHostname?: string | undefined;
|
|
22
23
|
githubApiBaseUrlV3?: string | undefined;
|
|
23
24
|
githubApiBaseUrlV4?: string | undefined;
|
|
24
25
|
gitAuthorName?: string | undefined;
|
|
25
26
|
gitAuthorEmail?: string | undefined;
|
|
26
|
-
interactive?: boolean | undefined;
|
|
27
27
|
ls?: boolean | undefined;
|
|
28
28
|
mainline?: number | undefined;
|
|
29
29
|
maxNumber?: number | undefined;
|
|
@@ -53,7 +53,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
|
|
|
53
53
|
publishStatusCommentOnFailure?: boolean | undefined;
|
|
54
54
|
publishStatusCommentOnAbort?: boolean | undefined;
|
|
55
55
|
};
|
|
56
|
-
export declare function
|
|
56
|
+
export declare function getRuntimeArguments(processArgs: string[], optionsFromModule?: ConfigFileOptions): {
|
|
57
57
|
interactive: boolean;
|
|
58
58
|
logFilePath: any;
|
|
59
59
|
ls: any;
|
package/dist/options/cliArgs.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getRuntimeArguments = exports.getOptionsFromCliArgs = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
9
9
|
const excludeUndefined_1 = require("../utils/excludeUndefined");
|
|
@@ -369,7 +369,7 @@ function getOptionsFromCliArgs(processArgs) {
|
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
371
|
exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
|
|
372
|
-
function
|
|
372
|
+
function getRuntimeArguments(processArgs, optionsFromModule) {
|
|
373
373
|
const { nonInteractive, json, logFilePath, ls } = (0, yargs_parser_1.default)(processArgs);
|
|
374
374
|
const base = { ...options_1.defaultConfigOptions, ...optionsFromModule };
|
|
375
375
|
return {
|
|
@@ -380,4 +380,4 @@ function getEarlyArguments(processArgs, optionsFromModule) {
|
|
|
380
380
|
ls,
|
|
381
381
|
};
|
|
382
382
|
}
|
|
383
|
-
exports.
|
|
383
|
+
exports.getRuntimeArguments = getRuntimeArguments;
|
|
@@ -112,7 +112,7 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
112
112
|
});
|
|
113
113
|
it('should conflict when using both', () => {
|
|
114
114
|
const argv = ['--multiple', '--multiple-branches', 'false'];
|
|
115
|
-
expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv)).
|
|
115
|
+
expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv)).toThrowError('Arguments multiple and multipleBranches are mutually exclusive');
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
describe('fork', () => {
|
|
@@ -264,42 +264,42 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
264
264
|
});
|
|
265
265
|
});
|
|
266
266
|
});
|
|
267
|
-
describe('
|
|
267
|
+
describe('getRuntimeArguments', () => {
|
|
268
268
|
describe('interactive', () => {
|
|
269
269
|
it('--non-interactive flag', () => {
|
|
270
|
-
const { interactive } = (0, cliArgs_1.
|
|
270
|
+
const { interactive } = (0, cliArgs_1.getRuntimeArguments)(['--non-interactive']);
|
|
271
271
|
expect(interactive).toEqual(false);
|
|
272
272
|
});
|
|
273
273
|
it('--json flag', () => {
|
|
274
|
-
const { interactive } = (0, cliArgs_1.
|
|
274
|
+
const { interactive } = (0, cliArgs_1.getRuntimeArguments)(['--json']);
|
|
275
275
|
expect(interactive).toEqual(false);
|
|
276
276
|
});
|
|
277
277
|
it('default', () => {
|
|
278
|
-
const { interactive } = (0, cliArgs_1.
|
|
278
|
+
const { interactive } = (0, cliArgs_1.getRuntimeArguments)([]);
|
|
279
279
|
expect(interactive).toEqual(true);
|
|
280
280
|
});
|
|
281
281
|
it('setting via module options', () => {
|
|
282
|
-
const { interactive } = (0, cliArgs_1.
|
|
282
|
+
const { interactive } = (0, cliArgs_1.getRuntimeArguments)([], { interactive: false });
|
|
283
283
|
expect(interactive).toEqual(false);
|
|
284
284
|
});
|
|
285
285
|
});
|
|
286
286
|
describe('ls', () => {
|
|
287
287
|
it('by default', () => {
|
|
288
|
-
const { ls } = (0, cliArgs_1.
|
|
288
|
+
const { ls } = (0, cliArgs_1.getRuntimeArguments)([]);
|
|
289
289
|
expect(ls).toEqual(undefined);
|
|
290
290
|
});
|
|
291
291
|
it('--ls flag', () => {
|
|
292
|
-
const { ls } = (0, cliArgs_1.
|
|
292
|
+
const { ls } = (0, cliArgs_1.getRuntimeArguments)(['--ls']);
|
|
293
293
|
expect(ls).toEqual(true);
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
describe('logFilePath', () => {
|
|
297
297
|
it('by default', () => {
|
|
298
|
-
const { logFilePath } = (0, cliArgs_1.
|
|
298
|
+
const { logFilePath } = (0, cliArgs_1.getRuntimeArguments)([]);
|
|
299
299
|
expect(logFilePath).toEqual(undefined);
|
|
300
300
|
});
|
|
301
301
|
it('--log-file-path flag', () => {
|
|
302
|
-
const { logFilePath } = (0, cliArgs_1.
|
|
302
|
+
const { logFilePath } = (0, cliArgs_1.getRuntimeArguments)(['--log-file-path']);
|
|
303
303
|
expect(logFilePath).toEqual(true);
|
|
304
304
|
});
|
|
305
305
|
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ConfigFileOptions } from '../ConfigOptions';
|
|
2
2
|
export declare function readConfigFile(filepath: string): Promise<ConfigFileOptions>;
|
|
3
3
|
export declare function withConfigMigrations({ upstream, labels, branches, ...config }: ConfigFileOptions): {
|
|
4
|
-
|
|
4
|
+
fork?: boolean | undefined;
|
|
5
|
+
dir?: string | undefined;
|
|
6
|
+
help?: boolean | undefined;
|
|
7
|
+
interactive?: boolean | undefined;
|
|
5
8
|
accessToken?: string | undefined;
|
|
9
|
+
logFilePath?: string | undefined;
|
|
6
10
|
author?: string | null | undefined;
|
|
7
11
|
autoAssign?: boolean | undefined;
|
|
8
12
|
assignees?: string[] | undefined;
|
|
@@ -10,18 +14,15 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
10
14
|
autoMergeMethod?: string | undefined;
|
|
11
15
|
cherrypickRef?: boolean | undefined;
|
|
12
16
|
projectConfigFile?: string | undefined;
|
|
13
|
-
dir?: string | undefined;
|
|
14
17
|
details?: boolean | undefined;
|
|
15
18
|
dryRun?: boolean | undefined;
|
|
16
19
|
editor?: string | undefined;
|
|
17
20
|
skipRemoteConfig?: boolean | undefined;
|
|
18
|
-
fork?: boolean | undefined;
|
|
19
21
|
gitHostname?: string | undefined;
|
|
20
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
21
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
22
24
|
gitAuthorName?: string | undefined;
|
|
23
25
|
gitAuthorEmail?: string | undefined;
|
|
24
|
-
interactive?: boolean | undefined;
|
|
25
26
|
ls?: boolean | undefined;
|
|
26
27
|
maxNumber?: number | undefined;
|
|
27
28
|
multiple?: boolean | undefined;
|
|
@@ -56,6 +57,5 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
56
57
|
targetBranch: string;
|
|
57
58
|
}) => boolean | Promise<boolean>) | undefined;
|
|
58
59
|
backportBinary?: string | undefined;
|
|
59
|
-
help?: boolean | undefined;
|
|
60
60
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
61
61
|
};
|
|
@@ -37,6 +37,10 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
|
|
|
37
37
|
accessToken: string;
|
|
38
38
|
repoName: string;
|
|
39
39
|
repoOwner: string;
|
|
40
|
+
cwd: string;
|
|
41
|
+
fork: boolean;
|
|
42
|
+
dir?: string | undefined;
|
|
43
|
+
interactive: boolean;
|
|
40
44
|
logFilePath?: string | undefined;
|
|
41
45
|
author: string | null;
|
|
42
46
|
autoAssign: boolean;
|
|
@@ -44,21 +48,17 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
|
|
|
44
48
|
autoMerge: boolean;
|
|
45
49
|
autoMergeMethod: string;
|
|
46
50
|
cherrypickRef: boolean;
|
|
47
|
-
cwd: string;
|
|
48
51
|
projectConfigFile?: string | undefined;
|
|
49
52
|
globalConfigFile?: string | undefined;
|
|
50
|
-
dir?: string | undefined;
|
|
51
53
|
details: boolean;
|
|
52
54
|
dryRun?: boolean | undefined;
|
|
53
55
|
editor?: string | undefined;
|
|
54
56
|
skipRemoteConfig?: boolean | undefined;
|
|
55
|
-
fork: boolean;
|
|
56
57
|
gitHostname: string;
|
|
57
58
|
githubApiBaseUrlV3?: string | undefined;
|
|
58
59
|
githubApiBaseUrlV4?: string | undefined;
|
|
59
60
|
gitAuthorName?: string | undefined;
|
|
60
61
|
gitAuthorEmail?: string | undefined;
|
|
61
|
-
interactive: boolean;
|
|
62
62
|
ls?: boolean | undefined;
|
|
63
63
|
mainline?: number | undefined;
|
|
64
64
|
maxNumber: number;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BackportError } from './lib/BackportError';
|
|
2
|
-
import { GitConfigAuthor } from './lib/getGitConfigAuthor';
|
|
3
2
|
import { Commit } from './lib/sourceCommit/parseSourceCommit';
|
|
4
3
|
import { ValidConfigOptions } from './options/options';
|
|
5
4
|
export declare type SuccessResult = {
|
|
@@ -20,9 +19,8 @@ export declare type UnhandledErrorResult = {
|
|
|
20
19
|
error: Error;
|
|
21
20
|
};
|
|
22
21
|
export declare type Result = SuccessResult | HandledErrorResult | UnhandledErrorResult;
|
|
23
|
-
export declare function runSequentially({ options, commits, targetBranches,
|
|
22
|
+
export declare function runSequentially({ options, commits, targetBranches, }: {
|
|
24
23
|
options: ValidConfigOptions;
|
|
25
24
|
commits: Commit[];
|
|
26
25
|
targetBranches: string[];
|
|
27
|
-
gitConfigAuthor?: GitConfigAuthor;
|
|
28
26
|
}): Promise<Result[]>;
|
package/dist/runSequentially.js
CHANGED
|
@@ -5,7 +5,7 @@ const BackportError_1 = require("./lib/BackportError");
|
|
|
5
5
|
const cherrypickAndCreateTargetPullRequest_1 = require("./lib/cherrypickAndCreateTargetPullRequest");
|
|
6
6
|
const logger_1 = require("./lib/logger");
|
|
7
7
|
const sequentially_1 = require("./lib/sequentially");
|
|
8
|
-
async function runSequentially({ options, commits, targetBranches,
|
|
8
|
+
async function runSequentially({ options, commits, targetBranches, }) {
|
|
9
9
|
logger_1.logger.verbose('Backport options', options);
|
|
10
10
|
const results = [];
|
|
11
11
|
await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
|
|
@@ -15,7 +15,6 @@ async function runSequentially({ options, commits, targetBranches, gitConfigAuth
|
|
|
15
15
|
options,
|
|
16
16
|
commits,
|
|
17
17
|
targetBranch,
|
|
18
|
-
gitConfigAuthor: gitConfigAuthor,
|
|
19
18
|
});
|
|
20
19
|
results.push({
|
|
21
20
|
targetBranch,
|
|
@@ -46,7 +45,7 @@ async function runSequentially({ options, commits, targetBranches, gitConfigAuth
|
|
|
46
45
|
}
|
|
47
46
|
(0, logger_1.consoleLog)(isHandledError
|
|
48
47
|
? e.message
|
|
49
|
-
: 'An error occurred while backporting commit. Please see the logs for details');
|
|
48
|
+
: 'An unhandled error occurred while backporting commit. Please see the logs for details');
|
|
50
49
|
logger_1.logger.error('runSequentially failed', e);
|
|
51
50
|
}
|
|
52
51
|
});
|
|
@@ -8,7 +8,7 @@ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
|
8
8
|
describe('different-merge-strategies', () => {
|
|
9
9
|
it('list all commits regardless how they were merged', async () => {
|
|
10
10
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
11
|
-
'--branch=
|
|
11
|
+
'--branch=7.x',
|
|
12
12
|
'--repo=backport-org/different-merge-strategies',
|
|
13
13
|
`--accessToken=${accessToken}`,
|
|
14
14
|
'-n=20',
|
|
@@ -22,12 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
26
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
32
27
|
const packageVersion = __importStar(require("../../../utils/packageVersion"));
|
|
33
28
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
@@ -123,7 +118,7 @@ describe('entrypoint cli', () => {
|
|
|
123
118
|
Or contact me directly: https://twitter.com/sorenlouv"
|
|
124
119
|
`);
|
|
125
120
|
});
|
|
126
|
-
it('
|
|
121
|
+
it('lists commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
|
|
127
122
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
128
123
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
129
124
|
await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
|
|
@@ -146,9 +141,9 @@ describe('entrypoint cli', () => {
|
|
|
146
141
|
10.Add package.json"
|
|
147
142
|
`);
|
|
148
143
|
});
|
|
149
|
-
it(`
|
|
144
|
+
it(`lists commits from master`, async () => {
|
|
150
145
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
151
|
-
'--branch=
|
|
146
|
+
'--branch=7.x',
|
|
152
147
|
'--repo=backport-org/backport-e2e',
|
|
153
148
|
'--author=sqren',
|
|
154
149
|
`--accessToken=${accessToken}`,
|
|
@@ -164,9 +159,9 @@ describe('entrypoint cli', () => {
|
|
|
164
159
|
6. Merge pull request #1 from backport-org/add-heart-emoji"
|
|
165
160
|
`);
|
|
166
161
|
});
|
|
167
|
-
it(`
|
|
162
|
+
it(`filters commits by "since" and "until"`, async () => {
|
|
168
163
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
169
|
-
'--branch=
|
|
164
|
+
'--branch=7.x',
|
|
170
165
|
'--repo=backport-org/backport-e2e',
|
|
171
166
|
`--accessToken=${accessToken}`,
|
|
172
167
|
'--since=2020-08-15T10:00:00.000Z',
|
|
@@ -180,9 +175,9 @@ describe('entrypoint cli', () => {
|
|
|
180
175
|
4. Create .backportrc.json"
|
|
181
176
|
`);
|
|
182
177
|
});
|
|
183
|
-
it(`
|
|
178
|
+
it(`lists commits from 7.x`, async () => {
|
|
184
179
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
185
|
-
'--branch=
|
|
180
|
+
'--branch=7.x',
|
|
186
181
|
'--repo=backport-org/backport-e2e',
|
|
187
182
|
'--author=sqren',
|
|
188
183
|
`--accessToken=${accessToken}`,
|
|
@@ -199,252 +194,4 @@ describe('entrypoint cli', () => {
|
|
|
199
194
|
6. Bump to 8.0.0"
|
|
200
195
|
`);
|
|
201
196
|
});
|
|
202
|
-
async function createConfigFile(options) {
|
|
203
|
-
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
204
|
-
const configPath = path_1.default.join(sandboxPath, 'config.json');
|
|
205
|
-
await promises_1.default.writeFile(configPath, JSON.stringify(options));
|
|
206
|
-
return configPath;
|
|
207
|
-
}
|
|
208
|
-
describe('errors in interactive mode (non-json)', () => {
|
|
209
|
-
it('when branch is missing', async () => {
|
|
210
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
211
|
-
'--skip-remote-config',
|
|
212
|
-
'--repo=backport-org/backport-e2e',
|
|
213
|
-
`--accessToken=${accessToken}`,
|
|
214
|
-
]);
|
|
215
|
-
expect(output).toMatchInlineSnapshot(`
|
|
216
|
-
"Please specify a target branch: \\"--branch 6.1\\".
|
|
217
|
-
|
|
218
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
219
|
-
`);
|
|
220
|
-
});
|
|
221
|
-
it('when supplying invalid argument', async () => {
|
|
222
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--foo`]);
|
|
223
|
-
expect(output).toMatchInlineSnapshot(`
|
|
224
|
-
"Unknown argument: foo
|
|
225
|
-
Run \\"backport --help\\" to see all options"
|
|
226
|
-
`);
|
|
227
|
-
});
|
|
228
|
-
it('when access token is invalid', async () => {
|
|
229
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
230
|
-
'--branch=foo',
|
|
231
|
-
'--repo=foo/bar',
|
|
232
|
-
'--accessToken=some-token',
|
|
233
|
-
]);
|
|
234
|
-
expect(output).toContain('Please check your access token and make sure it is valid');
|
|
235
|
-
});
|
|
236
|
-
it(`should output error when repo doesn't exist`, async () => {
|
|
237
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
238
|
-
'--branch=foo',
|
|
239
|
-
'--repo=foo/bar',
|
|
240
|
-
'--author=sqren',
|
|
241
|
-
`--accessToken=${accessToken}`,
|
|
242
|
-
]);
|
|
243
|
-
expect(output).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
244
|
-
});
|
|
245
|
-
it(`should output error when given branch is invalid`, async () => {
|
|
246
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
247
|
-
'--branch=foo',
|
|
248
|
-
'--repo=backport-org/backport-e2e',
|
|
249
|
-
'--pr=9',
|
|
250
|
-
`--accessToken=${accessToken}`,
|
|
251
|
-
]);
|
|
252
|
-
expect(output).toMatchInlineSnapshot(`
|
|
253
|
-
"Backporting to foo:
|
|
254
|
-
The branch \\"foo\\" is invalid or doesn't exist"
|
|
255
|
-
`);
|
|
256
|
-
});
|
|
257
|
-
it(`should output merge conflict`, async () => {
|
|
258
|
-
const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
259
|
-
await (0, sandbox_1.resetSandbox)(backportDir);
|
|
260
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
261
|
-
'--repo=backport-org/repo-with-conflicts',
|
|
262
|
-
'--pr=12',
|
|
263
|
-
'--branch=7.x',
|
|
264
|
-
`--accessToken=${accessToken}`,
|
|
265
|
-
`--dir=${backportDir}`,
|
|
266
|
-
'--dry-run',
|
|
267
|
-
], {
|
|
268
|
-
waitForString: 'Press ENTER when the conflicts',
|
|
269
|
-
timeoutSeconds: 5,
|
|
270
|
-
});
|
|
271
|
-
// //@ts-expect-error
|
|
272
|
-
// const lineToReplace = output.match(
|
|
273
|
-
// /Conflicting files:[\s]+- (.*[\s].*)la-liga.md/
|
|
274
|
-
// )[1];
|
|
275
|
-
// const lineWithoutBreaks = lineToReplace.replace(/\s/g, '');
|
|
276
|
-
// const outputReplaced = output
|
|
277
|
-
// .replace(lineToReplace, lineWithoutBreaks)
|
|
278
|
-
// .replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
279
|
-
const outputReplaced = output
|
|
280
|
-
.replaceAll('\n', '')
|
|
281
|
-
.replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
282
|
-
expect(outputReplaced).toMatchInlineSnapshot(`"Backporting to 7.x:The commit could not be backported due to conflictsPlease fix the conflicts in <BACKPORT_DIR>Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\": - Change Barca to Braithwaite (#8) (backport missing) https://github.com/backport-org/repo-with-conflicts/pull/8? Fix the following conflicts manually:Conflicting files: - <BACKPORT_DIR>/la-liga.mdPress ENTER when the conflicts are resolved and files are staged (Y/n)"`);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe('failure cases in json mode (and non-interactive)', () => {
|
|
286
|
-
it(`when access token is missing`, async () => {
|
|
287
|
-
const configFilePath = await createConfigFile({});
|
|
288
|
-
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
289
|
-
'--json',
|
|
290
|
-
`--globalConfigFile=${configFilePath}`,
|
|
291
|
-
]);
|
|
292
|
-
const backportResult = JSON.parse(output);
|
|
293
|
-
expect(code).toBe(1);
|
|
294
|
-
expect(backportResult.status).toBe('failure');
|
|
295
|
-
expect(backportResult.errorMessage.replace(configFilePath, '<GLOBAL_CONFIG_FILE>')).toMatchInlineSnapshot(`
|
|
296
|
-
"Please update your config file: \\"<GLOBAL_CONFIG_FILE>\\".
|
|
297
|
-
It must contain a valid \\"accessToken\\".
|
|
298
|
-
|
|
299
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
300
|
-
`);
|
|
301
|
-
});
|
|
302
|
-
it('when target branches cannot be inferred from pull request', async () => {
|
|
303
|
-
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
304
|
-
'--json',
|
|
305
|
-
'--repo=backport-org/backport-e2e',
|
|
306
|
-
'--pr=9',
|
|
307
|
-
`--accessToken=${accessToken}`,
|
|
308
|
-
]);
|
|
309
|
-
expect(code).toBe(0);
|
|
310
|
-
const backportResult = JSON.parse(output);
|
|
311
|
-
expect(backportResult.status).toBe('aborted');
|
|
312
|
-
expect(backportResult.error).toEqual({
|
|
313
|
-
errorContext: { code: 'no-branches-exception' },
|
|
314
|
-
name: 'BackportError',
|
|
315
|
-
});
|
|
316
|
-
expect(backportResult.errorMessage).toBe('There are no branches to backport to. Aborting.');
|
|
317
|
-
});
|
|
318
|
-
it(`when target branch and branch label mapping are missing`, async () => {
|
|
319
|
-
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
320
|
-
'--json',
|
|
321
|
-
`--access-token=${accessToken}`,
|
|
322
|
-
]);
|
|
323
|
-
expect(code).toBe(1);
|
|
324
|
-
const backportResult = JSON.parse(output);
|
|
325
|
-
expect(backportResult.status).toBe('failure');
|
|
326
|
-
expect(backportResult.errorMessage).toMatchInlineSnapshot(`
|
|
327
|
-
"Please specify a target branch: \\"--branch 6.1\\".
|
|
328
|
-
|
|
329
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
330
|
-
`);
|
|
331
|
-
});
|
|
332
|
-
it(`when argument is invalid`, async () => {
|
|
333
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)(['--json', '--foo'], {});
|
|
334
|
-
const backportResult = JSON.parse(output);
|
|
335
|
-
expect(backportResult.status).toBe('failure');
|
|
336
|
-
expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
|
|
337
|
-
});
|
|
338
|
-
it('when `--repo` is invalid', async () => {
|
|
339
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
340
|
-
'--json',
|
|
341
|
-
'--repo=backport-org/backport-e2e-foo',
|
|
342
|
-
`--accessToken=${accessToken}`,
|
|
343
|
-
]);
|
|
344
|
-
const backportResult = JSON.parse(output);
|
|
345
|
-
expect(backportResult.status).toBe('failure');
|
|
346
|
-
expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
|
|
347
|
-
});
|
|
348
|
-
it('when `--sha` is invalid', async () => {
|
|
349
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
350
|
-
'--json',
|
|
351
|
-
'--repo=backport-org/backport-e2e',
|
|
352
|
-
'--sha=abcdefg',
|
|
353
|
-
`--accessToken=${accessToken}`,
|
|
354
|
-
]);
|
|
355
|
-
const backportResult = JSON.parse(output);
|
|
356
|
-
expect(backportResult.status).toBe('failure');
|
|
357
|
-
expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
|
|
358
|
-
});
|
|
359
|
-
it('when `--branch` is invalid', async () => {
|
|
360
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
361
|
-
'--json',
|
|
362
|
-
'--repo=backport-org/backport-e2e',
|
|
363
|
-
'--pr=9',
|
|
364
|
-
'--branch=foobar',
|
|
365
|
-
`--accessToken=${accessToken}`,
|
|
366
|
-
]);
|
|
367
|
-
const backportResult = JSON.parse(output);
|
|
368
|
-
expect(backportResult.status).toBe('success');
|
|
369
|
-
expect(backportResult.results[0]).toEqual({
|
|
370
|
-
error: {
|
|
371
|
-
errorContext: {
|
|
372
|
-
code: 'message-only-exception',
|
|
373
|
-
message: 'The branch "foobar" is invalid or doesn\'t exist',
|
|
374
|
-
},
|
|
375
|
-
name: 'BackportError',
|
|
376
|
-
},
|
|
377
|
-
status: 'handled-error',
|
|
378
|
-
targetBranch: 'foobar',
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
it('when `--pr` is invalid', async () => {
|
|
382
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
383
|
-
'--json',
|
|
384
|
-
'--repo=backport-org/backport-e2e',
|
|
385
|
-
'--pr=900',
|
|
386
|
-
'--branch=foobar',
|
|
387
|
-
`--accessToken=${accessToken}`,
|
|
388
|
-
]);
|
|
389
|
-
const backportResult = JSON.parse(output);
|
|
390
|
-
expect(backportResult.status).toEqual('failure');
|
|
391
|
-
expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
|
|
392
|
-
});
|
|
393
|
-
it('when having conflicts in non-interactive mode', async () => {
|
|
394
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
395
|
-
'--json',
|
|
396
|
-
'--repo=backport-org/repo-with-conflicts',
|
|
397
|
-
'--pr=12',
|
|
398
|
-
'--branch=7.x',
|
|
399
|
-
`--accessToken=${accessToken}`,
|
|
400
|
-
]);
|
|
401
|
-
const backportResult = JSON.parse(output);
|
|
402
|
-
expect(backportResult.status).toEqual('success');
|
|
403
|
-
expect(
|
|
404
|
-
//@ts-expect-error
|
|
405
|
-
backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
|
|
406
|
-
});
|
|
407
|
-
it('when `--source-branch` is invalid', async () => {
|
|
408
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
409
|
-
'--json',
|
|
410
|
-
'--repo=backport-org/backport-e2e',
|
|
411
|
-
'--pr=9',
|
|
412
|
-
'--branch=7.x',
|
|
413
|
-
'--source-branch=foo',
|
|
414
|
-
`--accessToken=${accessToken}`,
|
|
415
|
-
]);
|
|
416
|
-
const backportResult = JSON.parse(output);
|
|
417
|
-
expect(backportResult.status).toBe('success');
|
|
418
|
-
expect(backportResult.results[0]).toEqual({
|
|
419
|
-
error: {
|
|
420
|
-
context: {
|
|
421
|
-
cmdArgs: ['checkout', 'foo'],
|
|
422
|
-
code: 1,
|
|
423
|
-
stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
|
|
424
|
-
stdout: '',
|
|
425
|
-
},
|
|
426
|
-
name: 'SpawnError',
|
|
427
|
-
},
|
|
428
|
-
status: 'unhandled-error',
|
|
429
|
-
targetBranch: '7.x',
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
it('when PR is not merged', async () => {
|
|
433
|
-
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
434
|
-
'--json',
|
|
435
|
-
'--repo=backport-org/backport-e2e',
|
|
436
|
-
'--pr=12',
|
|
437
|
-
`--accessToken=${accessToken}`,
|
|
438
|
-
]);
|
|
439
|
-
const backportResult = JSON.parse(output);
|
|
440
|
-
expect(backportResult.status).toBe('failure');
|
|
441
|
-
expect(backportResult.error).toEqual({
|
|
442
|
-
errorContext: {
|
|
443
|
-
code: 'message-only-exception',
|
|
444
|
-
message: 'The PR #12 is not merged',
|
|
445
|
-
},
|
|
446
|
-
name: 'BackportError',
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
197
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|