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
|
@@ -1,45 +1,69 @@
|
|
|
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
|
+
backportBinary: string;
|
|
9
|
+
cherrypickRef: boolean;
|
|
10
|
+
ci: boolean;
|
|
11
|
+
commitPaths: string[];
|
|
12
|
+
details: boolean;
|
|
13
|
+
fork: boolean;
|
|
14
|
+
maxNumber: number;
|
|
12
15
|
multipleBranches: boolean;
|
|
13
16
|
multipleCommits: boolean;
|
|
14
|
-
|
|
17
|
+
noVerify: boolean;
|
|
18
|
+
resetAuthor: boolean;
|
|
15
19
|
reviewers: string[];
|
|
16
|
-
sourcePRLabels:
|
|
17
|
-
|
|
20
|
+
sourcePRLabels: string[];
|
|
21
|
+
targetBranchChoices: TargetBranchChoiceOrString[];
|
|
22
|
+
targetBranches: string[];
|
|
18
23
|
targetPRLabels: string[];
|
|
19
|
-
|
|
24
|
+
verbose: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
|
|
27
|
+
accessToken: string;
|
|
28
|
+
repoName: string;
|
|
29
|
+
repoOwner: string;
|
|
20
30
|
fork: boolean;
|
|
21
|
-
|
|
31
|
+
verbose: boolean;
|
|
32
|
+
assignees: string[];
|
|
33
|
+
author: string | null;
|
|
22
34
|
autoAssign: boolean;
|
|
23
35
|
autoMerge: boolean;
|
|
24
36
|
autoMergeMethod: string;
|
|
37
|
+
cherrypickRef: boolean;
|
|
25
38
|
ci: boolean;
|
|
39
|
+
commitPaths: string[];
|
|
26
40
|
details: boolean;
|
|
27
|
-
editor
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
githubApiBaseUrlV4: string;
|
|
32
|
-
mainline: number | undefined;
|
|
41
|
+
editor?: string | undefined;
|
|
42
|
+
gitHostname?: string | undefined;
|
|
43
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
44
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
33
45
|
maxNumber: number;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
multipleBranches: boolean;
|
|
47
|
+
multipleCommits: boolean;
|
|
48
|
+
noVerify: boolean;
|
|
49
|
+
prDescription?: string | undefined;
|
|
50
|
+
prFilter?: string | undefined;
|
|
51
|
+
prTitle?: string | undefined;
|
|
52
|
+
pullNumber?: number | undefined;
|
|
38
53
|
resetAuthor: boolean;
|
|
39
|
-
|
|
54
|
+
reviewers: string[];
|
|
55
|
+
sha?: string | undefined;
|
|
56
|
+
skipRemoteConfig?: boolean | undefined;
|
|
40
57
|
sourceBranch: string;
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
sourcePRLabels: string[];
|
|
59
|
+
targetBranchChoices: string[] | TargetBranchChoiceOrString[];
|
|
60
|
+
targetBranches: string[];
|
|
61
|
+
targetPRLabels: string[];
|
|
62
|
+
mainline?: number | undefined;
|
|
63
|
+
historicalBranchLabelMappings: {
|
|
64
|
+
branchLabelMapping: Record<string, string>;
|
|
65
|
+
committedDate: string;
|
|
66
|
+
}[];
|
|
43
67
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
44
68
|
files: string[];
|
|
45
69
|
directory: string;
|
|
@@ -52,12 +76,11 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
52
76
|
};
|
|
53
77
|
targetBranch: string;
|
|
54
78
|
}) => boolean | Promise<boolean>) | undefined;
|
|
79
|
+
backportBinary: string;
|
|
55
80
|
multiple?: boolean | undefined;
|
|
56
81
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
57
|
-
|
|
82
|
+
upstream?: string | undefined;
|
|
83
|
+
branches?: TargetBranchChoiceOrString[] | undefined;
|
|
58
84
|
labels?: string[] | undefined;
|
|
59
|
-
|
|
60
|
-
branchLabelMapping: Record<string, string>;
|
|
61
|
-
committedDate: string;
|
|
62
|
-
}[];
|
|
85
|
+
authenticatedUsername: string;
|
|
63
86
|
}>;
|
package/dist/options/options.js
CHANGED
|
@@ -1,18 +1,112 @@
|
|
|
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
|
+
backportBinary: 'backport',
|
|
19
|
+
cherrypickRef: true,
|
|
20
|
+
ci: false,
|
|
21
|
+
commitPaths: [],
|
|
22
|
+
details: false,
|
|
23
|
+
fork: true,
|
|
24
|
+
maxNumber: 10,
|
|
25
|
+
multipleBranches: true,
|
|
26
|
+
multipleCommits: false,
|
|
27
|
+
noVerify: true,
|
|
28
|
+
resetAuthor: false,
|
|
29
|
+
reviewers: [],
|
|
30
|
+
sourcePRLabels: [],
|
|
31
|
+
targetBranchChoices: [],
|
|
32
|
+
targetBranches: [],
|
|
33
|
+
targetPRLabels: [],
|
|
34
|
+
verbose: false,
|
|
35
|
+
};
|
|
9
36
|
async function getOptions(argv, optionsFromModule) {
|
|
10
37
|
const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)(optionsFromModule);
|
|
11
38
|
const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
39
|
+
// combined options from cli and config files
|
|
40
|
+
const combined = getCombinedOptions({
|
|
41
|
+
optionsFromConfigFiles,
|
|
42
|
+
optionsFromCliArgs,
|
|
43
|
+
});
|
|
12
44
|
// update logger
|
|
13
|
-
(0, logger_1.updateLogger)(
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
45
|
+
(0, logger_1.updateLogger)(combined);
|
|
46
|
+
// required
|
|
47
|
+
const accessToken = requireAccessToken(combined);
|
|
48
|
+
const repoName = requireRepoName(combined);
|
|
49
|
+
const repoOwner = requireRepoOwner(combined);
|
|
50
|
+
const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)({
|
|
51
|
+
...combined,
|
|
52
|
+
// required props
|
|
53
|
+
accessToken,
|
|
54
|
+
repoName,
|
|
55
|
+
repoOwner,
|
|
56
|
+
});
|
|
57
|
+
const res = {
|
|
58
|
+
// default author
|
|
59
|
+
author: optionsFromGithub.authenticatedUsername,
|
|
60
|
+
// default values have lowest precedence
|
|
61
|
+
...exports.defaultConfigOptions,
|
|
62
|
+
// local config options override default options
|
|
63
|
+
...optionsFromConfigFiles,
|
|
64
|
+
// remote config options override local config options
|
|
65
|
+
...optionsFromGithub,
|
|
66
|
+
// cli args override the above
|
|
67
|
+
...optionsFromCliArgs,
|
|
68
|
+
// required properties
|
|
69
|
+
accessToken,
|
|
70
|
+
repoName,
|
|
71
|
+
repoOwner,
|
|
72
|
+
};
|
|
73
|
+
requireTargetBranch(res);
|
|
74
|
+
return res;
|
|
17
75
|
}
|
|
18
76
|
exports.getOptions = getOptions;
|
|
77
|
+
function getCombinedOptions({ optionsFromConfigFiles, optionsFromCliArgs, }) {
|
|
78
|
+
return {
|
|
79
|
+
...exports.defaultConfigOptions,
|
|
80
|
+
...optionsFromConfigFiles,
|
|
81
|
+
...optionsFromCliArgs,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function requireAccessToken(combinedOptions) {
|
|
85
|
+
// accessToken must be supplied in config or via cli args
|
|
86
|
+
if (!combinedOptions.accessToken) {
|
|
87
|
+
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
88
|
+
throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
|
|
89
|
+
}
|
|
90
|
+
return combinedOptions.accessToken;
|
|
91
|
+
}
|
|
92
|
+
function requireRepoName(combinedOptions) {
|
|
93
|
+
if (!combinedOptions.repoName) {
|
|
94
|
+
throw new HandledError_1.HandledError(`Please specify a repo name: "--repo-name kibana".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
95
|
+
}
|
|
96
|
+
return combinedOptions.repoName;
|
|
97
|
+
}
|
|
98
|
+
function requireRepoOwner(combinedOptions) {
|
|
99
|
+
if (!combinedOptions.repoOwner) {
|
|
100
|
+
throw new HandledError_1.HandledError(`Please specify a repo owner: "--repo-owner elastic".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
101
|
+
}
|
|
102
|
+
return combinedOptions.repoOwner;
|
|
103
|
+
}
|
|
104
|
+
function requireTargetBranch(config) {
|
|
105
|
+
// ensure `targetBranches` or `targetBranchChoices` are given
|
|
106
|
+
if ((0, lodash_1.isEmpty)(config.targetBranches) &&
|
|
107
|
+
(0, lodash_1.isEmpty)(config.targetBranchChoices) &&
|
|
108
|
+
// this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
|
|
109
|
+
(0, lodash_1.isEmpty)(config.branchLabelMapping)) {
|
|
110
|
+
throw new HandledError_1.HandledError(`Please specify a target branch: "--branch 6.1".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -24,159 +24,310 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
const nock_1 = __importDefault(require("nock"));
|
|
26
26
|
const logger = __importStar(require("../services/logger"));
|
|
27
|
+
const mockConfigFiles_1 = require("../test/mockConfigFiles");
|
|
27
28
|
const nockHelpers_1 = require("../test/nockHelpers");
|
|
28
29
|
const options_1 = require("./options");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
statusCode: 200,
|
|
33
|
-
body: {
|
|
34
|
-
data: {
|
|
35
|
-
repository: {
|
|
36
|
-
isFork: false,
|
|
37
|
-
parent: null,
|
|
38
|
-
ref: refName ? { name: refName } : null,
|
|
39
|
-
defaultBranchRef: {
|
|
40
|
-
name: defaultBranch,
|
|
41
|
-
target: { history: { edges: [] } },
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
describe('getOptions', () => {
|
|
49
|
-
const defaultArgs = [
|
|
50
|
-
'--branch',
|
|
51
|
-
'6.0',
|
|
52
|
-
'--branch',
|
|
53
|
-
'6.1',
|
|
54
|
-
'--upstream',
|
|
55
|
-
'elastic/kibana',
|
|
30
|
+
jest.unmock('../services/fs-promisified');
|
|
31
|
+
const defaultConfigs = {
|
|
32
|
+
projectConfig: {
|
|
56
33
|
// use localhost to avoid CORS issues with nock
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
|
|
34
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
35
|
+
repoOwner: 'elastic',
|
|
36
|
+
repoName: 'kibana',
|
|
37
|
+
targetBranchChoices: ['7.9', '8.0'],
|
|
38
|
+
},
|
|
39
|
+
globalConfig: { accessToken: 'abc', editor: 'code' },
|
|
40
|
+
};
|
|
41
|
+
describe('getOptions', () => {
|
|
60
42
|
afterEach(() => {
|
|
61
43
|
jest.clearAllMocks();
|
|
62
44
|
nock_1.default.cleanAll();
|
|
63
45
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
defaultBranch: 'my-default-branch',
|
|
67
|
-
});
|
|
68
|
-
const options = await (0, options_1.getOptions)(defaultArgs);
|
|
69
|
-
expect(mockCalls.length).toBe(1);
|
|
70
|
-
expect(options.sourceBranch).toBe('my-default-branch');
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
(0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
|
|
71
48
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
describe('should throw', () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
mockGithubConfigOptions({});
|
|
52
|
+
});
|
|
53
|
+
it('when accessToken is missing', async () => {
|
|
54
|
+
(0, mockConfigFiles_1.mockConfigFiles)({
|
|
55
|
+
projectConfig: defaultConfigs.projectConfig,
|
|
56
|
+
globalConfig: { accessToken: undefined },
|
|
57
|
+
});
|
|
58
|
+
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
59
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
60
|
+
"Please update your config file: /Users/sqren/.backport/config.json.
|
|
61
|
+
It must contain a valid \\"accessToken\\".
|
|
62
|
+
|
|
63
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
64
|
+
`);
|
|
65
|
+
});
|
|
66
|
+
it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
|
|
67
|
+
mockProjectConfig({
|
|
68
|
+
targetBranches: undefined,
|
|
69
|
+
targetBranchChoices: undefined,
|
|
70
|
+
branchLabelMapping: undefined,
|
|
71
|
+
});
|
|
72
|
+
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
73
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
74
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
75
|
+
|
|
76
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
77
|
+
`);
|
|
78
|
+
});
|
|
79
|
+
it('when repoName is missing', async () => {
|
|
80
|
+
mockProjectConfig({ repoName: '' });
|
|
81
|
+
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
82
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
83
|
+
"Please specify a repo name: \\"--repo-name kibana\\".
|
|
84
|
+
|
|
85
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
86
|
+
`);
|
|
87
|
+
});
|
|
88
|
+
it('when repoOwner is missing', async () => {
|
|
89
|
+
mockProjectConfig({ repoOwner: '' });
|
|
90
|
+
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
91
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
92
|
+
"Please specify a repo owner: \\"--repo-owner elastic\\".
|
|
93
|
+
|
|
94
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
95
|
+
`);
|
|
96
|
+
});
|
|
88
97
|
});
|
|
89
98
|
it('should ensure that "backport" branch does not exist', async () => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
refName: 'backport',
|
|
93
|
-
});
|
|
94
|
-
await expect((0, options_1.getOptions)(defaultArgs)).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
99
|
+
mockGithubConfigOptions({ refName: 'backport' });
|
|
100
|
+
await expect((0, options_1.getOptions)([])).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
95
101
|
});
|
|
96
102
|
it('should merge config options and module options', async () => {
|
|
97
|
-
|
|
103
|
+
mockGithubConfigOptions({});
|
|
98
104
|
const myFn = async () => true;
|
|
99
|
-
const options = await (0, options_1.getOptions)(
|
|
105
|
+
const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
|
|
100
106
|
expect(options.autoFixConflicts).toBe(myFn);
|
|
101
107
|
});
|
|
102
108
|
it('should call updateLogger', async () => {
|
|
103
|
-
|
|
104
|
-
await (0, options_1.getOptions)(
|
|
109
|
+
mockGithubConfigOptions({});
|
|
110
|
+
await (0, options_1.getOptions)([]);
|
|
105
111
|
expect(logger.updateLogger).toHaveBeenCalledTimes(1);
|
|
106
112
|
});
|
|
107
113
|
it('should return options', async () => {
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
mockGithubConfigOptions({
|
|
115
|
+
viewerLogin: 'john.diller',
|
|
116
|
+
defaultBranchRef: 'default-branch-from-github',
|
|
117
|
+
historicalMappings: [
|
|
118
|
+
{
|
|
119
|
+
committedDate: '2022-01-02T20:52:45.173Z',
|
|
120
|
+
branchLabelMapping: { foo: 'bar' },
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
const options = await (0, options_1.getOptions)([]);
|
|
110
125
|
expect(options).toEqual({
|
|
111
|
-
accessToken: '
|
|
112
|
-
all: false,
|
|
126
|
+
accessToken: 'abc',
|
|
113
127
|
assignees: [],
|
|
114
|
-
author: 'sqren',
|
|
115
128
|
autoAssign: false,
|
|
129
|
+
authenticatedUsername: 'john.diller',
|
|
116
130
|
autoMerge: false,
|
|
117
131
|
autoMergeMethod: 'merge',
|
|
118
|
-
|
|
132
|
+
backportBinary: 'backport',
|
|
133
|
+
branchLabelMapping: {
|
|
134
|
+
foo: 'bar',
|
|
135
|
+
},
|
|
119
136
|
cherrypickRef: true,
|
|
137
|
+
ci: false,
|
|
138
|
+
commitPaths: [],
|
|
120
139
|
details: false,
|
|
140
|
+
editor: 'code',
|
|
121
141
|
fork: true,
|
|
122
|
-
gitHostname: 'github.com',
|
|
123
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
124
142
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
historicalBranchLabelMappings: [
|
|
144
|
+
{
|
|
145
|
+
branchLabelMapping: { foo: 'bar' },
|
|
146
|
+
committedDate: '2022-01-02T20:52:45.173Z',
|
|
147
|
+
},
|
|
148
|
+
],
|
|
127
149
|
maxNumber: 10,
|
|
128
150
|
multipleBranches: true,
|
|
129
151
|
multipleCommits: false,
|
|
130
152
|
noVerify: true,
|
|
131
|
-
prTitle: '[{targetBranch}] {commitMessages}',
|
|
132
153
|
repoName: 'kibana',
|
|
133
154
|
repoOwner: 'elastic',
|
|
134
155
|
resetAuthor: false,
|
|
135
156
|
reviewers: [],
|
|
136
157
|
sourceBranch: 'default-branch-from-github',
|
|
137
158
|
sourcePRLabels: [],
|
|
138
|
-
targetBranchChoices: [
|
|
139
|
-
|
|
140
|
-
{ checked: false, name: '5.9' },
|
|
141
|
-
],
|
|
142
|
-
targetBranches: ['6.0', '6.1'],
|
|
159
|
+
targetBranchChoices: ['7.9', '8.0'],
|
|
160
|
+
targetBranches: [],
|
|
143
161
|
targetPRLabels: [],
|
|
144
|
-
|
|
145
|
-
username: 'sqren',
|
|
162
|
+
author: 'john.diller',
|
|
146
163
|
verbose: false,
|
|
147
164
|
});
|
|
148
165
|
});
|
|
166
|
+
describe('sourceBranch', () => {
|
|
167
|
+
beforeEach(() => {
|
|
168
|
+
mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
|
|
169
|
+
});
|
|
170
|
+
it('uses the `defaultBranchRef` as default', async () => {
|
|
171
|
+
const options = await (0, options_1.getOptions)([]);
|
|
172
|
+
expect(options.sourceBranch).toBe('some-default-branch');
|
|
173
|
+
});
|
|
174
|
+
it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
|
|
175
|
+
const options = await (0, options_1.getOptions)([
|
|
176
|
+
'--source-branch',
|
|
177
|
+
'cli-source-branch',
|
|
178
|
+
]);
|
|
179
|
+
expect(options.sourceBranch).toBe('cli-source-branch');
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('fork', () => {
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
mockGithubConfigOptions({});
|
|
185
|
+
});
|
|
186
|
+
it('is enabled by default', async () => {
|
|
187
|
+
const { fork } = await (0, options_1.getOptions)([]);
|
|
188
|
+
expect(fork).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
it('can be disabled via `--no-fork` flag', async () => {
|
|
191
|
+
const { fork } = await (0, options_1.getOptions)(['--no-fork']);
|
|
192
|
+
expect(fork).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
it('can be disabled via config file', async () => {
|
|
195
|
+
mockProjectConfig({ fork: false });
|
|
196
|
+
const { fork } = await (0, options_1.getOptions)([]);
|
|
197
|
+
expect(fork).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('reviewers', () => {
|
|
201
|
+
beforeEach(() => {
|
|
202
|
+
mockGithubConfigOptions({});
|
|
203
|
+
});
|
|
204
|
+
it('can be set via `--reviewer` flag', async () => {
|
|
205
|
+
const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter']);
|
|
206
|
+
expect(reviewers).toEqual(['peter']);
|
|
207
|
+
});
|
|
208
|
+
it('can be set via config file', async () => {
|
|
209
|
+
mockProjectConfig({ reviewers: ['john'] });
|
|
210
|
+
const { reviewers } = await (0, options_1.getOptions)([]);
|
|
211
|
+
expect(reviewers).toEqual(['john']);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe('mainline', () => {
|
|
215
|
+
beforeEach(() => {
|
|
216
|
+
mockGithubConfigOptions({});
|
|
217
|
+
});
|
|
218
|
+
it('is not enabled by default', async () => {
|
|
219
|
+
const { mainline } = await (0, options_1.getOptions)([]);
|
|
220
|
+
expect(mainline).toBe(undefined);
|
|
221
|
+
});
|
|
222
|
+
it('can be set via `--mainline` flag', async () => {
|
|
223
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline']);
|
|
224
|
+
expect(mainline).toBe(1);
|
|
225
|
+
});
|
|
226
|
+
it('accepts numeric values', async () => {
|
|
227
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline', '2']);
|
|
228
|
+
expect(mainline).toBe(2);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
describe('author', () => {
|
|
232
|
+
beforeEach(() => {
|
|
233
|
+
mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
|
|
234
|
+
});
|
|
235
|
+
it('defaults to authenticated user', async () => {
|
|
236
|
+
const { author } = await (0, options_1.getOptions)([]);
|
|
237
|
+
expect(author).toBe('billy.bob');
|
|
238
|
+
});
|
|
239
|
+
it('can be overridden via `--author` flag', async () => {
|
|
240
|
+
const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
|
|
241
|
+
expect(author).toBe('john.doe');
|
|
242
|
+
});
|
|
243
|
+
it('can be reset via `--all` flag', async () => {
|
|
244
|
+
const { author } = await (0, options_1.getOptions)(['--all']);
|
|
245
|
+
expect(author).toBe(null);
|
|
246
|
+
});
|
|
247
|
+
it('can be reset via config file (similar to `--all` flag)', async () => {
|
|
248
|
+
mockProjectConfig({ author: null });
|
|
249
|
+
const { author } = await (0, options_1.getOptions)([]);
|
|
250
|
+
expect(author).toBe(null);
|
|
251
|
+
});
|
|
252
|
+
it('can be overridden via config file', async () => {
|
|
253
|
+
mockProjectConfig({ author: 'jane.doe' });
|
|
254
|
+
const { author } = await (0, options_1.getOptions)([]);
|
|
255
|
+
expect(author).toBe('jane.doe');
|
|
256
|
+
});
|
|
257
|
+
});
|
|
149
258
|
describe('cherrypickRef', () => {
|
|
150
259
|
beforeEach(() => {
|
|
151
|
-
|
|
260
|
+
mockGithubConfigOptions({});
|
|
152
261
|
});
|
|
153
|
-
const defaultArgs = [
|
|
154
|
-
// use localhost to avoid CORS issues with nock
|
|
155
|
-
'--github-api-base-url-v4',
|
|
156
|
-
'http://localhost/graphql',
|
|
157
|
-
];
|
|
158
262
|
it('should default to true', async () => {
|
|
159
|
-
const { cherrypickRef } = await (0, options_1.getOptions)(
|
|
263
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
160
264
|
expect(cherrypickRef).toBe(true);
|
|
161
265
|
});
|
|
162
266
|
it('should negate with `noCherrypickRef` cli arg', async () => {
|
|
163
|
-
const { cherrypickRef } = await (0, options_1.getOptions)([
|
|
164
|
-
...defaultArgs,
|
|
165
|
-
'--no-cherrypick-ref',
|
|
166
|
-
]);
|
|
267
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref']);
|
|
167
268
|
expect(cherrypickRef).toBe(false);
|
|
168
269
|
});
|
|
169
270
|
it('should be settable via config file', async () => {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
271
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
272
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
173
273
|
expect(cherrypickRef).toBe(false);
|
|
174
274
|
});
|
|
175
275
|
it('cli args overwrites config', async () => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
276
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
277
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref']);
|
|
179
278
|
expect(cherrypickRef).toBe(true);
|
|
180
279
|
});
|
|
181
280
|
});
|
|
182
281
|
});
|
|
282
|
+
function mockProjectConfig(projectConfig) {
|
|
283
|
+
return (0, mockConfigFiles_1.mockConfigFiles)({
|
|
284
|
+
globalConfig: { accessToken: 'abc' },
|
|
285
|
+
projectConfig: {
|
|
286
|
+
// use localhost to avoid CORS issues with nock
|
|
287
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
288
|
+
repoOwner: 'elastic',
|
|
289
|
+
repoName: 'kibana',
|
|
290
|
+
targetBranchChoices: ['7.9', '8.0'],
|
|
291
|
+
...projectConfig,
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
|
|
296
|
+
return (0, nockHelpers_1.mockGqlRequest)({
|
|
297
|
+
name: 'GithubConfigOptions',
|
|
298
|
+
statusCode: 200,
|
|
299
|
+
body: {
|
|
300
|
+
data: {
|
|
301
|
+
viewer: {
|
|
302
|
+
login: viewerLogin,
|
|
303
|
+
},
|
|
304
|
+
repository: {
|
|
305
|
+
isFork: false,
|
|
306
|
+
parent: null,
|
|
307
|
+
ref: refName ? { name: refName } : null,
|
|
308
|
+
defaultBranchRef: {
|
|
309
|
+
name: defaultBranchRef,
|
|
310
|
+
target: {
|
|
311
|
+
history: {
|
|
312
|
+
edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
|
|
313
|
+
return {
|
|
314
|
+
remoteConfig: {
|
|
315
|
+
committedDate,
|
|
316
|
+
file: {
|
|
317
|
+
object: {
|
|
318
|
+
text: JSON.stringify({
|
|
319
|
+
branchLabelMapping,
|
|
320
|
+
}),
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
}),
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
}
|
|
@@ -17,7 +17,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
|
|
|
17
17
|
reviewers: string[];
|
|
18
18
|
sourcePRLabels: (string[] | undefined) & (string[] | never[]);
|
|
19
19
|
targetBranches: (string[] | undefined) & (string[] | never[]);
|
|
20
|
-
targetPRLabels: string[];
|
|
20
|
+
targetPRLabels: (string[] | undefined) & (string[] | never[]);
|
|
21
21
|
cherrypickRef: boolean;
|
|
22
22
|
fork: boolean;
|
|
23
23
|
noVerify: boolean;
|
|
@@ -40,7 +40,6 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
|
|
|
40
40
|
resetAuthor: boolean;
|
|
41
41
|
sha: string | undefined;
|
|
42
42
|
sourceBranch: string;
|
|
43
|
-
upstream: string | undefined;
|
|
44
43
|
verbose: boolean;
|
|
45
44
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
46
45
|
files: string[];
|
|
@@ -56,6 +55,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
|
|
|
56
55
|
}) => boolean | Promise<boolean>) | undefined;
|
|
57
56
|
multiple?: boolean | undefined;
|
|
58
57
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
58
|
+
upstream?: string | undefined;
|
|
59
59
|
branches?: TargetBranchChoiceOrString[] | undefined;
|
|
60
60
|
labels?: string[] | undefined;
|
|
61
61
|
historicalBranchLabelMappings: {
|
|
@@ -63,7 +63,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
|
|
|
63
63
|
committedDate: string;
|
|
64
64
|
}[];
|
|
65
65
|
};
|
|
66
|
-
export declare function getRequiredOptions({ accessToken, username,
|
|
66
|
+
export declare function getRequiredOptions({ accessToken, username, repoName, repoOwner, }: ConfigFileOptions): {
|
|
67
67
|
accessToken: string;
|
|
68
68
|
username: string;
|
|
69
69
|
repoOwner: string;
|