backport 6.0.0 → 6.1.3
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/README.md +179 -52
- package/dist/entrypoint.cli.js +2 -0
- package/dist/entrypoint.module.d.ts +16 -4
- package/dist/entrypoint.module.js +41 -13
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +16 -6
- package/dist/options/cliArgs.d.ts +36 -37
- package/dist/options/cliArgs.js +25 -24
- package/dist/options/cliArgs.test.js +6 -10
- package/dist/options/config/config.d.ts +28 -52
- package/dist/options/config/config.js +2 -36
- package/dist/options/config/config.test.js +10 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.js +2 -5
- package/dist/options/config/globalConfig.test.js +0 -2
- package/dist/options/config/projectConfig.test.js +51 -14
- package/dist/options/config/readConfigFile.d.ts +52 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +55 -32
- package/dist/options/options.js +101 -7
- package/dist/options/options.test.js +248 -97
- package/dist/options/parseRequiredOptions.d.ts +3 -3
- package/dist/options/parseRequiredOptions.js +2 -4
- package/dist/options/parseRequiredOptions.test.js +6 -11
- package/dist/runSequentially.test.js +40 -78
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.js +11 -10
- package/dist/services/git.test.js +12 -9
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
- package/dist/services/github/v3/createPullRequest.js +10 -13
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- package/dist/services/github/v3/createStatusComment.js +12 -14
- package/dist/services/github/v3/createStatusComment.test.js +58 -29
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +5 -6
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
- package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
- package/dist/test/inquirer.private.test.js +33 -36
- package/dist/test/integration/integration.private.test.js +114 -95
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +4 -4
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -29
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/getTargetBranches.d.ts +2 -1
- package/dist/ui/getTargetBranches.js +17 -1
- package/dist/ui/maybeSetupRepo.js +4 -3
- package/dist/ui/maybeSetupRepo.test.js +49 -3
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +9 -8
- package/yarn.lock +98 -77
package/dist/options/cliArgs.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getOptionsFromCliArgs = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const excludeUndefined_1 = require("../utils/excludeUndefined");
|
|
8
9
|
function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
9
10
|
const yargsInstance = (0, yargs_1.default)(argv)
|
|
10
11
|
.parserConfiguration({
|
|
@@ -24,6 +25,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
24
25
|
description: 'List all commits',
|
|
25
26
|
alias: 'a',
|
|
26
27
|
type: 'boolean',
|
|
28
|
+
conflicts: 'author',
|
|
27
29
|
})
|
|
28
30
|
.option('assignee', {
|
|
29
31
|
description: 'Add assignees to the target pull request',
|
|
@@ -31,10 +33,6 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
31
33
|
type: 'array',
|
|
32
34
|
string: true,
|
|
33
35
|
conflicts: ['autoAssign'],
|
|
34
|
-
})
|
|
35
|
-
.option('author', {
|
|
36
|
-
description: 'Show commits by specific author',
|
|
37
|
-
type: 'string',
|
|
38
36
|
})
|
|
39
37
|
.option('autoAssign', {
|
|
40
38
|
description: 'Auto assign the target pull request to yourself',
|
|
@@ -67,11 +65,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
67
65
|
description: 'Editor to be opened during conflict resolution',
|
|
68
66
|
type: 'string',
|
|
69
67
|
})
|
|
70
|
-
.option('
|
|
68
|
+
.option('skipRemoteConfig', {
|
|
71
69
|
description: 'Use local .backportrc.json config instead of loading from Github',
|
|
72
70
|
type: 'boolean',
|
|
73
71
|
})
|
|
74
|
-
// push target branch to {
|
|
72
|
+
// push target branch to {authenticatedUsername}/{repoName}
|
|
75
73
|
.option('fork', {
|
|
76
74
|
description: 'Create backports in fork or origin repo',
|
|
77
75
|
type: 'boolean',
|
|
@@ -96,9 +94,10 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
96
94
|
description: 'Parent id of merge commit. Defaults to 1 when supplied without arguments',
|
|
97
95
|
type: 'number',
|
|
98
96
|
coerce: (mainline) => {
|
|
99
|
-
// `--mainline` (default to 1 when no parent is given)
|
|
100
97
|
if (mainline === undefined) {
|
|
101
|
-
return 1
|
|
98
|
+
// return 1 if `--mainline` is given without a value
|
|
99
|
+
// return undefined if --mainline is not supplied at all
|
|
100
|
+
return argv.includes('--mainline') ? 1 : undefined;
|
|
102
101
|
}
|
|
103
102
|
// use specified mainline parent
|
|
104
103
|
if (Number.isInteger(mainline)) {
|
|
@@ -181,6 +180,14 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
181
180
|
description: 'Add reviewer to the target PR',
|
|
182
181
|
type: 'array',
|
|
183
182
|
string: true,
|
|
183
|
+
})
|
|
184
|
+
.option('repoOwner', {
|
|
185
|
+
description: 'Repository owner',
|
|
186
|
+
type: 'string',
|
|
187
|
+
})
|
|
188
|
+
.option('repoName', {
|
|
189
|
+
description: 'Repository name',
|
|
190
|
+
type: 'string',
|
|
184
191
|
})
|
|
185
192
|
.option('sha', {
|
|
186
193
|
conflicts: ['pullNumber', 'prFilter'],
|
|
@@ -215,14 +222,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
215
222
|
type: 'array',
|
|
216
223
|
string: true,
|
|
217
224
|
})
|
|
218
|
-
.option('
|
|
219
|
-
description: '
|
|
220
|
-
alias: '
|
|
221
|
-
type: 'string',
|
|
222
|
-
})
|
|
223
|
-
.option('username', {
|
|
224
|
-
description: 'Github username',
|
|
225
|
+
.option('author', {
|
|
226
|
+
description: 'Show commits by a specific user',
|
|
227
|
+
alias: 'author',
|
|
225
228
|
type: 'string',
|
|
229
|
+
conflicts: 'all',
|
|
226
230
|
})
|
|
227
231
|
.option('verbose', {
|
|
228
232
|
description: 'Show additional debug information',
|
|
@@ -252,20 +256,21 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
252
256
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
253
257
|
$0, _,
|
|
254
258
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
255
|
-
multiple, multipleBranches, multipleCommits,
|
|
259
|
+
multiple, multipleBranches, multipleCommits, all, author,
|
|
256
260
|
// negations
|
|
257
261
|
verify, noVerify, noCherrypickRef, noFork,
|
|
258
262
|
// array types (should be renamed to plural form)
|
|
259
263
|
assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
|
|
260
|
-
return excludeUndefined({
|
|
264
|
+
return (0, excludeUndefined_1.excludeUndefined)({
|
|
261
265
|
...restOptions,
|
|
266
|
+
author: all ? null : author,
|
|
262
267
|
// `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
|
|
263
268
|
multipleBranches: multiple ?? multipleBranches,
|
|
264
269
|
multipleCommits: multiple ?? multipleCommits,
|
|
265
270
|
// rename array types to plural
|
|
266
|
-
assignees: assignee
|
|
267
|
-
commitPaths: path
|
|
268
|
-
reviewers: reviewer
|
|
271
|
+
assignees: assignee,
|
|
272
|
+
commitPaths: path,
|
|
273
|
+
reviewers: reviewer,
|
|
269
274
|
sourcePRLabels: sourcePRLabel,
|
|
270
275
|
targetBranchChoices: targetBranchChoice,
|
|
271
276
|
targetBranches: targetBranch,
|
|
@@ -277,7 +282,3 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
277
282
|
});
|
|
278
283
|
}
|
|
279
284
|
exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
|
|
280
|
-
function excludeUndefined(obj) {
|
|
281
|
-
Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
|
|
282
|
-
return obj;
|
|
283
|
-
}
|
|
@@ -20,20 +20,16 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
20
20
|
const argv = [
|
|
21
21
|
'--access-token',
|
|
22
22
|
'my access token',
|
|
23
|
-
'--
|
|
24
|
-
'
|
|
25
|
-
'--
|
|
26
|
-
'
|
|
23
|
+
'--repo-owner',
|
|
24
|
+
'elastic',
|
|
25
|
+
'--repo-name',
|
|
26
|
+
'kibana',
|
|
27
27
|
];
|
|
28
28
|
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
29
29
|
expect(res).toEqual({
|
|
30
30
|
accessToken: 'my access token',
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mainline: 1,
|
|
34
|
-
reviewers: [],
|
|
35
|
-
assignees: [],
|
|
36
|
-
commitPaths: [],
|
|
31
|
+
repoOwner: 'elastic',
|
|
32
|
+
repoName: 'kibana',
|
|
37
33
|
});
|
|
38
34
|
});
|
|
39
35
|
});
|
|
@@ -1,38 +1,10 @@
|
|
|
1
1
|
import { ConfigFileOptions } from '../ConfigOptions';
|
|
2
|
-
export declare const defaultConfigOptions: {
|
|
3
|
-
all: boolean;
|
|
4
|
-
assignees: string[];
|
|
5
|
-
autoAssign: boolean;
|
|
6
|
-
autoMerge: boolean;
|
|
7
|
-
autoMergeMethod: string;
|
|
8
|
-
ci: boolean;
|
|
9
|
-
cherrypickRef: boolean;
|
|
10
|
-
details: boolean;
|
|
11
|
-
fork: boolean;
|
|
12
|
-
gitHostname: string;
|
|
13
|
-
githubApiBaseUrlV3: string;
|
|
14
|
-
githubApiBaseUrlV4: string;
|
|
15
|
-
maxNumber: number;
|
|
16
|
-
multipleBranches: boolean;
|
|
17
|
-
multipleCommits: boolean;
|
|
18
|
-
noVerify: boolean;
|
|
19
|
-
prTitle: string;
|
|
20
|
-
resetAuthor: boolean;
|
|
21
|
-
sourcePRLabels: never[];
|
|
22
|
-
targetBranchChoices: never[];
|
|
23
|
-
targetBranches: never[];
|
|
24
|
-
targetPRLabels: never[];
|
|
25
|
-
verbose: boolean;
|
|
26
|
-
};
|
|
27
2
|
export declare type OptionsFromConfigFiles = Awaited<ReturnType<typeof getOptionsFromConfigFiles>>;
|
|
28
3
|
export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFileOptions): Promise<{
|
|
29
|
-
targetPRLabels: string[];
|
|
30
|
-
targetBranchChoices: import("../ConfigOptions").TargetBranchChoiceOrString[];
|
|
31
4
|
accessToken?: string | undefined;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
autoAssign: boolean;
|
|
5
|
+
assignees?: string[] | undefined;
|
|
6
|
+
author?: string | null | undefined;
|
|
7
|
+
autoAssign?: boolean | undefined;
|
|
36
8
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
37
9
|
files: string[];
|
|
38
10
|
directory: string;
|
|
@@ -45,37 +17,41 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFile
|
|
|
45
17
|
};
|
|
46
18
|
targetBranch: string;
|
|
47
19
|
}) => boolean | Promise<boolean>) | undefined;
|
|
48
|
-
autoMerge
|
|
49
|
-
autoMergeMethod
|
|
50
|
-
|
|
51
|
-
cherrypickRef
|
|
20
|
+
autoMerge?: boolean | undefined;
|
|
21
|
+
autoMergeMethod?: string | undefined;
|
|
22
|
+
backportBinary?: string | undefined;
|
|
23
|
+
cherrypickRef?: boolean | undefined;
|
|
24
|
+
ci?: boolean | undefined;
|
|
52
25
|
commitPaths?: string[] | undefined;
|
|
53
|
-
details
|
|
26
|
+
details?: boolean | undefined;
|
|
54
27
|
editor?: string | undefined;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
maxNumber: number;
|
|
28
|
+
fork?: boolean | undefined;
|
|
29
|
+
gitHostname?: string | undefined;
|
|
30
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
31
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
32
|
+
maxNumber?: number | undefined;
|
|
61
33
|
multiple?: boolean | undefined;
|
|
62
|
-
multipleBranches
|
|
63
|
-
multipleCommits
|
|
64
|
-
noVerify
|
|
34
|
+
multipleBranches?: boolean | undefined;
|
|
35
|
+
multipleCommits?: boolean | undefined;
|
|
36
|
+
noVerify?: boolean | undefined;
|
|
65
37
|
prDescription?: string | undefined;
|
|
66
38
|
prFilter?: string | undefined;
|
|
67
|
-
prTitle
|
|
39
|
+
prTitle?: string | undefined;
|
|
68
40
|
pullNumber?: number | undefined;
|
|
69
|
-
|
|
41
|
+
repoName?: string | undefined;
|
|
42
|
+
repoOwner?: string | undefined;
|
|
43
|
+
resetAuthor?: boolean | undefined;
|
|
70
44
|
reviewers?: string[] | undefined;
|
|
71
45
|
sha?: string | undefined;
|
|
46
|
+
skipRemoteConfig?: boolean | undefined;
|
|
72
47
|
sourceBranch?: string | undefined;
|
|
73
|
-
sourcePRLabels
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
verbose
|
|
48
|
+
sourcePRLabels?: string[] | undefined;
|
|
49
|
+
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
50
|
+
targetBranches?: string[] | undefined;
|
|
51
|
+
targetPRLabels?: string[] | undefined;
|
|
52
|
+
verbose?: boolean | undefined;
|
|
78
53
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
54
|
+
upstream?: string | undefined;
|
|
79
55
|
branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
80
56
|
labels?: string[] | undefined;
|
|
81
57
|
}>;
|
|
@@ -1,54 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOptionsFromConfigFiles =
|
|
3
|
+
exports.getOptionsFromConfigFiles = void 0;
|
|
4
4
|
const getOptionsFromGit_1 = require("./getOptionsFromGit");
|
|
5
5
|
const globalConfig_1 = require("./globalConfig");
|
|
6
6
|
const projectConfig_1 = require("./projectConfig");
|
|
7
|
-
exports.defaultConfigOptions = {
|
|
8
|
-
all: false,
|
|
9
|
-
assignees: [],
|
|
10
|
-
autoAssign: false,
|
|
11
|
-
autoMerge: false,
|
|
12
|
-
autoMergeMethod: 'merge',
|
|
13
|
-
ci: false,
|
|
14
|
-
cherrypickRef: true,
|
|
15
|
-
details: false,
|
|
16
|
-
fork: true,
|
|
17
|
-
gitHostname: 'github.com',
|
|
18
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
19
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
20
|
-
maxNumber: 10,
|
|
21
|
-
multipleBranches: true,
|
|
22
|
-
multipleCommits: false,
|
|
23
|
-
noVerify: true,
|
|
24
|
-
prTitle: '[{targetBranch}] {commitMessages}',
|
|
25
|
-
resetAuthor: false,
|
|
26
|
-
sourcePRLabels: [],
|
|
27
|
-
targetBranchChoices: [],
|
|
28
|
-
targetBranches: [],
|
|
29
|
-
targetPRLabels: [],
|
|
30
|
-
verbose: false,
|
|
31
|
-
};
|
|
32
7
|
async function getOptionsFromConfigFiles(optionsFromModule) {
|
|
33
8
|
const [gitConfig, projectConfig, globalConfig] = await Promise.all([
|
|
34
9
|
(0, getOptionsFromGit_1.getOptionsFromGit)(),
|
|
35
10
|
(0, projectConfig_1.getProjectConfig)(),
|
|
36
11
|
(0, globalConfig_1.getGlobalConfig)(optionsFromModule?.ci),
|
|
37
12
|
]);
|
|
38
|
-
|
|
39
|
-
const combinedConfig = {
|
|
13
|
+
return {
|
|
40
14
|
...gitConfig,
|
|
41
15
|
...globalConfig,
|
|
42
16
|
...projectConfig,
|
|
43
17
|
...optionsFromModule,
|
|
44
18
|
};
|
|
45
|
-
return {
|
|
46
|
-
...exports.defaultConfigOptions,
|
|
47
|
-
...combinedConfig,
|
|
48
|
-
// backwards-compatability: `labels` was renamed `targetPRLabels`
|
|
49
|
-
targetPRLabels: combinedConfig.targetPRLabels ?? combinedConfig.labels ?? [],
|
|
50
|
-
// backwards-compatability: `branches` was renamed `targetBranchChoices`
|
|
51
|
-
targetBranchChoices: combinedConfig.targetBranchChoices ?? combinedConfig.branches ?? [],
|
|
52
|
-
};
|
|
53
19
|
}
|
|
54
20
|
exports.getOptionsFromConfigFiles = getOptionsFromConfigFiles;
|
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mockConfigFiles_1 = require("../../test/mockConfigFiles");
|
|
3
4
|
const config_1 = require("./config");
|
|
4
5
|
describe('getOptionsFromConfigFiles', () => {
|
|
5
6
|
let res;
|
|
6
7
|
beforeEach(async () => {
|
|
8
|
+
(0, mockConfigFiles_1.mockConfigFiles)({
|
|
9
|
+
globalConfig: { accessToken: 'abc', editor: 'vim' },
|
|
10
|
+
projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
|
|
11
|
+
});
|
|
7
12
|
res = await (0, config_1.getOptionsFromConfigFiles)();
|
|
8
13
|
});
|
|
9
|
-
it('should return values from
|
|
14
|
+
it('should return values from config files', () => {
|
|
10
15
|
expect(res).toEqual({
|
|
11
|
-
accessToken: '
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
autoMerge: false,
|
|
16
|
-
autoMergeMethod: 'merge',
|
|
17
|
-
ci: false,
|
|
18
|
-
cherrypickRef: true,
|
|
19
|
-
details: false,
|
|
20
|
-
fork: true,
|
|
21
|
-
gitHostname: 'github.com',
|
|
22
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
23
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
24
|
-
maxNumber: 10,
|
|
25
|
-
multipleBranches: true,
|
|
26
|
-
multipleCommits: false,
|
|
27
|
-
noVerify: true,
|
|
28
|
-
prTitle: '[{targetBranch}] {commitMessages}',
|
|
29
|
-
resetAuthor: false,
|
|
30
|
-
sourcePRLabels: [],
|
|
31
|
-
targetBranchChoices: ['6.0', '5.9'],
|
|
32
|
-
targetBranches: [],
|
|
33
|
-
targetPRLabels: [],
|
|
34
|
-
upstream: 'backport-org/backport-demo',
|
|
35
|
-
username: 'sqren',
|
|
36
|
-
verbose: false,
|
|
16
|
+
accessToken: 'abc',
|
|
17
|
+
editor: 'vim',
|
|
18
|
+
repoName: 'kibana',
|
|
19
|
+
repoOwner: 'elastic',
|
|
37
20
|
});
|
|
38
21
|
});
|
|
39
22
|
});
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getOptionsFromGit = void 0;
|
|
4
4
|
const git_1 = require("../../services/git");
|
|
5
5
|
async function getOptionsFromGit() {
|
|
6
|
-
return
|
|
7
|
-
upstream: await (0, git_1.getUpstreamFromGitRemote)(),
|
|
8
|
-
};
|
|
6
|
+
return (0, git_1.getRepoOwnerAndNameFromGitRemote)();
|
|
9
7
|
}
|
|
10
8
|
exports.getOptionsFromGit = getOptionsFromGit;
|
|
@@ -50,11 +50,8 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
|
|
|
50
50
|
exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
|
|
51
51
|
function getConfigTemplate() {
|
|
52
52
|
return `{
|
|
53
|
-
// Github personal access token. Must be created here: https://github.com/settings/tokens
|
|
53
|
+
// Github personal access token. Must be created here: https://github.com/settings/tokens
|
|
54
54
|
// Must have "Repo: Full control of private repositories"
|
|
55
|
-
"accessToken": ""
|
|
56
|
-
|
|
57
|
-
// Github username, eg. kimchy
|
|
58
|
-
"username": ""
|
|
55
|
+
"accessToken": ""
|
|
59
56
|
}`;
|
|
60
57
|
}
|
|
@@ -38,7 +38,6 @@ describe('config', () => {
|
|
|
38
38
|
jest.spyOn(fs, 'writeFile').mockResolvedValueOnce();
|
|
39
39
|
jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
|
|
40
40
|
accessToken: 'myAccessToken',
|
|
41
|
-
username: 'sqren',
|
|
42
41
|
}));
|
|
43
42
|
res = await (0, globalConfig_1.getGlobalConfig)();
|
|
44
43
|
});
|
|
@@ -54,7 +53,6 @@ describe('config', () => {
|
|
|
54
53
|
it('should return config', () => {
|
|
55
54
|
expect(res).toEqual({
|
|
56
55
|
accessToken: 'myAccessToken',
|
|
57
|
-
username: 'sqren',
|
|
58
56
|
});
|
|
59
57
|
});
|
|
60
58
|
});
|
|
@@ -27,21 +27,58 @@ const fs = __importStar(require("../../services/fs-promisified"));
|
|
|
27
27
|
const projectConfig_1 = require("./projectConfig");
|
|
28
28
|
describe('getProjectConfig', () => {
|
|
29
29
|
afterEach(() => jest.clearAllMocks());
|
|
30
|
-
describe('
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
describe('deprecations', () => {
|
|
31
|
+
describe('when specifying deprecated `branches`', () => {
|
|
32
|
+
it('is returned as `targetBranchChoices`', async () => {
|
|
33
|
+
jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
|
|
34
|
+
repoName: 'kibana',
|
|
35
|
+
repoOwner: 'elastic',
|
|
36
|
+
branches: ['6.x'],
|
|
37
|
+
}));
|
|
38
|
+
const projectConfig = await (0, projectConfig_1.getProjectConfig)();
|
|
39
|
+
expect(projectConfig?.targetBranchChoices).toEqual(['6.x']);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('when specifying deprecated `labels`', () => {
|
|
43
|
+
it('is returned as `targetPRLabels`', async () => {
|
|
44
|
+
jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
|
|
45
|
+
labels: ['backport'],
|
|
46
|
+
}));
|
|
47
|
+
const projectConfig = await (0, projectConfig_1.getProjectConfig)();
|
|
48
|
+
expect(projectConfig?.targetPRLabels).toEqual(['backport']);
|
|
49
|
+
});
|
|
37
50
|
});
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
describe('when specifying deprecated `upstream`', () => {
|
|
52
|
+
it('is split into `repoOwner` and `repoName`', async () => {
|
|
53
|
+
jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
|
|
54
|
+
upstream: 'elastic/kibana',
|
|
55
|
+
}));
|
|
56
|
+
const projectConfig = await (0, projectConfig_1.getProjectConfig)();
|
|
57
|
+
expect(projectConfig?.repoOwner).toEqual('elastic');
|
|
58
|
+
expect(projectConfig?.repoName).toEqual('kibana');
|
|
59
|
+
});
|
|
40
60
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
describe('when projectConfig is valid', () => {
|
|
62
|
+
let projectConfig;
|
|
63
|
+
beforeEach(async () => {
|
|
64
|
+
jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
|
|
65
|
+
repoName: 'kibana',
|
|
66
|
+
repoOwner: 'elastic',
|
|
67
|
+
targetBranchChoices: ['6.x'],
|
|
68
|
+
targetPRLabels: ['backport'],
|
|
69
|
+
}));
|
|
70
|
+
projectConfig = await (0, projectConfig_1.getProjectConfig)();
|
|
71
|
+
});
|
|
72
|
+
it('should call findUp', () => {
|
|
73
|
+
expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
|
|
74
|
+
});
|
|
75
|
+
it('should return config', () => {
|
|
76
|
+
expect(projectConfig).toEqual({
|
|
77
|
+
repoName: 'kibana',
|
|
78
|
+
repoOwner: 'elastic',
|
|
79
|
+
targetBranchChoices: ['6.x'],
|
|
80
|
+
targetPRLabels: ['backport'],
|
|
81
|
+
});
|
|
45
82
|
});
|
|
46
83
|
});
|
|
47
84
|
});
|
|
@@ -49,7 +86,7 @@ describe('getProjectConfig', () => {
|
|
|
49
86
|
it('should return empty config', async () => {
|
|
50
87
|
jest.spyOn(fs, 'readFile').mockResolvedValueOnce('{}');
|
|
51
88
|
const projectConfig = await (0, projectConfig_1.getProjectConfig)();
|
|
52
|
-
expect(projectConfig).toEqual({
|
|
89
|
+
expect(projectConfig).toEqual({});
|
|
53
90
|
});
|
|
54
91
|
});
|
|
55
92
|
describe('when projectConfig is missing', () => {
|
|
@@ -1,2 +1,54 @@
|
|
|
1
1
|
import { ConfigFileOptions } from '../ConfigOptions';
|
|
2
2
|
export declare function readConfigFile(filepath: string): Promise<ConfigFileOptions>;
|
|
3
|
+
export declare function withConfigMigrations({ upstream, labels, branches, ...config }: ConfigFileOptions): {
|
|
4
|
+
fork?: boolean | undefined;
|
|
5
|
+
verbose?: boolean | undefined;
|
|
6
|
+
accessToken?: string | undefined;
|
|
7
|
+
assignees?: string[] | undefined;
|
|
8
|
+
author?: string | null | undefined;
|
|
9
|
+
autoAssign?: boolean | undefined;
|
|
10
|
+
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
11
|
+
files: string[];
|
|
12
|
+
directory: string;
|
|
13
|
+
logger: {
|
|
14
|
+
error: (message: string, meta?: unknown) => void;
|
|
15
|
+
warn: (message: string, meta?: unknown) => void;
|
|
16
|
+
info: (message: string, meta?: unknown) => void;
|
|
17
|
+
verbose: (message: string, meta?: unknown) => void;
|
|
18
|
+
debug: (message: string, meta?: unknown) => void;
|
|
19
|
+
};
|
|
20
|
+
targetBranch: string;
|
|
21
|
+
}) => boolean | Promise<boolean>) | undefined;
|
|
22
|
+
autoMerge?: boolean | undefined;
|
|
23
|
+
autoMergeMethod?: string | undefined;
|
|
24
|
+
backportBinary?: string | undefined;
|
|
25
|
+
cherrypickRef?: boolean | undefined;
|
|
26
|
+
ci?: boolean | undefined;
|
|
27
|
+
commitPaths?: string[] | undefined;
|
|
28
|
+
details?: boolean | undefined;
|
|
29
|
+
editor?: string | undefined;
|
|
30
|
+
gitHostname?: string | undefined;
|
|
31
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
32
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
33
|
+
maxNumber?: number | undefined;
|
|
34
|
+
multiple?: boolean | undefined;
|
|
35
|
+
multipleBranches?: boolean | undefined;
|
|
36
|
+
multipleCommits?: boolean | undefined;
|
|
37
|
+
noVerify?: boolean | undefined;
|
|
38
|
+
prDescription?: string | undefined;
|
|
39
|
+
prFilter?: string | undefined;
|
|
40
|
+
prTitle?: string | undefined;
|
|
41
|
+
pullNumber?: number | undefined;
|
|
42
|
+
repoName?: string | undefined;
|
|
43
|
+
repoOwner?: string | undefined;
|
|
44
|
+
resetAuthor?: boolean | undefined;
|
|
45
|
+
reviewers?: string[] | undefined;
|
|
46
|
+
sha?: string | undefined;
|
|
47
|
+
skipRemoteConfig?: boolean | undefined;
|
|
48
|
+
sourceBranch?: string | undefined;
|
|
49
|
+
sourcePRLabels?: string[] | undefined;
|
|
50
|
+
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
51
|
+
targetBranches?: string[] | undefined;
|
|
52
|
+
targetPRLabels?: string[] | undefined;
|
|
53
|
+
branchLabelMapping?: Record<string, string> | undefined;
|
|
54
|
+
};
|
|
@@ -3,18 +3,44 @@ 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.readConfigFile = void 0;
|
|
6
|
+
exports.withConfigMigrations = exports.readConfigFile = void 0;
|
|
7
7
|
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
8
8
|
const HandledError_1 = require("../../services/HandledError");
|
|
9
9
|
const fs_promisified_1 = require("../../services/fs-promisified");
|
|
10
|
+
const excludeUndefined_1 = require("../../utils/excludeUndefined");
|
|
10
11
|
async function readConfigFile(filepath) {
|
|
11
12
|
const fileContents = await (0, fs_promisified_1.readFile)(filepath, 'utf8');
|
|
12
13
|
const configWithoutComments = (0, strip_json_comments_1.default)(fileContents);
|
|
13
14
|
try {
|
|
14
|
-
return JSON.parse(configWithoutComments);
|
|
15
|
+
return withConfigMigrations(JSON.parse(configWithoutComments));
|
|
15
16
|
}
|
|
16
17
|
catch (e) {
|
|
17
18
|
throw new HandledError_1.HandledError(`"${filepath}" contains invalid JSON:\n\n${fileContents}`);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
exports.readConfigFile = readConfigFile;
|
|
22
|
+
// ensure backwards compatability when config options are renamed
|
|
23
|
+
function withConfigMigrations({ upstream, labels, branches, ...config }) {
|
|
24
|
+
const { repoName, repoOwner } = parseUpstream(upstream, config);
|
|
25
|
+
return (0, excludeUndefined_1.excludeUndefined)({
|
|
26
|
+
...config,
|
|
27
|
+
// `branches` was renamed `targetBranchChoices`
|
|
28
|
+
targetBranchChoices: config.targetBranchChoices ?? branches,
|
|
29
|
+
// `upstream` has been renamed to `repoOwner`/`repoName`
|
|
30
|
+
repoName,
|
|
31
|
+
repoOwner,
|
|
32
|
+
// `labels` was renamed `targetPRLabels`
|
|
33
|
+
targetPRLabels: config.targetPRLabels ?? labels,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.withConfigMigrations = withConfigMigrations;
|
|
37
|
+
function parseUpstream(upstream, config) {
|
|
38
|
+
if (upstream) {
|
|
39
|
+
const [repoOwner, repoName] = upstream.split('/');
|
|
40
|
+
return { repoOwner, repoName };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
repoOwner: config.repoOwner,
|
|
44
|
+
repoName: config.repoName,
|
|
45
|
+
};
|
|
46
|
+
}
|