backport 6.1.1 → 6.1.5
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 +83 -70
- package/dist/entrypoint.module.d.ts +4 -1
- package/dist/entrypoint.module.js +10 -4
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +5 -1
- package/dist/options/ConfigOptions.d.ts +3 -0
- package/dist/options/cliArgs.d.ts +5 -1
- package/dist/options/cliArgs.js +24 -2
- package/dist/options/cliArgs.test.js +0 -7
- package/dist/options/config/config.d.ts +7 -1
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/config.test.js +1 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +4 -8
- package/dist/options/config/readConfigFile.d.ts +4 -1
- package/dist/options/options.d.ts +10 -1
- package/dist/options/options.js +10 -2
- package/dist/options/options.test.js +113 -123
- package/dist/runSequentially.test.js +8 -5
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/env.d.ts +2 -3
- package/dist/services/env.js +9 -10
- package/dist/services/env.test.js +0 -6
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createPullRequest.js +1 -1
- package/dist/services/github/v3/createPullRequest.test.js +3 -3
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +50 -27
- package/dist/services/github/v3/createStatusComment.test.js +155 -73
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
- package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchProjectConfig.js +3 -3
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/logger.d.ts +0 -1
- package/dist/services/logger.js +3 -3
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
- package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
- package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
- package/dist/test/inquirer.private.test.js +4 -15
- package/dist/test/integration/integration.private.test.js +2 -2
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/todo-delete.d.ts +1 -0
- package/dist/todo-delete.js +17 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +68 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/maybeSetupRepo.js +0 -6
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -0
- package/package.json +3 -3
- package/yarn.lock +462 -284
|
@@ -5,15 +5,19 @@ export declare const defaultConfigOptions: {
|
|
|
5
5
|
autoAssign: boolean;
|
|
6
6
|
autoMerge: boolean;
|
|
7
7
|
autoMergeMethod: string;
|
|
8
|
+
backportBinary: string;
|
|
8
9
|
cherrypickRef: boolean;
|
|
9
10
|
ci: boolean;
|
|
10
11
|
commitPaths: string[];
|
|
12
|
+
dateSince: null;
|
|
13
|
+
dateUntil: null;
|
|
11
14
|
details: boolean;
|
|
12
15
|
fork: boolean;
|
|
13
16
|
maxNumber: number;
|
|
14
17
|
multipleBranches: boolean;
|
|
15
18
|
multipleCommits: boolean;
|
|
16
19
|
noVerify: boolean;
|
|
20
|
+
publishStatusComment: boolean;
|
|
17
21
|
resetAuthor: boolean;
|
|
18
22
|
reviewers: string[];
|
|
19
23
|
sourcePRLabels: string[];
|
|
@@ -27,14 +31,15 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
27
31
|
repoName: string;
|
|
28
32
|
repoOwner: string;
|
|
29
33
|
fork: boolean;
|
|
34
|
+
dir?: string | undefined;
|
|
30
35
|
verbose: boolean;
|
|
36
|
+
ci: boolean;
|
|
31
37
|
assignees: string[];
|
|
32
38
|
author: string | null;
|
|
33
39
|
autoAssign: boolean;
|
|
34
40
|
autoMerge: boolean;
|
|
35
41
|
autoMergeMethod: string;
|
|
36
42
|
cherrypickRef: boolean;
|
|
37
|
-
ci: boolean;
|
|
38
43
|
commitPaths: string[];
|
|
39
44
|
details: boolean;
|
|
40
45
|
editor?: string | undefined;
|
|
@@ -48,6 +53,7 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
48
53
|
prDescription?: string | undefined;
|
|
49
54
|
prFilter?: string | undefined;
|
|
50
55
|
prTitle?: string | undefined;
|
|
56
|
+
publishStatusComment: boolean;
|
|
51
57
|
pullNumber?: number | undefined;
|
|
52
58
|
resetAuthor: boolean;
|
|
53
59
|
reviewers: string[];
|
|
@@ -59,6 +65,8 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
59
65
|
targetBranches: string[];
|
|
60
66
|
targetPRLabels: string[];
|
|
61
67
|
mainline?: number | undefined;
|
|
68
|
+
dateSince: string | null;
|
|
69
|
+
dateUntil: string | null;
|
|
62
70
|
historicalBranchLabelMappings: {
|
|
63
71
|
branchLabelMapping: Record<string, string>;
|
|
64
72
|
committedDate: string;
|
|
@@ -75,6 +83,7 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
|
|
|
75
83
|
};
|
|
76
84
|
targetBranch: string;
|
|
77
85
|
}) => boolean | Promise<boolean>) | undefined;
|
|
86
|
+
backportBinary: string;
|
|
78
87
|
multiple?: boolean | undefined;
|
|
79
88
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
80
89
|
upstream?: string | undefined;
|
package/dist/options/options.js
CHANGED
|
@@ -15,15 +15,19 @@ exports.defaultConfigOptions = {
|
|
|
15
15
|
autoAssign: false,
|
|
16
16
|
autoMerge: false,
|
|
17
17
|
autoMergeMethod: 'merge',
|
|
18
|
+
backportBinary: 'backport',
|
|
18
19
|
cherrypickRef: true,
|
|
19
20
|
ci: false,
|
|
20
21
|
commitPaths: [],
|
|
22
|
+
dateSince: null,
|
|
23
|
+
dateUntil: null,
|
|
21
24
|
details: false,
|
|
22
25
|
fork: true,
|
|
23
26
|
maxNumber: 10,
|
|
24
27
|
multipleBranches: true,
|
|
25
28
|
multipleCommits: false,
|
|
26
29
|
noVerify: true,
|
|
30
|
+
publishStatusComment: true,
|
|
27
31
|
resetAuthor: false,
|
|
28
32
|
reviewers: [],
|
|
29
33
|
sourcePRLabels: [],
|
|
@@ -33,8 +37,12 @@ exports.defaultConfigOptions = {
|
|
|
33
37
|
verbose: false,
|
|
34
38
|
};
|
|
35
39
|
async function getOptions(argv, optionsFromModule) {
|
|
36
|
-
const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)(optionsFromModule);
|
|
37
40
|
const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
41
|
+
const ci = optionsFromCliArgs.ci ?? optionsFromModule?.ci ?? exports.defaultConfigOptions.ci;
|
|
42
|
+
const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)({
|
|
43
|
+
optionsFromModule,
|
|
44
|
+
ci,
|
|
45
|
+
});
|
|
38
46
|
// combined options from cli and config files
|
|
39
47
|
const combined = getCombinedOptions({
|
|
40
48
|
optionsFromConfigFiles,
|
|
@@ -84,7 +92,7 @@ function requireAccessToken(combinedOptions) {
|
|
|
84
92
|
// accessToken must be supplied in config or via cli args
|
|
85
93
|
if (!combinedOptions.accessToken) {
|
|
86
94
|
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
87
|
-
throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
|
|
95
|
+
throw new HandledError_1.HandledError(`Please update your config file: "${globalConfigPath}".\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
|
|
88
96
|
}
|
|
89
97
|
return combinedOptions.accessToken;
|
|
90
98
|
}
|
|
@@ -28,45 +28,6 @@ const mockConfigFiles_1 = require("../test/mockConfigFiles");
|
|
|
28
28
|
const nockHelpers_1 = require("../test/nockHelpers");
|
|
29
29
|
const options_1 = require("./options");
|
|
30
30
|
jest.unmock('../services/fs-promisified');
|
|
31
|
-
function mockGithubConfigOptions({ viewerLogin = 'sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
|
|
32
|
-
return (0, nockHelpers_1.mockGqlRequest)({
|
|
33
|
-
name: 'GithubConfigOptions',
|
|
34
|
-
statusCode: 200,
|
|
35
|
-
body: {
|
|
36
|
-
data: {
|
|
37
|
-
viewer: {
|
|
38
|
-
login: viewerLogin,
|
|
39
|
-
},
|
|
40
|
-
repository: {
|
|
41
|
-
isFork: false,
|
|
42
|
-
parent: null,
|
|
43
|
-
ref: refName ? { name: refName } : null,
|
|
44
|
-
defaultBranchRef: {
|
|
45
|
-
name: defaultBranchRef,
|
|
46
|
-
target: {
|
|
47
|
-
history: {
|
|
48
|
-
edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
|
|
49
|
-
return {
|
|
50
|
-
remoteConfig: {
|
|
51
|
-
committedDate,
|
|
52
|
-
file: {
|
|
53
|
-
object: {
|
|
54
|
-
text: JSON.stringify({
|
|
55
|
-
branchLabelMapping,
|
|
56
|
-
}),
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
31
|
const defaultConfigs = {
|
|
71
32
|
projectConfig: {
|
|
72
33
|
// use localhost to avoid CORS issues with nock
|
|
@@ -96,79 +57,46 @@ describe('getOptions', () => {
|
|
|
96
57
|
});
|
|
97
58
|
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
98
59
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
99
|
-
"Please update your config file: /Users/sqren/.backport/config.json.
|
|
60
|
+
"Please update your config file: \\"/Users/sqren/.backport/config.json\\".
|
|
100
61
|
It must contain a valid \\"accessToken\\".
|
|
101
62
|
|
|
102
63
|
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
103
64
|
`);
|
|
104
65
|
});
|
|
105
66
|
it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
branchLabelMapping: undefined,
|
|
111
|
-
},
|
|
112
|
-
globalConfig: { accessToken: 'abc' },
|
|
67
|
+
mockProjectConfig({
|
|
68
|
+
targetBranches: undefined,
|
|
69
|
+
targetBranchChoices: undefined,
|
|
70
|
+
branchLabelMapping: undefined,
|
|
113
71
|
});
|
|
114
72
|
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
115
73
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
116
|
-
"Please specify a target branch: \\"--branch 6.1\\".
|
|
74
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
117
75
|
|
|
118
|
-
|
|
76
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
119
77
|
`);
|
|
120
78
|
});
|
|
121
79
|
it('when repoName is missing', async () => {
|
|
122
|
-
(
|
|
123
|
-
projectConfig: {
|
|
124
|
-
...defaultConfigs.projectConfig,
|
|
125
|
-
repoName: '',
|
|
126
|
-
},
|
|
127
|
-
globalConfig: { accessToken: 'abc' },
|
|
128
|
-
});
|
|
80
|
+
mockProjectConfig({ repoName: '' });
|
|
129
81
|
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
130
82
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
131
|
-
"Please specify a repo name: \\"--repo-name kibana\\".
|
|
83
|
+
"Please specify a repo name: \\"--repo-name kibana\\".
|
|
132
84
|
|
|
133
85
|
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
134
86
|
`);
|
|
135
87
|
});
|
|
136
88
|
it('when repoOwner is missing', async () => {
|
|
137
|
-
(
|
|
138
|
-
projectConfig: {
|
|
139
|
-
...defaultConfigs.projectConfig,
|
|
140
|
-
repoOwner: '',
|
|
141
|
-
},
|
|
142
|
-
globalConfig: { accessToken: 'abc' },
|
|
143
|
-
});
|
|
89
|
+
mockProjectConfig({ repoOwner: '' });
|
|
144
90
|
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
145
91
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
146
|
-
"Please specify a repo owner: \\"--repo-owner elastic\\".
|
|
92
|
+
"Please specify a repo owner: \\"--repo-owner elastic\\".
|
|
147
93
|
|
|
148
94
|
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
149
95
|
`);
|
|
150
96
|
});
|
|
151
97
|
});
|
|
152
|
-
describe('sourceBranch', () => {
|
|
153
|
-
beforeEach(() => {
|
|
154
|
-
mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
|
|
155
|
-
});
|
|
156
|
-
it('uses the `defaultBranchRef` as default', async () => {
|
|
157
|
-
const options = await (0, options_1.getOptions)([]);
|
|
158
|
-
expect(options.sourceBranch).toBe('some-default-branch');
|
|
159
|
-
});
|
|
160
|
-
it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
|
|
161
|
-
const options = await (0, options_1.getOptions)([
|
|
162
|
-
'--source-branch',
|
|
163
|
-
'cli-source-branch',
|
|
164
|
-
]);
|
|
165
|
-
expect(options.sourceBranch).toBe('cli-source-branch');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
98
|
it('should ensure that "backport" branch does not exist', async () => {
|
|
169
|
-
mockGithubConfigOptions({
|
|
170
|
-
refName: 'backport',
|
|
171
|
-
});
|
|
99
|
+
mockGithubConfigOptions({ refName: 'backport' });
|
|
172
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');
|
|
173
101
|
});
|
|
174
102
|
it('should merge config options and module options', async () => {
|
|
@@ -184,6 +112,7 @@ describe('getOptions', () => {
|
|
|
184
112
|
});
|
|
185
113
|
it('should return options', async () => {
|
|
186
114
|
mockGithubConfigOptions({
|
|
115
|
+
viewerLogin: 'john.diller',
|
|
187
116
|
defaultBranchRef: 'default-branch-from-github',
|
|
188
117
|
historicalMappings: [
|
|
189
118
|
{
|
|
@@ -197,15 +126,18 @@ describe('getOptions', () => {
|
|
|
197
126
|
accessToken: 'abc',
|
|
198
127
|
assignees: [],
|
|
199
128
|
autoAssign: false,
|
|
129
|
+
authenticatedUsername: 'john.diller',
|
|
200
130
|
autoMerge: false,
|
|
201
131
|
autoMergeMethod: 'merge',
|
|
202
|
-
|
|
132
|
+
backportBinary: 'backport',
|
|
203
133
|
branchLabelMapping: {
|
|
204
134
|
foo: 'bar',
|
|
205
135
|
},
|
|
206
136
|
cherrypickRef: true,
|
|
207
137
|
ci: false,
|
|
208
138
|
commitPaths: [],
|
|
139
|
+
dateSince: null,
|
|
140
|
+
dateUntil: null,
|
|
209
141
|
details: false,
|
|
210
142
|
editor: 'code',
|
|
211
143
|
fork: true,
|
|
@@ -216,7 +148,6 @@ describe('getOptions', () => {
|
|
|
216
148
|
committedDate: '2022-01-02T20:52:45.173Z',
|
|
217
149
|
},
|
|
218
150
|
],
|
|
219
|
-
mainline: 1,
|
|
220
151
|
maxNumber: 10,
|
|
221
152
|
multipleBranches: true,
|
|
222
153
|
multipleCommits: false,
|
|
@@ -230,13 +161,29 @@ describe('getOptions', () => {
|
|
|
230
161
|
targetBranchChoices: ['7.9', '8.0'],
|
|
231
162
|
targetBranches: [],
|
|
232
163
|
targetPRLabels: [],
|
|
233
|
-
author: '
|
|
164
|
+
author: 'john.diller',
|
|
234
165
|
verbose: false,
|
|
235
166
|
});
|
|
236
167
|
});
|
|
168
|
+
describe('sourceBranch', () => {
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
|
|
171
|
+
});
|
|
172
|
+
it('uses the `defaultBranchRef` as default', async () => {
|
|
173
|
+
const options = await (0, options_1.getOptions)([]);
|
|
174
|
+
expect(options.sourceBranch).toBe('some-default-branch');
|
|
175
|
+
});
|
|
176
|
+
it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
|
|
177
|
+
const options = await (0, options_1.getOptions)([
|
|
178
|
+
'--source-branch',
|
|
179
|
+
'cli-source-branch',
|
|
180
|
+
]);
|
|
181
|
+
expect(options.sourceBranch).toBe('cli-source-branch');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
237
184
|
describe('fork', () => {
|
|
238
185
|
beforeEach(() => {
|
|
239
|
-
mockGithubConfigOptions({
|
|
186
|
+
mockGithubConfigOptions({});
|
|
240
187
|
});
|
|
241
188
|
it('is enabled by default', async () => {
|
|
242
189
|
const { fork } = await (0, options_1.getOptions)([]);
|
|
@@ -247,37 +194,42 @@ describe('getOptions', () => {
|
|
|
247
194
|
expect(fork).toBe(false);
|
|
248
195
|
});
|
|
249
196
|
it('can be disabled via config file', async () => {
|
|
250
|
-
(
|
|
251
|
-
globalConfig: { accessToken: 'abc' },
|
|
252
|
-
projectConfig: {
|
|
253
|
-
...defaultConfigs.projectConfig,
|
|
254
|
-
fork: false,
|
|
255
|
-
},
|
|
256
|
-
});
|
|
197
|
+
mockProjectConfig({ fork: false });
|
|
257
198
|
const { fork } = await (0, options_1.getOptions)([]);
|
|
258
199
|
expect(fork).toBe(false);
|
|
259
200
|
});
|
|
260
201
|
});
|
|
261
202
|
describe('reviewers', () => {
|
|
262
203
|
beforeEach(() => {
|
|
263
|
-
mockGithubConfigOptions({
|
|
204
|
+
mockGithubConfigOptions({});
|
|
264
205
|
});
|
|
265
206
|
it('can be set via `--reviewer` flag', async () => {
|
|
266
207
|
const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter']);
|
|
267
208
|
expect(reviewers).toEqual(['peter']);
|
|
268
209
|
});
|
|
269
210
|
it('can be set via config file', async () => {
|
|
270
|
-
(
|
|
271
|
-
globalConfig: { accessToken: 'abc' },
|
|
272
|
-
projectConfig: {
|
|
273
|
-
...defaultConfigs.projectConfig,
|
|
274
|
-
reviewers: ['john'],
|
|
275
|
-
},
|
|
276
|
-
});
|
|
211
|
+
mockProjectConfig({ reviewers: ['john'] });
|
|
277
212
|
const { reviewers } = await (0, options_1.getOptions)([]);
|
|
278
213
|
expect(reviewers).toEqual(['john']);
|
|
279
214
|
});
|
|
280
215
|
});
|
|
216
|
+
describe('mainline', () => {
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
mockGithubConfigOptions({});
|
|
219
|
+
});
|
|
220
|
+
it('is not enabled by default', async () => {
|
|
221
|
+
const { mainline } = await (0, options_1.getOptions)([]);
|
|
222
|
+
expect(mainline).toBe(undefined);
|
|
223
|
+
});
|
|
224
|
+
it('can be set via `--mainline` flag', async () => {
|
|
225
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline']);
|
|
226
|
+
expect(mainline).toBe(1);
|
|
227
|
+
});
|
|
228
|
+
it('accepts numeric values', async () => {
|
|
229
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline', '2']);
|
|
230
|
+
expect(mainline).toBe(2);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
281
233
|
describe('author', () => {
|
|
282
234
|
beforeEach(() => {
|
|
283
235
|
mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
|
|
@@ -295,24 +247,12 @@ describe('getOptions', () => {
|
|
|
295
247
|
expect(author).toBe(null);
|
|
296
248
|
});
|
|
297
249
|
it('can be reset via config file (similar to `--all` flag)', async () => {
|
|
298
|
-
(
|
|
299
|
-
globalConfig: { accessToken: 'abc' },
|
|
300
|
-
projectConfig: {
|
|
301
|
-
...defaultConfigs.projectConfig,
|
|
302
|
-
author: null,
|
|
303
|
-
},
|
|
304
|
-
});
|
|
250
|
+
mockProjectConfig({ author: null });
|
|
305
251
|
const { author } = await (0, options_1.getOptions)([]);
|
|
306
252
|
expect(author).toBe(null);
|
|
307
253
|
});
|
|
308
254
|
it('can be overridden via config file', async () => {
|
|
309
|
-
(
|
|
310
|
-
globalConfig: { accessToken: 'abc' },
|
|
311
|
-
projectConfig: {
|
|
312
|
-
...defaultConfigs.projectConfig,
|
|
313
|
-
author: 'jane.doe',
|
|
314
|
-
},
|
|
315
|
-
});
|
|
255
|
+
mockProjectConfig({ author: 'jane.doe' });
|
|
316
256
|
const { author } = await (0, options_1.getOptions)([]);
|
|
317
257
|
expect(author).toBe('jane.doe');
|
|
318
258
|
});
|
|
@@ -330,16 +270,66 @@ describe('getOptions', () => {
|
|
|
330
270
|
expect(cherrypickRef).toBe(false);
|
|
331
271
|
});
|
|
332
272
|
it('should be settable via config file', async () => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
273
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
274
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
336
275
|
expect(cherrypickRef).toBe(false);
|
|
337
276
|
});
|
|
338
277
|
it('cli args overwrites config', async () => {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
});
|
|
278
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
279
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref']);
|
|
342
280
|
expect(cherrypickRef).toBe(true);
|
|
343
281
|
});
|
|
344
282
|
});
|
|
345
283
|
});
|
|
284
|
+
function mockProjectConfig(projectConfig) {
|
|
285
|
+
return (0, mockConfigFiles_1.mockConfigFiles)({
|
|
286
|
+
globalConfig: { accessToken: 'abc' },
|
|
287
|
+
projectConfig: {
|
|
288
|
+
// use localhost to avoid CORS issues with nock
|
|
289
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
290
|
+
repoOwner: 'elastic',
|
|
291
|
+
repoName: 'kibana',
|
|
292
|
+
targetBranchChoices: ['7.9', '8.0'],
|
|
293
|
+
...projectConfig,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
|
|
298
|
+
return (0, nockHelpers_1.mockGqlRequest)({
|
|
299
|
+
name: 'GithubConfigOptions',
|
|
300
|
+
statusCode: 200,
|
|
301
|
+
body: {
|
|
302
|
+
data: {
|
|
303
|
+
viewer: {
|
|
304
|
+
login: viewerLogin,
|
|
305
|
+
},
|
|
306
|
+
repository: {
|
|
307
|
+
isFork: false,
|
|
308
|
+
parent: null,
|
|
309
|
+
ref: refName ? { name: refName } : null,
|
|
310
|
+
defaultBranchRef: {
|
|
311
|
+
name: defaultBranchRef,
|
|
312
|
+
target: {
|
|
313
|
+
history: {
|
|
314
|
+
edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
|
|
315
|
+
return {
|
|
316
|
+
remoteConfig: {
|
|
317
|
+
committedDate,
|
|
318
|
+
file: {
|
|
319
|
+
object: {
|
|
320
|
+
text: JSON.stringify({
|
|
321
|
+
branchLabelMapping,
|
|
322
|
+
}),
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
}),
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
}
|
|
@@ -56,24 +56,27 @@ describe('runSequentially', () => {
|
|
|
56
56
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
57
57
|
const options = {
|
|
58
58
|
accessToken: 'myAccessToken',
|
|
59
|
-
authenticatedUsername: 'sqren_authenticated',
|
|
60
59
|
assignees: [],
|
|
60
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
61
|
+
author: 'sqren',
|
|
61
62
|
autoAssign: false,
|
|
62
63
|
autoFixConflicts: undefined,
|
|
63
64
|
autoMerge: false,
|
|
64
65
|
autoMergeMethod: 'merge',
|
|
66
|
+
backportBinary: 'node scripts/backport',
|
|
65
67
|
branchLabelMapping: undefined,
|
|
66
|
-
historicalBranchLabelMappings: [],
|
|
67
68
|
cherrypickRef: true,
|
|
68
69
|
ci: false,
|
|
69
70
|
commitPaths: [],
|
|
71
|
+
dateSince: null,
|
|
72
|
+
dateUntil: null,
|
|
70
73
|
details: false,
|
|
71
74
|
editor: 'code',
|
|
72
|
-
skipRemoteConfig: undefined,
|
|
73
75
|
fork: true,
|
|
74
76
|
gitHostname: 'github.com',
|
|
75
77
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
76
78
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
79
|
+
historicalBranchLabelMappings: [],
|
|
77
80
|
mainline: undefined,
|
|
78
81
|
maxNumber: 10,
|
|
79
82
|
multipleBranches: false,
|
|
@@ -88,6 +91,7 @@ describe('runSequentially', () => {
|
|
|
88
91
|
resetAuthor: false,
|
|
89
92
|
reviewers: [],
|
|
90
93
|
sha: undefined,
|
|
94
|
+
skipRemoteConfig: undefined,
|
|
91
95
|
sourceBranch: 'my-source-branch-from-options',
|
|
92
96
|
sourcePRLabels: [],
|
|
93
97
|
targetBranches: [],
|
|
@@ -99,7 +103,6 @@ describe('runSequentially', () => {
|
|
|
99
103
|
{ name: '5.4' },
|
|
100
104
|
],
|
|
101
105
|
targetPRLabels: [],
|
|
102
|
-
author: 'sqren',
|
|
103
106
|
verbose: false,
|
|
104
107
|
};
|
|
105
108
|
rpcExecMock = jest
|
|
@@ -145,7 +148,7 @@ describe('runSequentially', () => {
|
|
|
145
148
|
"base": "7.x",
|
|
146
149
|
"body": "# Backport
|
|
147
150
|
|
|
148
|
-
This is an automatic backport to 7.x of:
|
|
151
|
+
This is an automatic backport to \`7.x\` of:
|
|
149
152
|
- #55
|
|
150
153
|
|
|
151
154
|
### Questions ?
|
package/dist/services/env.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
+
export declare function getBackportDirPath(): string;
|
|
2
3
|
export declare function getLogfilePath(): string;
|
|
3
4
|
export declare function getGlobalConfigPath(): string;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function getRepoOwnerPath({ repoOwner }: ValidConfigOptions): string;
|
|
6
|
-
export declare function getRepoPath({ repoOwner, repoName }: ValidConfigOptions): string;
|
|
5
|
+
export declare function getRepoPath({ repoOwner, repoName, dir }: ValidConfigOptions): string;
|
package/dist/services/env.js
CHANGED
|
@@ -3,9 +3,13 @@ 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.getRepoPath = exports.
|
|
6
|
+
exports.getRepoPath = exports.getGlobalConfigPath = exports.getLogfilePath = exports.getBackportDirPath = void 0;
|
|
7
7
|
const os_1 = require("os");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function getBackportDirPath() {
|
|
10
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport');
|
|
11
|
+
}
|
|
12
|
+
exports.getBackportDirPath = getBackportDirPath;
|
|
9
13
|
function getLogfilePath() {
|
|
10
14
|
return path_1.default.join((0, os_1.homedir)(), '.backport', 'backport.log');
|
|
11
15
|
}
|
|
@@ -14,15 +18,10 @@ function getGlobalConfigPath() {
|
|
|
14
18
|
return path_1.default.join((0, os_1.homedir)(), '.backport', 'config.json');
|
|
15
19
|
}
|
|
16
20
|
exports.getGlobalConfigPath = getGlobalConfigPath;
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function getRepoOwnerPath({ repoOwner }) {
|
|
22
|
-
return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner);
|
|
23
|
-
}
|
|
24
|
-
exports.getRepoOwnerPath = getRepoOwnerPath;
|
|
25
|
-
function getRepoPath({ repoOwner, repoName }) {
|
|
21
|
+
function getRepoPath({ repoOwner, repoName, dir }) {
|
|
22
|
+
if (dir) {
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
26
25
|
return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner, repoName);
|
|
27
26
|
}
|
|
28
27
|
exports.getRepoPath = getRepoPath;
|
|
@@ -12,12 +12,6 @@ describe('env', () => {
|
|
|
12
12
|
test('getGlobalConfigPath', () => {
|
|
13
13
|
expect((0, env_1.getGlobalConfigPath)()).toBe('/myHomeDir/.backport/config.json');
|
|
14
14
|
});
|
|
15
|
-
test('getReposPath', () => {
|
|
16
|
-
expect((0, env_1.getReposPath)()).toBe('/myHomeDir/.backport/repositories');
|
|
17
|
-
});
|
|
18
|
-
test('getRepoOwnerPath', () => {
|
|
19
|
-
expect((0, env_1.getRepoOwnerPath)({ repoOwner: 'elastic' })).toBe('/myHomeDir/.backport/repositories/elastic');
|
|
20
|
-
});
|
|
21
15
|
test('getRepoPath', () => {
|
|
22
16
|
expect((0, env_1.getRepoPath)({
|
|
23
17
|
repoOwner: 'elastic',
|
package/dist/services/git.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
+
import { ExpectedTargetPullRequest } from './sourceCommit/getExpectedTargetPullRequests';
|
|
2
3
|
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
3
4
|
export declare function repoExists(options: ValidConfigOptions): Promise<boolean>;
|
|
4
5
|
export declare function deleteRepo(options: ValidConfigOptions): Promise<string[]>;
|
|
@@ -15,7 +16,7 @@ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitS
|
|
|
15
16
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
16
17
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
17
18
|
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
18
|
-
export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha']): Promise<{
|
|
19
|
+
export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha'], mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
|
|
19
20
|
conflictingFiles: {
|
|
20
21
|
absolute: string;
|
|
21
22
|
relative: string;
|
package/dist/services/git.js
CHANGED
|
@@ -49,7 +49,7 @@ function cloneRepo(options, callback) {
|
|
|
49
49
|
resolve();
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
const execProcess = (0, child_process_promisified_1.execAsCallback)(`git clone ${getRemoteUrl(options, options.repoOwner)}
|
|
52
|
+
const execProcess = (0, child_process_promisified_1.execAsCallback)(`git clone ${getRemoteUrl(options, options.repoOwner)} ${(0, env_1.getRepoPath)(options)} --progress`, { maxBuffer: 100 * 1024 * 1024 }, cb);
|
|
53
53
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
54
54
|
if (execProcess.stderr) {
|
|
55
55
|
execProcess.stderr.on('data', (data) => {
|
|
@@ -158,7 +158,7 @@ async function fetchBranch(options, branch) {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
exports.fetchBranch = fetchBranch;
|
|
161
|
-
async function cherrypick(options, sha) {
|
|
161
|
+
async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
162
162
|
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
163
163
|
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
164
164
|
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
|
|
@@ -174,7 +174,9 @@ async function cherrypick(options, sha) {
|
|
|
174
174
|
// commit was already backported
|
|
175
175
|
if (e.message.includes('The previous cherry-pick is now empty')) {
|
|
176
176
|
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
177
|
-
throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty.
|
|
177
|
+
throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. ${mergedTargetPullRequest?.url
|
|
178
|
+
? `It looks like the commit was already backported in ${mergedTargetPullRequest.url}`
|
|
179
|
+
: 'Did you already backport this commit? '}`);
|
|
178
180
|
}
|
|
179
181
|
// git info missing
|
|
180
182
|
if (e.message.includes('Please tell me who you are')) {
|
|
@@ -66,7 +66,7 @@ function getPullRequestBody({ options, commits, targetBranch, }) {
|
|
|
66
66
|
.join('\n');
|
|
67
67
|
return `# Backport
|
|
68
68
|
|
|
69
|
-
This is an automatic backport to
|
|
69
|
+
This is an automatic backport to \`${targetBranch}\` of:
|
|
70
70
|
${commitMessages}
|
|
71
71
|
|
|
72
72
|
### Questions ?
|
|
@@ -16,7 +16,7 @@ describe('getPullRequestBody', () => {
|
|
|
16
16
|
})).toMatchInlineSnapshot(`
|
|
17
17
|
"# Backport
|
|
18
18
|
|
|
19
|
-
This is an automatic backport to 7.x of:
|
|
19
|
+
This is an automatic backport to \`7.x\` of:
|
|
20
20
|
- #55
|
|
21
21
|
|
|
22
22
|
### Questions ?
|
|
@@ -37,7 +37,7 @@ describe('getPullRequestBody', () => {
|
|
|
37
37
|
})).toMatchInlineSnapshot(`
|
|
38
38
|
"# Backport
|
|
39
39
|
|
|
40
|
-
This is an automatic backport to 7.x of:
|
|
40
|
+
This is an automatic backport to \`7.x\` of:
|
|
41
41
|
- My commit message (abcdefgh)
|
|
42
42
|
|
|
43
43
|
### Questions ?
|
|
@@ -63,7 +63,7 @@ describe('getPullRequestBody', () => {
|
|
|
63
63
|
})).toMatchInlineSnapshot(`
|
|
64
64
|
"# Backport
|
|
65
65
|
|
|
66
|
-
This is an automatic backport to 7.x of:
|
|
66
|
+
This is an automatic backport to \`7.x\` of:
|
|
67
67
|
- #55
|
|
68
68
|
- Another commit message (qwertyui)
|
|
69
69
|
|