backport 6.0.0 → 6.1.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/README.md +158 -42
- 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 +33 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +15 -6
- package/dist/options/cliArgs.d.ts +33 -34
- package/dist/options/cliArgs.js +19 -19
- package/dist/options/cliArgs.test.js +8 -5
- package/dist/options/config/config.d.ts +27 -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 +1 -4
- 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 +51 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +52 -33
- package/dist/options/options.js +98 -7
- package/dist/options/options.test.js +180 -73
- 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 +35 -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 +78 -0
- 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 +66 -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 +15 -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 +42 -34
- package/dist/test/integration/integration.private.test.js +104 -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 +67 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +6 -3
- package/dist/ui/getCommits.d.ts +1 -1
- 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
|
@@ -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,40 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFile
|
|
|
45
17
|
};
|
|
46
18
|
targetBranch: string;
|
|
47
19
|
}) => boolean | Promise<boolean>) | undefined;
|
|
48
|
-
autoMerge
|
|
49
|
-
autoMergeMethod
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
autoMerge?: boolean | undefined;
|
|
21
|
+
autoMergeMethod?: string | undefined;
|
|
22
|
+
cherrypickRef?: boolean | undefined;
|
|
23
|
+
ci?: boolean | undefined;
|
|
52
24
|
commitPaths?: string[] | undefined;
|
|
53
|
-
details
|
|
25
|
+
details?: boolean | undefined;
|
|
54
26
|
editor?: string | undefined;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
maxNumber: number;
|
|
27
|
+
fork?: boolean | undefined;
|
|
28
|
+
gitHostname?: string | undefined;
|
|
29
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
30
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
31
|
+
maxNumber?: number | undefined;
|
|
61
32
|
multiple?: boolean | undefined;
|
|
62
|
-
multipleBranches
|
|
63
|
-
multipleCommits
|
|
64
|
-
noVerify
|
|
33
|
+
multipleBranches?: boolean | undefined;
|
|
34
|
+
multipleCommits?: boolean | undefined;
|
|
35
|
+
noVerify?: boolean | undefined;
|
|
65
36
|
prDescription?: string | undefined;
|
|
66
37
|
prFilter?: string | undefined;
|
|
67
|
-
prTitle
|
|
38
|
+
prTitle?: string | undefined;
|
|
68
39
|
pullNumber?: number | undefined;
|
|
69
|
-
|
|
40
|
+
repoName?: string | undefined;
|
|
41
|
+
repoOwner?: string | undefined;
|
|
42
|
+
resetAuthor?: boolean | undefined;
|
|
70
43
|
reviewers?: string[] | undefined;
|
|
71
44
|
sha?: string | undefined;
|
|
45
|
+
skipRemoteConfig?: boolean | undefined;
|
|
72
46
|
sourceBranch?: string | undefined;
|
|
73
|
-
sourcePRLabels
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
verbose
|
|
47
|
+
sourcePRLabels?: string[] | undefined;
|
|
48
|
+
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
49
|
+
targetBranches?: string[] | undefined;
|
|
50
|
+
targetPRLabels?: string[] | undefined;
|
|
51
|
+
verbose?: boolean | undefined;
|
|
78
52
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
53
|
+
upstream?: string | undefined;
|
|
79
54
|
branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
80
55
|
labels?: string[] | undefined;
|
|
81
56
|
}>;
|
|
@@ -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;
|
|
@@ -52,9 +52,6 @@ function getConfigTemplate() {
|
|
|
52
52
|
return `{
|
|
53
53
|
// Github personal access token. Must be created here: https://github.com/settings/tokens/new
|
|
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,53 @@
|
|
|
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
|
+
cherrypickRef?: boolean | undefined;
|
|
25
|
+
ci?: boolean | undefined;
|
|
26
|
+
commitPaths?: string[] | undefined;
|
|
27
|
+
details?: boolean | undefined;
|
|
28
|
+
editor?: string | undefined;
|
|
29
|
+
gitHostname?: string | undefined;
|
|
30
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
31
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
32
|
+
maxNumber?: number | undefined;
|
|
33
|
+
multiple?: boolean | undefined;
|
|
34
|
+
multipleBranches?: boolean | undefined;
|
|
35
|
+
multipleCommits?: boolean | undefined;
|
|
36
|
+
noVerify?: boolean | undefined;
|
|
37
|
+
prDescription?: string | undefined;
|
|
38
|
+
prFilter?: string | undefined;
|
|
39
|
+
prTitle?: string | undefined;
|
|
40
|
+
pullNumber?: number | undefined;
|
|
41
|
+
repoName?: string | undefined;
|
|
42
|
+
repoOwner?: string | undefined;
|
|
43
|
+
resetAuthor?: boolean | undefined;
|
|
44
|
+
reviewers?: string[] | undefined;
|
|
45
|
+
sha?: string | undefined;
|
|
46
|
+
skipRemoteConfig?: boolean | undefined;
|
|
47
|
+
sourceBranch?: string | undefined;
|
|
48
|
+
sourcePRLabels?: string[] | undefined;
|
|
49
|
+
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
50
|
+
targetBranches?: string[] | undefined;
|
|
51
|
+
targetPRLabels?: string[] | undefined;
|
|
52
|
+
branchLabelMapping?: Record<string, string> | undefined;
|
|
53
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -1,45 +1,66 @@
|
|
|
1
|
-
import { ConfigFileOptions } from './ConfigOptions';
|
|
1
|
+
import { ConfigFileOptions, TargetBranchChoiceOrString } from './ConfigOptions';
|
|
2
2
|
export declare type ValidConfigOptions = Readonly<Awaited<ReturnType<typeof getOptions>>>;
|
|
3
|
-
export declare
|
|
4
|
-
targetBranchChoices: import("./ConfigOptions").TargetBranchChoice[];
|
|
5
|
-
accessToken: string;
|
|
6
|
-
username: string;
|
|
7
|
-
repoName: string;
|
|
8
|
-
repoOwner: string;
|
|
3
|
+
export declare const defaultConfigOptions: {
|
|
9
4
|
assignees: string[];
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
autoAssign: boolean;
|
|
6
|
+
autoMerge: boolean;
|
|
7
|
+
autoMergeMethod: string;
|
|
8
|
+
cherrypickRef: boolean;
|
|
9
|
+
ci: boolean;
|
|
10
|
+
details: boolean;
|
|
11
|
+
fork: boolean;
|
|
12
|
+
maxNumber: number;
|
|
12
13
|
multipleBranches: boolean;
|
|
13
14
|
multipleCommits: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
sourcePRLabels:
|
|
17
|
-
|
|
15
|
+
noVerify: boolean;
|
|
16
|
+
resetAuthor: boolean;
|
|
17
|
+
sourcePRLabels: string[];
|
|
18
|
+
targetBranchChoices: TargetBranchChoiceOrString[];
|
|
19
|
+
targetBranches: string[];
|
|
18
20
|
targetPRLabels: string[];
|
|
19
|
-
|
|
21
|
+
verbose: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
|
|
24
|
+
accessToken: string;
|
|
25
|
+
repoName: string;
|
|
26
|
+
repoOwner: string;
|
|
20
27
|
fork: boolean;
|
|
21
|
-
|
|
28
|
+
verbose: boolean;
|
|
29
|
+
assignees: string[];
|
|
30
|
+
author: string | null;
|
|
22
31
|
autoAssign: boolean;
|
|
23
32
|
autoMerge: boolean;
|
|
24
33
|
autoMergeMethod: string;
|
|
34
|
+
cherrypickRef: boolean;
|
|
25
35
|
ci: boolean;
|
|
36
|
+
commitPaths: string[];
|
|
26
37
|
details: boolean;
|
|
27
|
-
editor
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
githubApiBaseUrlV4: string;
|
|
32
|
-
mainline: number | undefined;
|
|
38
|
+
editor?: string | undefined;
|
|
39
|
+
gitHostname?: string | undefined;
|
|
40
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
41
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
33
42
|
maxNumber: number;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
multipleBranches: boolean;
|
|
44
|
+
multipleCommits: boolean;
|
|
45
|
+
noVerify: boolean;
|
|
46
|
+
prDescription?: string | undefined;
|
|
47
|
+
prFilter?: string | undefined;
|
|
48
|
+
prTitle?: string | undefined;
|
|
49
|
+
pullNumber?: number | undefined;
|
|
38
50
|
resetAuthor: boolean;
|
|
39
|
-
|
|
51
|
+
reviewers: string[];
|
|
52
|
+
sha?: string | undefined;
|
|
53
|
+
skipRemoteConfig?: boolean | undefined;
|
|
40
54
|
sourceBranch: string;
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
sourcePRLabels: string[];
|
|
56
|
+
targetBranchChoices: string[] | TargetBranchChoiceOrString[];
|
|
57
|
+
targetBranches: string[];
|
|
58
|
+
targetPRLabels: string[];
|
|
59
|
+
mainline?: number | undefined;
|
|
60
|
+
historicalBranchLabelMappings: {
|
|
61
|
+
branchLabelMapping: Record<string, string>;
|
|
62
|
+
committedDate: string;
|
|
63
|
+
}[];
|
|
43
64
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
44
65
|
files: string[];
|
|
45
66
|
directory: string;
|
|
@@ -54,10 +75,8 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
54
75
|
}) => boolean | Promise<boolean>) | undefined;
|
|
55
76
|
multiple?: boolean | undefined;
|
|
56
77
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
57
|
-
|
|
78
|
+
upstream?: string | undefined;
|
|
79
|
+
branches?: TargetBranchChoiceOrString[] | undefined;
|
|
58
80
|
labels?: string[] | undefined;
|
|
59
|
-
|
|
60
|
-
branchLabelMapping: Record<string, string>;
|
|
61
|
-
committedDate: string;
|
|
62
|
-
}[];
|
|
81
|
+
authenticatedUsername: string;
|
|
63
82
|
}>;
|
package/dist/options/options.js
CHANGED
|
@@ -1,18 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOptions = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.getOptions = exports.defaultConfigOptions = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const HandledError_1 = require("../services/HandledError");
|
|
6
|
+
const env_1 = require("../services/env");
|
|
7
|
+
const getOptionsFromGithub_1 = require("../services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
|
|
5
8
|
const logger_1 = require("./../services/logger");
|
|
6
9
|
const cliArgs_1 = require("./cliArgs");
|
|
7
10
|
const config_1 = require("./config/config");
|
|
8
|
-
const
|
|
11
|
+
const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson';
|
|
12
|
+
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson';
|
|
13
|
+
exports.defaultConfigOptions = {
|
|
14
|
+
assignees: [],
|
|
15
|
+
autoAssign: false,
|
|
16
|
+
autoMerge: false,
|
|
17
|
+
autoMergeMethod: 'merge',
|
|
18
|
+
cherrypickRef: true,
|
|
19
|
+
ci: false,
|
|
20
|
+
details: false,
|
|
21
|
+
fork: true,
|
|
22
|
+
maxNumber: 10,
|
|
23
|
+
multipleBranches: true,
|
|
24
|
+
multipleCommits: false,
|
|
25
|
+
noVerify: true,
|
|
26
|
+
resetAuthor: false,
|
|
27
|
+
sourcePRLabels: [],
|
|
28
|
+
targetBranchChoices: [],
|
|
29
|
+
targetBranches: [],
|
|
30
|
+
targetPRLabels: [],
|
|
31
|
+
verbose: false,
|
|
32
|
+
};
|
|
9
33
|
async function getOptions(argv, optionsFromModule) {
|
|
10
34
|
const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)(optionsFromModule);
|
|
11
35
|
const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
36
|
+
// combined options from cli and config files
|
|
37
|
+
const combined = getCombinedOptions({
|
|
38
|
+
optionsFromConfigFiles,
|
|
39
|
+
optionsFromCliArgs,
|
|
40
|
+
});
|
|
12
41
|
// update logger
|
|
13
|
-
(0, logger_1.updateLogger)(
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
42
|
+
(0, logger_1.updateLogger)(combined);
|
|
43
|
+
// required
|
|
44
|
+
const accessToken = requireAccessToken(combined);
|
|
45
|
+
const repoName = requireRepoName(combined);
|
|
46
|
+
const repoOwner = requireRepoOwner(combined);
|
|
47
|
+
const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)({
|
|
48
|
+
...combined,
|
|
49
|
+
// required props
|
|
50
|
+
accessToken,
|
|
51
|
+
repoName,
|
|
52
|
+
repoOwner,
|
|
53
|
+
});
|
|
54
|
+
const res = {
|
|
55
|
+
// default author
|
|
56
|
+
author: optionsFromGithub.authenticatedUsername,
|
|
57
|
+
// default values have lowest precedence
|
|
58
|
+
...exports.defaultConfigOptions,
|
|
59
|
+
// local config options override default options
|
|
60
|
+
...optionsFromConfigFiles,
|
|
61
|
+
// remote config options override local config options
|
|
62
|
+
...optionsFromGithub,
|
|
63
|
+
// cli args override the above
|
|
64
|
+
...optionsFromCliArgs,
|
|
65
|
+
// required properties
|
|
66
|
+
accessToken,
|
|
67
|
+
repoName,
|
|
68
|
+
repoOwner,
|
|
69
|
+
};
|
|
70
|
+
requireTargetBranch(res);
|
|
71
|
+
return res;
|
|
17
72
|
}
|
|
18
73
|
exports.getOptions = getOptions;
|
|
74
|
+
function getCombinedOptions({ optionsFromConfigFiles, optionsFromCliArgs, }) {
|
|
75
|
+
return {
|
|
76
|
+
...exports.defaultConfigOptions,
|
|
77
|
+
...optionsFromConfigFiles,
|
|
78
|
+
...optionsFromCliArgs,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function requireAccessToken(combinedOptions) {
|
|
82
|
+
// accessToken must be supplied in config or via cli args
|
|
83
|
+
if (!combinedOptions.accessToken) {
|
|
84
|
+
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
85
|
+
throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
|
|
86
|
+
}
|
|
87
|
+
return combinedOptions.accessToken;
|
|
88
|
+
}
|
|
89
|
+
function requireRepoName(combinedOptions) {
|
|
90
|
+
if (!combinedOptions.repoName) {
|
|
91
|
+
throw new HandledError_1.HandledError(`Please specify a repo name: "--repo-name kibana". \n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
92
|
+
}
|
|
93
|
+
return combinedOptions.repoName;
|
|
94
|
+
}
|
|
95
|
+
function requireRepoOwner(combinedOptions) {
|
|
96
|
+
if (!combinedOptions.repoOwner) {
|
|
97
|
+
throw new HandledError_1.HandledError(`Please specify a repo owner: "--repo-owner elastic". \n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
98
|
+
}
|
|
99
|
+
return combinedOptions.repoOwner;
|
|
100
|
+
}
|
|
101
|
+
function requireTargetBranch(config) {
|
|
102
|
+
// ensure `targetBranches` or `targetBranchChoices` are given
|
|
103
|
+
if ((0, lodash_1.isEmpty)(config.targetBranches) &&
|
|
104
|
+
(0, lodash_1.isEmpty)(config.targetBranchChoices) &&
|
|
105
|
+
// this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
|
|
106
|
+
(0, lodash_1.isEmpty)(config.branchLabelMapping)) {
|
|
107
|
+
throw new HandledError_1.HandledError(`Please specify a target branch: "--branch 6.1". \n\n Read more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
108
|
+
}
|
|
109
|
+
}
|