backport 7.3.0 → 7.3.2-beta.2
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 +3 -1
- package/dist/backportRun.js +12 -1
- package/dist/options/ConfigOptions.d.ts +3 -3
- package/dist/options/cliArgs.d.ts +3 -1
- package/dist/options/cliArgs.js +16 -7
- package/dist/options/config/config.d.ts +3 -3
- package/dist/options/config/readConfigFile.d.ts +3 -3
- package/dist/options/options.d.ts +3 -3
- package/dist/options/options.js +3 -1
- package/dist/options/options.test.js +2 -1
- package/dist/runSequentially.d.ts +3 -1
- package/dist/runSequentially.js +2 -3
- package/dist/services/git.d.ts +9 -10
- package/dist/services/git.integration.test.js +26 -12
- package/dist/services/git.js +6 -29
- package/dist/services/git.test.js +44 -16
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -5
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
- package/dist/test/e2e/cli/cli.private.test.js +6 -2
- package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
- package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/module.mutation.test.js +369 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +26 -7
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +14 -11
- package/dist/ui/getGitConfigAuthor.d.ts +6 -0
- package/dist/ui/getGitConfigAuthor.js +15 -0
- package/dist/ui/setupRepo.d.ts +1 -2
- package/dist/ui/setupRepo.js +4 -36
- package/dist/ui/setupRepo.test.js +11 -63
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +6 -6
- package/yarn.lock +58 -78
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rest_1 = require("@octokit/rest");
|
|
4
|
+
const entrypoint_module_1 = require("../../../entrypoint.module");
|
|
5
|
+
const commitFormatters_1 = require("../../../services/github/commitFormatters");
|
|
6
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
7
|
+
const sandbox_1 = require("../../sandbox");
|
|
8
|
+
jest.unmock('find-up');
|
|
9
|
+
jest.unmock('del');
|
|
10
|
+
jest.unmock('make-dir');
|
|
11
|
+
jest.setTimeout(15000);
|
|
12
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
|
+
const octokit = new rest_1.Octokit({ auth: accessToken });
|
|
14
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
15
|
+
// repo
|
|
16
|
+
const REPO_OWNER = 'backport-org';
|
|
17
|
+
const REPO_NAME = 'integration-test';
|
|
18
|
+
const AUTHOR = 'sqren';
|
|
19
|
+
// commit 1
|
|
20
|
+
const COMMIT_SHA_1 = '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad';
|
|
21
|
+
const BRANCH_WITH_ONE_COMMIT = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}`;
|
|
22
|
+
// commit 2
|
|
23
|
+
const COMMIT_SHA_2 = '59d6ff1ca90a4ce210c0a4f0e159214875c19d60';
|
|
24
|
+
const BRANCH_WITH_TWO_COMMITS = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}_commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_2)}`;
|
|
25
|
+
describe('backport e2e', () => {
|
|
26
|
+
describe('when a single commit is backported', () => {
|
|
27
|
+
let res;
|
|
28
|
+
let pullRequestResponse;
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
await resetState(accessToken);
|
|
31
|
+
res = await (0, entrypoint_module_1.backportRun)({
|
|
32
|
+
dir: sandboxPath,
|
|
33
|
+
accessToken,
|
|
34
|
+
repoOwner: 'backport-org',
|
|
35
|
+
repoName: 'integration-test',
|
|
36
|
+
sha: COMMIT_SHA_1,
|
|
37
|
+
targetBranches: ['7.x'],
|
|
38
|
+
});
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
41
|
+
pullRequestResponse = await octokit.pulls.get({
|
|
42
|
+
owner: REPO_OWNER,
|
|
43
|
+
repo: REPO_NAME,
|
|
44
|
+
pull_number: pullRequestNumber,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it('returns the backport result', () => {
|
|
48
|
+
expect(res).toEqual({
|
|
49
|
+
commits: [
|
|
50
|
+
{
|
|
51
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
52
|
+
expectedTargetPullRequests: [],
|
|
53
|
+
sourceBranch: 'master',
|
|
54
|
+
sourceCommit: {
|
|
55
|
+
committedDate: '2020-08-15T10:37:41Z',
|
|
56
|
+
message: 'Add ❤️ emoji',
|
|
57
|
+
sha: COMMIT_SHA_1,
|
|
58
|
+
},
|
|
59
|
+
sourcePullRequest: undefined,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
results: [
|
|
63
|
+
{
|
|
64
|
+
didUpdate: false,
|
|
65
|
+
pullRequestNumber: expect.any(Number),
|
|
66
|
+
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
67
|
+
status: 'success',
|
|
68
|
+
targetBranch: '7.x',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
status: 'success',
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
it('pull request: status code', async () => {
|
|
75
|
+
expect(pullRequestResponse.status).toEqual(200);
|
|
76
|
+
});
|
|
77
|
+
it('pull request: title', async () => {
|
|
78
|
+
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
|
|
79
|
+
});
|
|
80
|
+
it('pull request: body', async () => {
|
|
81
|
+
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
82
|
+
"# Backport
|
|
83
|
+
|
|
84
|
+
This will backport the following commits from \`master\` to \`7.x\`:
|
|
85
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
86
|
+
|
|
87
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
88
|
+
|
|
89
|
+
### Questions ?
|
|
90
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
91
|
+
`);
|
|
92
|
+
});
|
|
93
|
+
it('pull request: head branch is in fork repo', async () => {
|
|
94
|
+
expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
|
|
95
|
+
});
|
|
96
|
+
it('pull request: base branch', async () => {
|
|
97
|
+
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
98
|
+
});
|
|
99
|
+
it('does not create any new branches in origin (backport-org/integration-test)', async () => {
|
|
100
|
+
const branches = await getBranchesOnGithub({
|
|
101
|
+
accessToken,
|
|
102
|
+
repoOwner: REPO_OWNER,
|
|
103
|
+
repoName: REPO_NAME,
|
|
104
|
+
});
|
|
105
|
+
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
106
|
+
});
|
|
107
|
+
it('creates a branch in the fork (sqren/integration-test)', async () => {
|
|
108
|
+
const branches = await getBranchesOnGithub({
|
|
109
|
+
accessToken,
|
|
110
|
+
repoOwner: AUTHOR,
|
|
111
|
+
repoName: REPO_NAME,
|
|
112
|
+
});
|
|
113
|
+
expect(branches.map((b) => b.name)).toEqual([
|
|
114
|
+
'7.x',
|
|
115
|
+
BRANCH_WITH_ONE_COMMIT,
|
|
116
|
+
'master',
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('when two commits are backported', () => {
|
|
121
|
+
let res;
|
|
122
|
+
let pullRequestResponse;
|
|
123
|
+
beforeAll(async () => {
|
|
124
|
+
await resetState(accessToken);
|
|
125
|
+
res = await (0, entrypoint_module_1.backportRun)({
|
|
126
|
+
dir: sandboxPath,
|
|
127
|
+
accessToken,
|
|
128
|
+
repoOwner: 'backport-org',
|
|
129
|
+
repoName: 'integration-test',
|
|
130
|
+
sha: [COMMIT_SHA_1, COMMIT_SHA_2],
|
|
131
|
+
targetBranches: ['7.x'],
|
|
132
|
+
});
|
|
133
|
+
// @ts-expect-error
|
|
134
|
+
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
135
|
+
pullRequestResponse = await octokit.pulls.get({
|
|
136
|
+
owner: REPO_OWNER,
|
|
137
|
+
repo: REPO_NAME,
|
|
138
|
+
pull_number: pullRequestNumber,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
it('returns the backport result containing both commits', () => {
|
|
142
|
+
expect(res).toEqual({
|
|
143
|
+
commits: [
|
|
144
|
+
{
|
|
145
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
146
|
+
expectedTargetPullRequests: [],
|
|
147
|
+
sourceBranch: 'master',
|
|
148
|
+
sourceCommit: {
|
|
149
|
+
committedDate: '2020-08-15T10:37:41Z',
|
|
150
|
+
message: 'Add ❤️ emoji',
|
|
151
|
+
sha: COMMIT_SHA_1,
|
|
152
|
+
},
|
|
153
|
+
sourcePullRequest: undefined,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
157
|
+
expectedTargetPullRequests: [],
|
|
158
|
+
sourceBranch: 'master',
|
|
159
|
+
sourceCommit: {
|
|
160
|
+
committedDate: '2020-08-15T10:44:04Z',
|
|
161
|
+
message: 'Add family emoji (#2)',
|
|
162
|
+
sha: COMMIT_SHA_2,
|
|
163
|
+
},
|
|
164
|
+
sourcePullRequest: undefined,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
results: [
|
|
168
|
+
{
|
|
169
|
+
didUpdate: false,
|
|
170
|
+
pullRequestNumber: expect.any(Number),
|
|
171
|
+
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
172
|
+
status: 'success',
|
|
173
|
+
targetBranch: '7.x',
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
status: 'success',
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
it('pull request: status code', async () => {
|
|
180
|
+
expect(pullRequestResponse.status).toEqual(200);
|
|
181
|
+
});
|
|
182
|
+
it('pull request: title', async () => {
|
|
183
|
+
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
|
|
184
|
+
});
|
|
185
|
+
it('pull request: body', async () => {
|
|
186
|
+
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
187
|
+
"# Backport
|
|
188
|
+
|
|
189
|
+
This will backport the following commits from \`master\` to \`7.x\`:
|
|
190
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
191
|
+
- Add family emoji (#2) (59d6ff1c)
|
|
192
|
+
|
|
193
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
194
|
+
|
|
195
|
+
### Questions ?
|
|
196
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
it('pull request: head branch contains both commits in name', async () => {
|
|
200
|
+
expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
|
|
201
|
+
});
|
|
202
|
+
it('pull request: base branch', async () => {
|
|
203
|
+
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
describe('when disabling fork mode', () => {
|
|
207
|
+
let res;
|
|
208
|
+
let pullRequestResponse;
|
|
209
|
+
beforeAll(async () => {
|
|
210
|
+
await resetState(accessToken);
|
|
211
|
+
res = await (0, entrypoint_module_1.backportRun)({
|
|
212
|
+
fork: false,
|
|
213
|
+
dir: sandboxPath,
|
|
214
|
+
accessToken,
|
|
215
|
+
repoOwner: 'backport-org',
|
|
216
|
+
repoName: 'integration-test',
|
|
217
|
+
sha: COMMIT_SHA_1,
|
|
218
|
+
targetBranches: ['7.x'],
|
|
219
|
+
});
|
|
220
|
+
// @ts-expect-error
|
|
221
|
+
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
222
|
+
pullRequestResponse = await octokit.pulls.get({
|
|
223
|
+
owner: REPO_OWNER,
|
|
224
|
+
repo: REPO_NAME,
|
|
225
|
+
pull_number: pullRequestNumber,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('pull request: title', async () => {
|
|
229
|
+
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
|
|
230
|
+
});
|
|
231
|
+
it('pull request: body', async () => {
|
|
232
|
+
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
233
|
+
"# Backport
|
|
234
|
+
|
|
235
|
+
This will backport the following commits from \`master\` to \`7.x\`:
|
|
236
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
237
|
+
|
|
238
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
239
|
+
|
|
240
|
+
### Questions ?
|
|
241
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
242
|
+
`);
|
|
243
|
+
});
|
|
244
|
+
it('pull request: head branch is in origin (non-fork) repo', async () => {
|
|
245
|
+
expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
|
|
246
|
+
});
|
|
247
|
+
it('pull request: base branch', async () => {
|
|
248
|
+
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
249
|
+
});
|
|
250
|
+
it('returns pull request', () => {
|
|
251
|
+
expect(res).toEqual({
|
|
252
|
+
commits: [
|
|
253
|
+
{
|
|
254
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
255
|
+
expectedTargetPullRequests: [],
|
|
256
|
+
sourceBranch: 'master',
|
|
257
|
+
sourceCommit: {
|
|
258
|
+
committedDate: '2020-08-15T10:37:41Z',
|
|
259
|
+
message: 'Add ❤️ emoji',
|
|
260
|
+
sha: COMMIT_SHA_1,
|
|
261
|
+
},
|
|
262
|
+
sourcePullRequest: undefined,
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
results: [
|
|
266
|
+
{
|
|
267
|
+
didUpdate: false,
|
|
268
|
+
pullRequestNumber: expect.any(Number),
|
|
269
|
+
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
270
|
+
status: 'success',
|
|
271
|
+
targetBranch: '7.x',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
status: 'success',
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
it('creates a new branch in origin (backport-org/integration-test)', async () => {
|
|
278
|
+
const branches = await getBranchesOnGithub({
|
|
279
|
+
accessToken,
|
|
280
|
+
repoOwner: REPO_OWNER,
|
|
281
|
+
repoName: REPO_NAME,
|
|
282
|
+
});
|
|
283
|
+
expect(branches.map((b) => b.name)).toEqual([
|
|
284
|
+
'7.x',
|
|
285
|
+
BRANCH_WITH_ONE_COMMIT,
|
|
286
|
+
'master',
|
|
287
|
+
]);
|
|
288
|
+
});
|
|
289
|
+
it('does not create branches in the fork (sqren/integration-test)', async () => {
|
|
290
|
+
const branches = await getBranchesOnGithub({
|
|
291
|
+
accessToken,
|
|
292
|
+
repoOwner: AUTHOR,
|
|
293
|
+
repoName: REPO_NAME,
|
|
294
|
+
});
|
|
295
|
+
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
|
|
300
|
+
// console.log(`fetch branches for ${repoOwner}`);
|
|
301
|
+
const octokit = new rest_1.Octokit({
|
|
302
|
+
auth: accessToken,
|
|
303
|
+
});
|
|
304
|
+
const res = await octokit.repos.listBranches({
|
|
305
|
+
owner: repoOwner,
|
|
306
|
+
repo: repoName,
|
|
307
|
+
});
|
|
308
|
+
return res.data;
|
|
309
|
+
}
|
|
310
|
+
async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
|
|
311
|
+
try {
|
|
312
|
+
const octokit = new rest_1.Octokit({
|
|
313
|
+
auth: accessToken,
|
|
314
|
+
});
|
|
315
|
+
// console.log({ accessToken });
|
|
316
|
+
const opts = {
|
|
317
|
+
owner: repoOwner,
|
|
318
|
+
repo: repoName,
|
|
319
|
+
ref: `heads/${branchName}`,
|
|
320
|
+
};
|
|
321
|
+
const res = await octokit.git.deleteRef(opts);
|
|
322
|
+
// console.log(`Deleted ${repoOwner}:heads/${branchName}`);
|
|
323
|
+
return res.data;
|
|
324
|
+
}
|
|
325
|
+
catch (e) {
|
|
326
|
+
// console.log(
|
|
327
|
+
// `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
|
|
328
|
+
// );
|
|
329
|
+
if (e.message === 'Reference does not exist') {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
throw e;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async function resetState(accessToken) {
|
|
336
|
+
const ownerBranches = await getBranchesOnGithub({
|
|
337
|
+
accessToken,
|
|
338
|
+
repoOwner: REPO_OWNER,
|
|
339
|
+
repoName: REPO_NAME,
|
|
340
|
+
});
|
|
341
|
+
// delete all branches except master and 7.x
|
|
342
|
+
await Promise.all(ownerBranches
|
|
343
|
+
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
344
|
+
.map((b) => {
|
|
345
|
+
return deleteBranchOnGithub({
|
|
346
|
+
accessToken,
|
|
347
|
+
repoOwner: REPO_OWNER,
|
|
348
|
+
repoName: REPO_NAME,
|
|
349
|
+
branchName: b.name,
|
|
350
|
+
});
|
|
351
|
+
}));
|
|
352
|
+
const forkBranches = await getBranchesOnGithub({
|
|
353
|
+
accessToken,
|
|
354
|
+
repoOwner: AUTHOR,
|
|
355
|
+
repoName: REPO_NAME,
|
|
356
|
+
});
|
|
357
|
+
// delete all branches except master and 7.x
|
|
358
|
+
await Promise.all(forkBranches
|
|
359
|
+
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
360
|
+
.map((b) => {
|
|
361
|
+
return deleteBranchOnGithub({
|
|
362
|
+
accessToken,
|
|
363
|
+
repoOwner: AUTHOR,
|
|
364
|
+
repoName: REPO_NAME,
|
|
365
|
+
branchName: b.name,
|
|
366
|
+
});
|
|
367
|
+
}));
|
|
368
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
369
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
2
|
import { Commit } from '../services/sourceCommit/parseSourceCommit';
|
|
3
|
-
|
|
3
|
+
import { GitConfigAuthor } from './getGitConfigAuthor';
|
|
4
|
+
export declare function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, gitConfigAuthor, }: {
|
|
4
5
|
options: ValidConfigOptions;
|
|
5
6
|
commits: Commit[];
|
|
6
7
|
targetBranch: string;
|
|
8
|
+
gitConfigAuthor?: GitConfigAuthor;
|
|
7
9
|
}): Promise<{
|
|
8
10
|
url: string;
|
|
9
11
|
number: number;
|
|
@@ -21,15 +21,12 @@ const prompts_1 = require("../services/prompts");
|
|
|
21
21
|
const sequentially_1 = require("../services/sequentially");
|
|
22
22
|
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
23
23
|
const ora_1 = require("./ora");
|
|
24
|
-
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
|
|
24
|
+
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, gitConfigAuthor, }) {
|
|
25
25
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
26
26
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
27
27
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
28
28
|
await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
|
|
29
|
-
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
30
|
-
if (options.resetAuthor) {
|
|
31
|
-
await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
|
|
32
|
-
}
|
|
29
|
+
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch, gitConfigAuthor));
|
|
33
30
|
if (options.dryRun) {
|
|
34
31
|
(0, ora_1.ora)(options.ci).succeed('Dry run complete');
|
|
35
32
|
return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
|
|
@@ -94,16 +91,26 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
94
91
|
.slice(0, 200);
|
|
95
92
|
return `backport/${targetBranch}/${refValues}`;
|
|
96
93
|
}
|
|
97
|
-
async function waitForCherrypick(options, commit, targetBranch) {
|
|
94
|
+
async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
|
|
98
95
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
99
96
|
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
100
97
|
const cherrypickSpinner = (0, ora_1.ora)(options.ci, spinnerText).start();
|
|
101
98
|
let conflictingFiles;
|
|
102
99
|
let unstagedFiles;
|
|
103
100
|
let needsResolving;
|
|
101
|
+
const commitAuthor = getCommitAuthor({
|
|
102
|
+
options,
|
|
103
|
+
gitConfigAuthor,
|
|
104
|
+
commit,
|
|
105
|
+
});
|
|
104
106
|
try {
|
|
105
107
|
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
106
|
-
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(
|
|
108
|
+
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)({
|
|
109
|
+
options,
|
|
110
|
+
sha: commit.sourceCommit.sha,
|
|
111
|
+
mergedTargetPullRequest,
|
|
112
|
+
commitAuthor,
|
|
113
|
+
}));
|
|
107
114
|
// no conflicts encountered
|
|
108
115
|
if (!needsResolving) {
|
|
109
116
|
cherrypickSpinner.succeed();
|
|
@@ -218,3 +225,15 @@ Press ENTER when the conflicts are resolved and files are staged`);
|
|
|
218
225
|
unstagedFiles: _unstagedFiles,
|
|
219
226
|
});
|
|
220
227
|
}
|
|
228
|
+
function getCommitAuthor({ options, gitConfigAuthor, commit, }) {
|
|
229
|
+
if (options.resetAuthor) {
|
|
230
|
+
return {
|
|
231
|
+
name: options.authenticatedUsername,
|
|
232
|
+
email: `<${options.authenticatedUsername}@users.noreply.github.com>`,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
name: options.gitAuthorName ?? gitConfigAuthor?.name ?? commit.author.name,
|
|
237
|
+
email: options.gitAuthorEmail ?? gitConfigAuthor?.email ?? commit.author.email,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
@@ -62,15 +62,16 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
62
62
|
const options = {
|
|
63
63
|
assignees: [],
|
|
64
64
|
authenticatedUsername: 'sqren_authenticated',
|
|
65
|
+
author: 'sqren',
|
|
65
66
|
fork: true,
|
|
66
67
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
68
|
+
repoForkOwner: 'sqren',
|
|
67
69
|
repoName: 'kibana',
|
|
68
70
|
repoOwner: 'elastic',
|
|
69
71
|
reviewers: [],
|
|
70
72
|
sourceBranch: 'myDefaultSourceBranch',
|
|
71
73
|
sourcePRLabels: [],
|
|
72
74
|
targetPRLabels: ['backport'],
|
|
73
|
-
author: 'sqren',
|
|
74
75
|
};
|
|
75
76
|
const commits = [
|
|
76
77
|
{
|
|
@@ -143,7 +144,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
143
144
|
|
|
144
145
|
### Questions ?
|
|
145
146
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
146
|
-
"head": "
|
|
147
|
+
"head": "sqren:backport/6.x/pr-1000_pr-2000",
|
|
147
148
|
"title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
|
|
148
149
|
},
|
|
149
150
|
]
|
|
@@ -170,7 +171,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
170
171
|
"Pulling latest changes",
|
|
171
172
|
"Cherry-picking: My original commit message (#1000)",
|
|
172
173
|
"Cherry-picking: My other commit message (#2000)",
|
|
173
|
-
"Pushing branch \\"
|
|
174
|
+
"Pushing branch \\"sqren:backport/6.x/pr-1000_pr-2000\\"",
|
|
174
175
|
undefined,
|
|
175
176
|
"Creating pull request",
|
|
176
177
|
"Adding labels: backport",
|
|
@@ -185,14 +186,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
185
186
|
const options = {
|
|
186
187
|
assignees: [],
|
|
187
188
|
authenticatedUsername: 'sqren_authenticated',
|
|
189
|
+
author: 'sqren',
|
|
188
190
|
fork: true,
|
|
189
191
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
192
|
+
repoForkOwner: 'the_fork_owner',
|
|
190
193
|
repoName: 'kibana',
|
|
191
194
|
repoOwner: 'elastic',
|
|
192
195
|
reviewers: [],
|
|
193
196
|
sourcePRLabels: [],
|
|
194
197
|
targetPRLabels: ['backport'],
|
|
195
|
-
author: 'sqren',
|
|
196
198
|
};
|
|
197
199
|
const commits = [
|
|
198
200
|
{
|
|
@@ -235,7 +237,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
235
237
|
|
|
236
238
|
### Questions ?
|
|
237
239
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
238
|
-
"head": "
|
|
240
|
+
"head": "the_fork_owner:backport/6.x/commit-mySha",
|
|
239
241
|
"title": "[6.x] My original commit message",
|
|
240
242
|
},
|
|
241
243
|
]
|
|
@@ -258,16 +260,17 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
258
260
|
const options = {
|
|
259
261
|
assignees: [],
|
|
260
262
|
authenticatedUsername: 'sqren_authenticated',
|
|
263
|
+
author: 'sqren',
|
|
261
264
|
fork: true,
|
|
262
265
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
263
266
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
267
|
+
repoForkOwner: 'sqren',
|
|
264
268
|
repoName: 'kibana',
|
|
265
269
|
repoOwner: 'elastic',
|
|
266
270
|
reviewers: [],
|
|
267
271
|
sourceBranch: 'myDefaultSourceBranch',
|
|
268
272
|
sourcePRLabels: [],
|
|
269
273
|
targetPRLabels: ['backport'],
|
|
270
|
-
author: 'sqren',
|
|
271
274
|
};
|
|
272
275
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
273
276
|
.post('/repos/elastic/kibana/pulls')
|
|
@@ -315,7 +318,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
315
318
|
|
|
316
319
|
### Questions ?
|
|
317
320
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
318
|
-
"head": "
|
|
321
|
+
"head": "sqren:backport/6.x/commit-mySha",
|
|
319
322
|
"title": "[6.x] My original commit message",
|
|
320
323
|
},
|
|
321
324
|
]
|
|
@@ -378,7 +381,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
378
381
|
"Pulling latest changes",
|
|
379
382
|
"Cherry-picking: My original commit message",
|
|
380
383
|
"Finalizing cherrypick",
|
|
381
|
-
"Pushing branch \\"
|
|
384
|
+
"Pushing branch \\"sqren:backport/6.x/commit-mySha\\"",
|
|
382
385
|
undefined,
|
|
383
386
|
"Creating pull request",
|
|
384
387
|
"Adding labels: backport",
|
|
@@ -416,9 +419,9 @@ function setupExecSpyForCherryPick() {
|
|
|
416
419
|
if (cmd.startsWith('git fetch')) {
|
|
417
420
|
return { stderr: '', stdout: '' };
|
|
418
421
|
}
|
|
419
|
-
// cherrypick
|
|
420
|
-
if (cmd
|
|
421
|
-
throw new ExecError_1.ExecError({ cmd });
|
|
422
|
+
// emulate cherrypick exception
|
|
423
|
+
if (cmd.includes('cherry-pick -x mySha')) {
|
|
424
|
+
throw new ExecError_1.ExecError({ cmd, code: 128 });
|
|
422
425
|
}
|
|
423
426
|
// getIsCommitInBranch
|
|
424
427
|
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGitConfigAuthor = void 0;
|
|
4
|
+
const git_1 = require("../services/git");
|
|
5
|
+
async function getGitConfigAuthor(options) {
|
|
6
|
+
const localRepoPath = await (0, git_1.getLocalRepoPath)(options);
|
|
7
|
+
if (!localRepoPath) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
|
|
12
|
+
email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getGitConfigAuthor = getGitConfigAuthor;
|
package/dist/ui/setupRepo.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Commit } from '../entrypoint.module';
|
|
2
1
|
import { ValidConfigOptions } from '../options/options';
|
|
3
|
-
export declare function setupRepo(options: ValidConfigOptions
|
|
2
|
+
export declare function setupRepo(options: ValidConfigOptions): Promise<void>;
|
package/dist/ui/setupRepo.js
CHANGED
|
@@ -6,7 +6,7 @@ const HandledError_1 = require("../services/HandledError");
|
|
|
6
6
|
const env_1 = require("../services/env");
|
|
7
7
|
const git_1 = require("../services/git");
|
|
8
8
|
const ora_1 = require("./ora");
|
|
9
|
-
async function setupRepo(options
|
|
9
|
+
async function setupRepo(options) {
|
|
10
10
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
11
11
|
const isAlreadyCloned = await getIsRepoCloned(options);
|
|
12
12
|
if (options.cwd.includes(repoPath)) {
|
|
@@ -37,14 +37,13 @@ async function setupRepo(options, commits) {
|
|
|
37
37
|
throw e;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
await setupGitUsernameAndEmail(options, commits);
|
|
41
40
|
// delete default "origin" remote to avoid confusion
|
|
42
41
|
await (0, git_1.deleteRemote)(options, 'origin');
|
|
43
42
|
// ensure remote are setup with latest accessToken
|
|
44
|
-
await (0, git_1.deleteRemote)(options, options.
|
|
45
|
-
await (0, git_1.addRemote)(options, options.
|
|
43
|
+
await (0, git_1.deleteRemote)(options, options.repoForkOwner);
|
|
44
|
+
await (0, git_1.addRemote)(options, options.repoForkOwner);
|
|
46
45
|
// add remote for non-fork repo (if the above is a fork)
|
|
47
|
-
if (options.
|
|
46
|
+
if (options.repoForkOwner !== options.repoOwner) {
|
|
48
47
|
await (0, git_1.deleteRemote)(options, options.repoOwner);
|
|
49
48
|
await (0, git_1.addRemote)(options, options.repoOwner);
|
|
50
49
|
}
|
|
@@ -55,34 +54,3 @@ async function getIsRepoCloned(options) {
|
|
|
55
54
|
const projectRoot = await (0, git_1.getGitProjectRootPath)(repoPath);
|
|
56
55
|
return repoPath === projectRoot;
|
|
57
56
|
}
|
|
58
|
-
async function setupGitUsernameAndEmail(options, commits) {
|
|
59
|
-
const repoPath = (0, env_1.getRepoPath)(options);
|
|
60
|
-
const userName = await (0, git_1.getGitConfig)({ dir: repoPath, key: 'user.name' });
|
|
61
|
-
const userEmail = await (0, git_1.getGitConfig)({ dir: repoPath, key: 'user.email' });
|
|
62
|
-
// return early if user.email and user.name is already set
|
|
63
|
-
if (userName && userEmail) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const commitAuthor = commits[0].author;
|
|
67
|
-
const localRepoPath = await (0, git_1.getLocalRepoPath)(options);
|
|
68
|
-
if (!userName) {
|
|
69
|
-
const gitConfigUsername = localRepoPath
|
|
70
|
-
? await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' })
|
|
71
|
-
: undefined;
|
|
72
|
-
await (0, git_1.setGitConfig)({
|
|
73
|
-
dir: repoPath,
|
|
74
|
-
key: 'user.name',
|
|
75
|
-
value: gitConfigUsername ?? options.gitUserName ?? commitAuthor.name,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (!userEmail) {
|
|
79
|
-
const gitConfigEmail = localRepoPath
|
|
80
|
-
? await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' })
|
|
81
|
-
: undefined;
|
|
82
|
-
await (0, git_1.setGitConfig)({
|
|
83
|
-
dir: repoPath,
|
|
84
|
-
key: 'user.email',
|
|
85
|
-
value: gitConfigEmail ?? options.gitUserEmail ?? commitAuthor.email,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|