backport 6.1.0 → 6.1.4
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 +45 -34
- package/dist/entrypoint.module.d.ts +2 -0
- package/dist/entrypoint.module.js +5 -1
- package/dist/entrypoint.module.private.test.js +16 -12
- package/dist/main.js +1 -1
- package/dist/options/ConfigOptions.d.ts +1 -0
- package/dist/options/cliArgs.d.ts +5 -3
- package/dist/options/cliArgs.js +20 -6
- package/dist/options/cliArgs.test.js +0 -7
- package/dist/options/config/config.d.ts +1 -0
- package/dist/options/config/globalConfig.js +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -0
- package/dist/options/options.d.ts +8 -0
- package/dist/options/options.js +9 -4
- package/dist/options/options.test.js +150 -104
- package/dist/runSequentially.test.js +13 -6
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +4 -2
- package/dist/services/github/v3/createPullRequest.js +1 -1
- package/dist/services/github/v3/createPullRequest.test.js +38 -6
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +43 -25
- 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/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +37 -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 +14 -4
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +19 -6
- 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/utils/excludeUndefined.js +1 -1
- package/dist/utils/excludeUndefined.test.js +3 -3
- package/package.json +3 -3
- package/yarn.lock +462 -284
|
@@ -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,10 +161,75 @@ 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
|
+
});
|
|
184
|
+
describe('fork', () => {
|
|
185
|
+
beforeEach(() => {
|
|
186
|
+
mockGithubConfigOptions({});
|
|
187
|
+
});
|
|
188
|
+
it('is enabled by default', async () => {
|
|
189
|
+
const { fork } = await (0, options_1.getOptions)([]);
|
|
190
|
+
expect(fork).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
it('can be disabled via `--no-fork` flag', async () => {
|
|
193
|
+
const { fork } = await (0, options_1.getOptions)(['--no-fork']);
|
|
194
|
+
expect(fork).toBe(false);
|
|
195
|
+
});
|
|
196
|
+
it('can be disabled via config file', async () => {
|
|
197
|
+
mockProjectConfig({ fork: false });
|
|
198
|
+
const { fork } = await (0, options_1.getOptions)([]);
|
|
199
|
+
expect(fork).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe('reviewers', () => {
|
|
203
|
+
beforeEach(() => {
|
|
204
|
+
mockGithubConfigOptions({});
|
|
205
|
+
});
|
|
206
|
+
it('can be set via `--reviewer` flag', async () => {
|
|
207
|
+
const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter']);
|
|
208
|
+
expect(reviewers).toEqual(['peter']);
|
|
209
|
+
});
|
|
210
|
+
it('can be set via config file', async () => {
|
|
211
|
+
mockProjectConfig({ reviewers: ['john'] });
|
|
212
|
+
const { reviewers } = await (0, options_1.getOptions)([]);
|
|
213
|
+
expect(reviewers).toEqual(['john']);
|
|
214
|
+
});
|
|
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
|
+
});
|
|
237
233
|
describe('author', () => {
|
|
238
234
|
beforeEach(() => {
|
|
239
235
|
mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
|
|
@@ -242,21 +238,21 @@ describe('getOptions', () => {
|
|
|
242
238
|
const { author } = await (0, options_1.getOptions)([]);
|
|
243
239
|
expect(author).toBe('billy.bob');
|
|
244
240
|
});
|
|
245
|
-
it('can be overridden via
|
|
241
|
+
it('can be overridden via `--author` flag', async () => {
|
|
246
242
|
const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
|
|
247
243
|
expect(author).toBe('john.doe');
|
|
248
244
|
});
|
|
245
|
+
it('can be reset via `--all` flag', async () => {
|
|
246
|
+
const { author } = await (0, options_1.getOptions)(['--all']);
|
|
247
|
+
expect(author).toBe(null);
|
|
248
|
+
});
|
|
249
|
+
it('can be reset via config file (similar to `--all` flag)', async () => {
|
|
250
|
+
mockProjectConfig({ author: null });
|
|
251
|
+
const { author } = await (0, options_1.getOptions)([]);
|
|
252
|
+
expect(author).toBe(null);
|
|
253
|
+
});
|
|
249
254
|
it('can be overridden via config file', async () => {
|
|
250
|
-
(
|
|
251
|
-
globalConfig: { accessToken: 'abc' },
|
|
252
|
-
projectConfig: {
|
|
253
|
-
author: 'jane.doe',
|
|
254
|
-
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
255
|
-
targetBranchChoices: ['7.9', '8.0'],
|
|
256
|
-
repoName: 'foo',
|
|
257
|
-
repoOwner: 'bar',
|
|
258
|
-
},
|
|
259
|
-
});
|
|
255
|
+
mockProjectConfig({ author: 'jane.doe' });
|
|
260
256
|
const { author } = await (0, options_1.getOptions)([]);
|
|
261
257
|
expect(author).toBe('jane.doe');
|
|
262
258
|
});
|
|
@@ -274,16 +270,66 @@ describe('getOptions', () => {
|
|
|
274
270
|
expect(cherrypickRef).toBe(false);
|
|
275
271
|
});
|
|
276
272
|
it('should be settable via config file', async () => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
273
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
274
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
280
275
|
expect(cherrypickRef).toBe(false);
|
|
281
276
|
});
|
|
282
277
|
it('cli args overwrites config', async () => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
});
|
|
278
|
+
mockProjectConfig({ cherrypickRef: false });
|
|
279
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref']);
|
|
286
280
|
expect(cherrypickRef).toBe(true);
|
|
287
281
|
});
|
|
288
282
|
});
|
|
289
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
|
|
@@ -143,9 +146,13 @@ describe('runSequentially', () => {
|
|
|
143
146
|
Array [
|
|
144
147
|
Object {
|
|
145
148
|
"base": "7.x",
|
|
146
|
-
"body": "
|
|
149
|
+
"body": "# Backport
|
|
150
|
+
|
|
151
|
+
This is an automatic backport to \`7.x\` of:
|
|
152
|
+
- #55
|
|
147
153
|
|
|
148
|
-
|
|
154
|
+
### Questions ?
|
|
155
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
149
156
|
|
|
150
157
|
myPrDescription",
|
|
151
158
|
"head": "sqren_authenticated:backport/7.x/pr-55",
|
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
|
@@ -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 ?
|
|
@@ -14,9 +14,14 @@ describe('getPullRequestBody', () => {
|
|
|
14
14
|
],
|
|
15
15
|
targetBranch: '7.x',
|
|
16
16
|
})).toMatchInlineSnapshot(`
|
|
17
|
-
"
|
|
17
|
+
"# Backport
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
This is an automatic backport to \`7.x\` of:
|
|
20
|
+
- #55
|
|
21
|
+
|
|
22
|
+
### Questions ?
|
|
23
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
24
|
+
"
|
|
20
25
|
`);
|
|
21
26
|
});
|
|
22
27
|
it('when a single commit (non pull request) is backported', () => {
|
|
@@ -30,9 +35,14 @@ describe('getPullRequestBody', () => {
|
|
|
30
35
|
],
|
|
31
36
|
targetBranch: '7.x',
|
|
32
37
|
})).toMatchInlineSnapshot(`
|
|
33
|
-
"
|
|
38
|
+
"# Backport
|
|
39
|
+
|
|
40
|
+
This is an automatic backport to \`7.x\` of:
|
|
41
|
+
- My commit message (abcdefgh)
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
### Questions ?
|
|
44
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
45
|
+
"
|
|
36
46
|
`);
|
|
37
47
|
});
|
|
38
48
|
it('when multiple commits are backported', () => {
|
|
@@ -51,15 +61,37 @@ describe('getPullRequestBody', () => {
|
|
|
51
61
|
],
|
|
52
62
|
targetBranch: '7.x',
|
|
53
63
|
})).toMatchInlineSnapshot(`
|
|
54
|
-
"
|
|
64
|
+
"# Backport
|
|
65
|
+
|
|
66
|
+
This is an automatic backport to \`7.x\` of:
|
|
55
67
|
- #55
|
|
56
68
|
- Another commit message (qwertyui)
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
### Questions ?
|
|
71
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
72
|
+
"
|
|
59
73
|
`);
|
|
60
74
|
});
|
|
61
75
|
});
|
|
62
76
|
describe('getTitle', () => {
|
|
77
|
+
it('when the default title is used', () => {
|
|
78
|
+
expect((0, createPullRequest_1.getTitle)({
|
|
79
|
+
options: {},
|
|
80
|
+
commits: [
|
|
81
|
+
{
|
|
82
|
+
pullNumber: 55,
|
|
83
|
+
sha: 'abcdefghi',
|
|
84
|
+
originalMessage: 'My commit message',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
pullNumber: 56,
|
|
88
|
+
sha: 'jklmnopqr',
|
|
89
|
+
originalMessage: 'Another commit message',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
targetBranch: '7.x',
|
|
93
|
+
})).toEqual('[7.x] My commit message | Another commit message');
|
|
94
|
+
});
|
|
63
95
|
it('when a custom PR title is used', () => {
|
|
64
96
|
expect((0, createPullRequest_1.getTitle)({
|
|
65
97
|
options: {
|