backport 8.4.2 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entrypoint.module.d.ts +1 -1
- package/dist/entrypoint.module.js +8 -7
- package/dist/entrypoint.module.private.test.js +79 -29
- package/dist/lib/author.d.ts +13 -0
- package/dist/lib/author.js +28 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +14 -20
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +14 -4
- package/dist/lib/child-process-promisified.d.ts +1 -1
- package/dist/lib/child-process-promisified.js +14 -3
- package/dist/lib/getCommits.js +14 -9
- package/dist/lib/getCommitsWithoutBackports.js +3 -3
- package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +6 -10
- package/dist/lib/getTargetBranches.test.js +9 -5
- package/dist/lib/git.d.ts +9 -7
- package/dist/lib/git.js +12 -4
- package/dist/lib/git.private.test.js +21 -4
- package/dist/lib/git.test.js +31 -7
- package/dist/lib/github/v3/createPullRequest.test.js +39 -13
- package/dist/lib/github/v3/createStatusComment.js +5 -2
- package/dist/lib/github/v3/createStatusComment.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/lib/prompt.test.js +37 -9
- package/dist/lib/prompts.js +5 -2
- package/dist/lib/setupRepo.js +3 -3
- package/dist/lib/setupRepo.test.js +5 -5
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
- package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +1 -1
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
- package/dist/test/sandbox.d.ts +1 -0
- package/dist/test/sandbox.js +3 -2
- package/dist/utils/filterUnmergedCommits.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +15 -15
- package/yarn.lock +561 -471
- package/dist/lib/getGitConfigAuthor.d.ts +0 -6
- package/dist/lib/getGitConfigAuthor.js +0 -15
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
|
@@ -34,8 +34,8 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
34
34
|
afterEach(() => {
|
|
35
35
|
jest.restoreAllMocks();
|
|
36
36
|
});
|
|
37
|
-
describe('
|
|
38
|
-
function setupExpectedPullRequests({
|
|
37
|
+
describe('pullRequestStates', () => {
|
|
38
|
+
function setupExpectedPullRequests({ pullRequestStates, }) {
|
|
39
39
|
// simulate 1 unbackported commit
|
|
40
40
|
jest
|
|
41
41
|
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
@@ -45,7 +45,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
45
45
|
email: 'soren.louv@elastic.co',
|
|
46
46
|
name: 'Søren Louv-Jansen',
|
|
47
47
|
},
|
|
48
|
+
suggestedTargetBranches: [],
|
|
48
49
|
sourceCommit: {
|
|
50
|
+
branchLabelMapping: {},
|
|
49
51
|
committedDate: '10',
|
|
50
52
|
message: 'First commit (#1)',
|
|
51
53
|
sha: 'xyz',
|
|
@@ -58,7 +60,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
58
60
|
sha: 'xyz',
|
|
59
61
|
},
|
|
60
62
|
},
|
|
61
|
-
|
|
63
|
+
pullRequestStates,
|
|
62
64
|
sourceBranch: 'main',
|
|
63
65
|
},
|
|
64
66
|
]);
|
|
@@ -68,12 +70,14 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
68
70
|
options: {},
|
|
69
71
|
commit: {
|
|
70
72
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
73
|
+
suggestedTargetBranches: [],
|
|
71
74
|
sourceCommit: {
|
|
75
|
+
branchLabelMapping: {},
|
|
72
76
|
committedDate: '100',
|
|
73
77
|
message: 'Second commit (#2)',
|
|
74
78
|
sha: 'abc',
|
|
75
79
|
},
|
|
76
|
-
|
|
80
|
+
pullRequestStates: [],
|
|
77
81
|
sourceBranch: 'main',
|
|
78
82
|
},
|
|
79
83
|
targetBranch: '7.x',
|
|
@@ -82,13 +86,13 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
82
86
|
}
|
|
83
87
|
it('should not unbackported commits if no backports were expected', async () => {
|
|
84
88
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
85
|
-
|
|
89
|
+
pullRequestStates: [],
|
|
86
90
|
});
|
|
87
91
|
expect(commitsWithoutBackports.length).toEqual(0);
|
|
88
92
|
});
|
|
89
93
|
it('should display as missing if a backport is CLOSED', async () => {
|
|
90
94
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
91
|
-
|
|
95
|
+
pullRequestStates: [
|
|
92
96
|
{
|
|
93
97
|
state: 'CLOSED',
|
|
94
98
|
branch: '7.x',
|
|
@@ -101,13 +105,20 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
101
105
|
});
|
|
102
106
|
it('should display as missing if a backport is NOT_CREATED', async () => {
|
|
103
107
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
104
|
-
|
|
108
|
+
pullRequestStates: [
|
|
109
|
+
{
|
|
110
|
+
state: 'NOT_CREATED',
|
|
111
|
+
branch: '7.x',
|
|
112
|
+
label: 'v7.0.0',
|
|
113
|
+
isSourceBranch: false,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
105
116
|
});
|
|
106
117
|
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
|
|
107
118
|
});
|
|
108
119
|
it('should display as pending if a backport is OPEN', async () => {
|
|
109
120
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
110
|
-
|
|
121
|
+
pullRequestStates: [
|
|
111
122
|
{
|
|
112
123
|
state: 'OPEN',
|
|
113
124
|
branch: '7.x',
|
|
@@ -120,7 +131,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
120
131
|
});
|
|
121
132
|
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
122
133
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
123
|
-
|
|
134
|
+
pullRequestStates: [
|
|
124
135
|
{
|
|
125
136
|
state: 'MERGED',
|
|
126
137
|
branch: '7.x',
|
|
@@ -143,7 +154,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
143
154
|
email: 'soren.louv@elastic.co',
|
|
144
155
|
name: 'Søren Louv-Jansen',
|
|
145
156
|
},
|
|
157
|
+
suggestedTargetBranches: [],
|
|
146
158
|
sourceCommit: {
|
|
159
|
+
branchLabelMapping: {},
|
|
147
160
|
committedDate: offendingCommitDate,
|
|
148
161
|
message: 'First commit (#1)',
|
|
149
162
|
sha: 'xyz',
|
|
@@ -157,7 +170,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
157
170
|
},
|
|
158
171
|
},
|
|
159
172
|
sourceBranch: 'main',
|
|
160
|
-
|
|
173
|
+
pullRequestStates: [
|
|
161
174
|
{
|
|
162
175
|
state: 'OPEN',
|
|
163
176
|
branch: '7.x',
|
|
@@ -173,7 +186,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
173
186
|
options: {},
|
|
174
187
|
commit: {
|
|
175
188
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
189
|
+
suggestedTargetBranches: [],
|
|
176
190
|
sourceCommit: {
|
|
191
|
+
branchLabelMapping: {},
|
|
177
192
|
committedDate: currentCommitDate,
|
|
178
193
|
message: 'Second commit (#2)',
|
|
179
194
|
sha: 'abc',
|
|
@@ -187,7 +202,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
187
202
|
},
|
|
188
203
|
},
|
|
189
204
|
sourceBranch: 'main',
|
|
190
|
-
|
|
205
|
+
pullRequestStates: [],
|
|
191
206
|
},
|
|
192
207
|
targetBranch: '7.x',
|
|
193
208
|
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
@@ -219,7 +234,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
219
234
|
email: 'soren.louv@elastic.co',
|
|
220
235
|
name: 'Søren Louv-Jansen',
|
|
221
236
|
},
|
|
237
|
+
suggestedTargetBranches: [],
|
|
222
238
|
sourceCommit: {
|
|
239
|
+
branchLabelMapping: {},
|
|
223
240
|
committedDate: '10',
|
|
224
241
|
message: 'First commit (#1)',
|
|
225
242
|
sha: 'xyz',
|
|
@@ -233,7 +250,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
233
250
|
},
|
|
234
251
|
},
|
|
235
252
|
sourceBranch: 'main',
|
|
236
|
-
|
|
253
|
+
pullRequestStates: [
|
|
237
254
|
{
|
|
238
255
|
branch: offendingCommitTargetBranch,
|
|
239
256
|
state: 'OPEN',
|
|
@@ -250,7 +267,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
250
267
|
// commit that is being backported
|
|
251
268
|
commit: {
|
|
252
269
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
270
|
+
suggestedTargetBranches: [],
|
|
253
271
|
sourceCommit: {
|
|
272
|
+
branchLabelMapping: {},
|
|
254
273
|
committedDate: '100',
|
|
255
274
|
message: 'Second commit (#2)',
|
|
256
275
|
sha: 'abc',
|
|
@@ -263,7 +282,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
263
282
|
sha: 'abc',
|
|
264
283
|
},
|
|
265
284
|
},
|
|
266
|
-
|
|
285
|
+
pullRequestStates: [],
|
|
267
286
|
sourceBranch: 'main',
|
|
268
287
|
},
|
|
269
288
|
targetBranch: currentCommitTargetBranch,
|
|
@@ -295,12 +314,14 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
295
314
|
email: 'soren.louv@elastic.co',
|
|
296
315
|
name: 'Søren Louv-Jansen',
|
|
297
316
|
},
|
|
317
|
+
suggestedTargetBranches: [],
|
|
298
318
|
sourceCommit: {
|
|
319
|
+
branchLabelMapping: {},
|
|
299
320
|
committedDate: '10',
|
|
300
321
|
sha: 'xyz',
|
|
301
322
|
message: 'First commit (#1)',
|
|
302
323
|
},
|
|
303
|
-
|
|
324
|
+
pullRequestStates: [],
|
|
304
325
|
sourceBranch: 'main',
|
|
305
326
|
},
|
|
306
327
|
]);
|
|
@@ -310,7 +331,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
310
331
|
options: {},
|
|
311
332
|
commit: {
|
|
312
333
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
334
|
+
suggestedTargetBranches: [],
|
|
313
335
|
sourceCommit: {
|
|
336
|
+
branchLabelMapping: {},
|
|
314
337
|
committedDate: '100',
|
|
315
338
|
message: 'Second commit (#2)',
|
|
316
339
|
sha: 'abc',
|
|
@@ -323,7 +346,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
323
346
|
sha: 'abc',
|
|
324
347
|
},
|
|
325
348
|
},
|
|
326
|
-
|
|
349
|
+
pullRequestStates: [],
|
|
327
350
|
sourceBranch: 'main',
|
|
328
351
|
},
|
|
329
352
|
targetBranch: '7.x',
|
|
@@ -2,4 +2,4 @@ import { TargetBranchChoice } from '../options/ConfigOptions';
|
|
|
2
2
|
import { ValidConfigOptions } from '../options/options';
|
|
3
3
|
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
4
4
|
export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): Promise<string[]>;
|
|
5
|
-
export declare function getTargetBranchChoices(options: ValidConfigOptions,
|
|
5
|
+
export declare function getTargetBranchChoices(options: ValidConfigOptions, suggestedTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
|
|
@@ -10,22 +10,18 @@ async function getTargetBranches(options, commits) {
|
|
|
10
10
|
return options.targetBranches;
|
|
11
11
|
}
|
|
12
12
|
// target branches from the first commit
|
|
13
|
-
const
|
|
14
|
-
? commits[0].expectedTargetPullRequests
|
|
15
|
-
.filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED')
|
|
16
|
-
.map((pr) => pr.branch)
|
|
17
|
-
: [];
|
|
13
|
+
const suggestedTargetBranches = commits.length === 1 ? commits[0].suggestedTargetBranches : [];
|
|
18
14
|
// require target branches to be specified when when in non-interactive mode
|
|
19
15
|
if (!options.interactive) {
|
|
20
|
-
if ((0, lodash_1.isEmpty)(
|
|
16
|
+
if ((0, lodash_1.isEmpty)(suggestedTargetBranches)) {
|
|
21
17
|
throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
|
|
22
18
|
}
|
|
23
|
-
return
|
|
19
|
+
return suggestedTargetBranches;
|
|
24
20
|
}
|
|
25
21
|
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
26
22
|
// this is specifically needed when backporting a PR like `backport --pr 123` and the source PR was merged to a non-default (aka non-master) branch.
|
|
27
23
|
const { sourceBranch } = commits[0];
|
|
28
|
-
const targetBranchChoices = getTargetBranchChoices(options,
|
|
24
|
+
const targetBranchChoices = getTargetBranchChoices(options, suggestedTargetBranches, sourceBranch);
|
|
29
25
|
// render prmompt for selecting target branches
|
|
30
26
|
return (0, prompts_1.promptForTargetBranches)({
|
|
31
27
|
targetBranchChoices,
|
|
@@ -33,7 +29,7 @@ async function getTargetBranches(options, commits) {
|
|
|
33
29
|
});
|
|
34
30
|
}
|
|
35
31
|
exports.getTargetBranches = getTargetBranches;
|
|
36
|
-
function getTargetBranchChoices(options,
|
|
32
|
+
function getTargetBranchChoices(options, suggestedTargetBranches, sourceBranch) {
|
|
37
33
|
// exclude sourceBranch from targetBranchChoices
|
|
38
34
|
const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
|
|
39
35
|
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
@@ -44,7 +40,7 @@ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
|
44
40
|
}
|
|
45
41
|
// select missing target branches (based on pull request labels)
|
|
46
42
|
return targetBranchesChoices.map((choice) => {
|
|
47
|
-
const isChecked =
|
|
43
|
+
const isChecked = suggestedTargetBranches.includes(choice.name);
|
|
48
44
|
return { ...choice, checked: isChecked };
|
|
49
45
|
});
|
|
50
46
|
}
|
|
@@ -47,6 +47,7 @@ describe('getTargetBranches', () => {
|
|
|
47
47
|
{
|
|
48
48
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
49
49
|
sourceCommit: {
|
|
50
|
+
branchLabelMapping: {},
|
|
50
51
|
committedDate: 'aaa',
|
|
51
52
|
message: 'hey',
|
|
52
53
|
sha: 'abcd',
|
|
@@ -60,7 +61,8 @@ describe('getTargetBranches', () => {
|
|
|
60
61
|
},
|
|
61
62
|
},
|
|
62
63
|
sourceBranch: '7.x',
|
|
63
|
-
|
|
64
|
+
suggestedTargetBranches: [],
|
|
65
|
+
pullRequestStates: [],
|
|
64
66
|
},
|
|
65
67
|
];
|
|
66
68
|
branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
@@ -99,7 +101,6 @@ describe('getTargetBranches', () => {
|
|
|
99
101
|
const commits = [];
|
|
100
102
|
await expect(() => {
|
|
101
103
|
return (0, getTargetBranches_1.getTargetBranches)({
|
|
102
|
-
expectedTargetPullRequests: [],
|
|
103
104
|
interactive: false,
|
|
104
105
|
}, commits);
|
|
105
106
|
}).rejects.toThrowError('There are no branches to backport to. Aborting.');
|
|
@@ -107,7 +108,8 @@ describe('getTargetBranches', () => {
|
|
|
107
108
|
it('should return missing backports', async () => {
|
|
108
109
|
const commits = [
|
|
109
110
|
{
|
|
110
|
-
|
|
111
|
+
suggestedTargetBranches: ['7.x'],
|
|
112
|
+
pullRequestStates: [
|
|
111
113
|
{ branch: '7.2', state: 'MERGED' },
|
|
112
114
|
{ branch: '7.1', state: 'OPEN' },
|
|
113
115
|
{ branch: '7.x', state: 'NOT_CREATED' },
|
|
@@ -118,7 +120,7 @@ describe('getTargetBranches', () => {
|
|
|
118
120
|
expect(targetBranches).toEqual(['7.x']);
|
|
119
121
|
});
|
|
120
122
|
});
|
|
121
|
-
describe('when `
|
|
123
|
+
describe('when `pullRequestStates` is missing a backport to 7.x', () => {
|
|
122
124
|
let targetBranchChoices;
|
|
123
125
|
beforeEach(async () => {
|
|
124
126
|
const options = {
|
|
@@ -139,6 +141,7 @@ describe('getTargetBranches', () => {
|
|
|
139
141
|
{
|
|
140
142
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
141
143
|
sourceCommit: {
|
|
144
|
+
branchLabelMapping: {},
|
|
142
145
|
committedDate: 'bbb',
|
|
143
146
|
message: '[backport] Bump to 5.1.3 (#62286)',
|
|
144
147
|
sha: 'my-sha',
|
|
@@ -152,7 +155,8 @@ describe('getTargetBranches', () => {
|
|
|
152
155
|
},
|
|
153
156
|
},
|
|
154
157
|
sourceBranch: 'master',
|
|
155
|
-
|
|
158
|
+
suggestedTargetBranches: ['7.x'],
|
|
159
|
+
pullRequestStates: [],
|
|
156
160
|
},
|
|
157
161
|
];
|
|
158
162
|
await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import {
|
|
2
|
+
import { CommitAuthor } from './author';
|
|
3
|
+
import { TargetPullRequest } from './sourceCommit/getPullRequestStates';
|
|
3
4
|
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
4
5
|
export declare function getRemoteUrl({ repoName, accessToken, gitHostname }: ValidConfigOptions, repoOwner: string): string;
|
|
5
6
|
export declare function cloneRepo({ sourcePath, targetPath }: {
|
|
@@ -31,11 +32,8 @@ export declare function getShasInMergeCommit(options: ValidConfigOptions, sha: s
|
|
|
31
32
|
export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
|
|
32
33
|
options: ValidConfigOptions;
|
|
33
34
|
sha: string;
|
|
34
|
-
mergedTargetPullRequest?:
|
|
35
|
-
commitAuthor:
|
|
36
|
-
name: string;
|
|
37
|
-
email: string;
|
|
38
|
-
};
|
|
35
|
+
mergedTargetPullRequest?: TargetPullRequest;
|
|
36
|
+
commitAuthor: CommitAuthor;
|
|
39
37
|
}): Promise<{
|
|
40
38
|
conflictingFiles: {
|
|
41
39
|
absolute: string;
|
|
@@ -44,7 +42,11 @@ export declare function cherrypick({ options, sha, mergedTargetPullRequest, comm
|
|
|
44
42
|
unstagedFiles: string[];
|
|
45
43
|
needsResolving: boolean;
|
|
46
44
|
}>;
|
|
47
|
-
export declare function commitChanges(commit
|
|
45
|
+
export declare function commitChanges({ options, commit, commitAuthor, }: {
|
|
46
|
+
options: ValidConfigOptions;
|
|
47
|
+
commit: Commit;
|
|
48
|
+
commitAuthor: CommitAuthor;
|
|
49
|
+
}): Promise<void>;
|
|
48
50
|
export declare type ConflictingFiles = Awaited<ReturnType<typeof getConflictingFiles>>;
|
|
49
51
|
export declare function getConflictingFiles(options: ValidConfigOptions): Promise<{
|
|
50
52
|
absolute: string;
|
package/dist/lib/git.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.getRemoteUrl = getRemoteUrl;
|
|
|
17
17
|
async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
18
18
|
logger_1.logger.info(`Cloning repo from ${sourcePath} to ${targetPath}`);
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
|
-
const subprocess = (0, child_process_promisified_1.
|
|
20
|
+
const subprocess = (0, child_process_promisified_1.spawnStream)('git', [
|
|
21
21
|
'clone',
|
|
22
22
|
sourcePath,
|
|
23
23
|
targetPath,
|
|
@@ -198,9 +198,9 @@ async function getShasInMergeCommit(options, sha) {
|
|
|
198
198
|
exports.getShasInMergeCommit = getShasInMergeCommit;
|
|
199
199
|
async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
|
|
200
200
|
const cmdArgs = [
|
|
201
|
-
|
|
201
|
+
`-c`,
|
|
202
202
|
`user.name="${commitAuthor.name}"`,
|
|
203
|
-
|
|
203
|
+
`-c`,
|
|
204
204
|
`user.email="${commitAuthor.email}"`,
|
|
205
205
|
`cherry-pick`,
|
|
206
206
|
...(options.mainline != undefined
|
|
@@ -247,11 +247,15 @@ async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor,
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
exports.cherrypick = cherrypick;
|
|
250
|
-
async function commitChanges(commit,
|
|
250
|
+
async function commitChanges({ options, commit, commitAuthor, }) {
|
|
251
251
|
const noVerifyFlag = options.noVerify ? ['--no-verify'] : [];
|
|
252
252
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
253
253
|
try {
|
|
254
254
|
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
255
|
+
`-c`,
|
|
256
|
+
`user.name="${commitAuthor.name}"`,
|
|
257
|
+
`-c`,
|
|
258
|
+
`user.email="${commitAuthor.email}"`,
|
|
255
259
|
'commit',
|
|
256
260
|
'--no-edit',
|
|
257
261
|
...noVerifyFlag, // bypass pre-commit and commit-msg hooks
|
|
@@ -268,6 +272,10 @@ async function commitChanges(commit, options) {
|
|
|
268
272
|
// this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
|
|
269
273
|
if (e.context.stderr.includes('Aborting commit due to empty commit message')) {
|
|
270
274
|
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
275
|
+
`-c`,
|
|
276
|
+
`user.name="${commitAuthor.name}"`,
|
|
277
|
+
`-c`,
|
|
278
|
+
`user.email="${commitAuthor.email}"`,
|
|
271
279
|
'commit',
|
|
272
280
|
`--message=${commit.sourceCommit.message}`,
|
|
273
281
|
...noVerifyFlag, // bypass pre-commit and commit-msg hooks
|
|
@@ -39,7 +39,7 @@ jest.unmock('del');
|
|
|
39
39
|
jest.unmock('make-dir');
|
|
40
40
|
const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
|
|
41
41
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
42
|
-
describe('git.
|
|
42
|
+
describe('git.private', () => {
|
|
43
43
|
describe('getIsCommitInBranch', () => {
|
|
44
44
|
let firstSha;
|
|
45
45
|
let secondSha;
|
|
@@ -80,6 +80,23 @@ describe('git.integration', () => {
|
|
|
80
80
|
expect(isSecondCommitInBranch).toEqual(false);
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
|
+
describe('deleteRemote', () => {
|
|
84
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
85
|
+
filename: __filename,
|
|
86
|
+
specname: 'deleteRemote',
|
|
87
|
+
});
|
|
88
|
+
it('should handle when deleting a remote that does not exist', async () => {
|
|
89
|
+
const options = {
|
|
90
|
+
repoName: 'kibana',
|
|
91
|
+
repoOwner: 'elastic',
|
|
92
|
+
dir: cwd,
|
|
93
|
+
};
|
|
94
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
95
|
+
await gitInit(cwd);
|
|
96
|
+
const res = await (0, git_1.deleteRemote)(options, 'my-remote-foo');
|
|
97
|
+
expect(res).toBe(undefined);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
83
100
|
describe('getGitConfig', () => {
|
|
84
101
|
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
85
102
|
filename: __filename,
|
|
@@ -293,7 +310,7 @@ describe('git.integration', () => {
|
|
|
293
310
|
cwd,
|
|
294
311
|
});
|
|
295
312
|
expect(async () => {
|
|
296
|
-
return await (0, git_1.commitChanges)(commit, options);
|
|
313
|
+
return await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
297
314
|
}).not.toThrowError();
|
|
298
315
|
const message = await getMostRecentCommitMessage(cwd);
|
|
299
316
|
expect(message).toBe('Update my-file-1.txt');
|
|
@@ -309,7 +326,7 @@ describe('git.integration', () => {
|
|
|
309
326
|
filename: 'my-file-2.txt',
|
|
310
327
|
cwd,
|
|
311
328
|
});
|
|
312
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
329
|
+
await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
313
330
|
const message = await getMostRecentCommitMessage(cwd);
|
|
314
331
|
expect(message).toBe('my fallback commit message');
|
|
315
332
|
});
|
|
@@ -329,7 +346,7 @@ describe('git.integration', () => {
|
|
|
329
346
|
}
|
|
330
347
|
// disregard conflicts and stage all files
|
|
331
348
|
await childProcess.exec('git add -A', { cwd });
|
|
332
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
349
|
+
await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
333
350
|
const message = await getMostRecentCommitMessage(cwd);
|
|
334
351
|
expect(message).toMatchInlineSnapshot(`
|
|
335
352
|
"Add 🇩🇰 (#12)
|
package/dist/lib/git.test.js
CHANGED
|
@@ -477,19 +477,21 @@ describe('commitChanges', () => {
|
|
|
477
477
|
};
|
|
478
478
|
const commit = {
|
|
479
479
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
480
|
+
suggestedTargetBranches: [],
|
|
480
481
|
sourceCommit: {
|
|
482
|
+
branchLabelMapping: {},
|
|
481
483
|
message: 'The original commit message',
|
|
482
484
|
committedDate: '2020',
|
|
483
485
|
sha: 'abc',
|
|
484
486
|
},
|
|
485
487
|
sourceBranch: 'master',
|
|
486
|
-
|
|
488
|
+
pullRequestStates: [],
|
|
487
489
|
};
|
|
488
490
|
it('should return when changes committed successfully', async () => {
|
|
489
491
|
jest
|
|
490
492
|
.spyOn(childProcess, 'spawnPromise')
|
|
491
493
|
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
492
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
494
|
+
await expect(await (0, git_1.commitChanges)({ commit, commitAuthor, options })).toBe(undefined);
|
|
493
495
|
});
|
|
494
496
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
495
497
|
const err = new childProcess.SpawnError({
|
|
@@ -499,7 +501,7 @@ describe('commitChanges', () => {
|
|
|
499
501
|
stderr: '',
|
|
500
502
|
});
|
|
501
503
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
502
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
504
|
+
await expect(await (0, git_1.commitChanges)({ commit, commitAuthor, options })).toBe(undefined);
|
|
503
505
|
});
|
|
504
506
|
describe('when commit fails due to empty message', () => {
|
|
505
507
|
let spy;
|
|
@@ -520,12 +522,34 @@ describe('commitChanges', () => {
|
|
|
520
522
|
code: 0,
|
|
521
523
|
cmdArgs: [],
|
|
522
524
|
});
|
|
523
|
-
res = await (0, git_1.commitChanges)(commit, options);
|
|
525
|
+
res = await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
524
526
|
});
|
|
525
527
|
it('should manually set the commit message', () => {
|
|
526
528
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
527
|
-
expect(spy
|
|
528
|
-
|
|
529
|
+
expect(spy.mock.calls[0]).toEqual([
|
|
530
|
+
'git',
|
|
531
|
+
[
|
|
532
|
+
'-c',
|
|
533
|
+
'user.name="Soren L"',
|
|
534
|
+
'-c',
|
|
535
|
+
'user.email="soren@mail.dk"',
|
|
536
|
+
'commit',
|
|
537
|
+
'--no-edit',
|
|
538
|
+
],
|
|
539
|
+
expect.any(String),
|
|
540
|
+
]);
|
|
541
|
+
expect(spy.mock.calls[1]).toEqual([
|
|
542
|
+
'git',
|
|
543
|
+
[
|
|
544
|
+
'-c',
|
|
545
|
+
'user.name="Soren L"',
|
|
546
|
+
'-c',
|
|
547
|
+
'user.email="soren@mail.dk"',
|
|
548
|
+
'commit',
|
|
549
|
+
'--message=The original commit message',
|
|
550
|
+
],
|
|
551
|
+
expect.any(String),
|
|
552
|
+
]);
|
|
529
553
|
});
|
|
530
554
|
it('should handle the error and resolve successfully', async () => {
|
|
531
555
|
await expect(res).toBe(undefined);
|
|
@@ -535,7 +559,7 @@ describe('commitChanges', () => {
|
|
|
535
559
|
const err = new Error('another error');
|
|
536
560
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
537
561
|
expect.assertions(1);
|
|
538
|
-
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
562
|
+
await expect((0, git_1.commitChanges)({ commit, commitAuthor, options })).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
539
563
|
});
|
|
540
564
|
});
|
|
541
565
|
describe('addRemote', () => {
|