backport 7.2.0-beta.1 → 7.2.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.cli.js +0 -0
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +1 -0
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +2 -1
- package/dist/runSequentially.test.js +54 -30
- package/dist/services/git.d.ts +1 -3
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
- package/dist/services/github/v4/apiRequestV4.js +15 -14
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -5
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/remoteConfig.js +2 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
- package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
- package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
- package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +85 -38
- package/dist/test/{backport-e2e.mutation.test.d.ts → e2e/module.e2e.private.test.d.ts} +0 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +2 -2
- package/dist/ui/getCommits.js +6 -4
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +9 -9
- package/yarn.lock +121 -114
- package/dist/test/backport-e2e.mutation.test.js +0 -347
|
@@ -11,12 +11,16 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
11
11
|
nock_1.default.cleanAll();
|
|
12
12
|
});
|
|
13
13
|
it('should return empty when there is no associated PR', () => {
|
|
14
|
+
// no associated pull request
|
|
15
|
+
const sourcePullRequest = null;
|
|
14
16
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
15
17
|
sourceCommit: { message: 'identical messages (#1234)' },
|
|
16
|
-
sourcePullRequest
|
|
18
|
+
sourcePullRequest,
|
|
19
|
+
});
|
|
20
|
+
const expectedTargetPRs = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
21
|
+
sourceCommit: mockSourceCommit,
|
|
22
|
+
latestBranchLabelMapping: {},
|
|
17
23
|
});
|
|
18
|
-
const branchLabelMapping = {};
|
|
19
|
-
const expectedTargetPRs = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(mockSourceCommit, branchLabelMapping);
|
|
20
24
|
expect(expectedTargetPRs).toEqual([]);
|
|
21
25
|
});
|
|
22
26
|
it('should return a result when sourceCommit message matches the commit of the target pull request', () => {
|
|
@@ -32,8 +36,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
32
36
|
},
|
|
33
37
|
],
|
|
34
38
|
});
|
|
35
|
-
const
|
|
36
|
-
|
|
39
|
+
const expectedTargetPRs = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
40
|
+
sourceCommit: mockSourceCommit,
|
|
41
|
+
latestBranchLabelMapping: {},
|
|
42
|
+
});
|
|
37
43
|
expect(expectedTargetPRs).toEqual([
|
|
38
44
|
{
|
|
39
45
|
branch: '6.x',
|
|
@@ -57,12 +63,14 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
57
63
|
targetBranch: '6.x',
|
|
58
64
|
commitMessages: ['identical messages (#1234)'],
|
|
59
65
|
number: 5678,
|
|
60
|
-
repoName: 'foo', // this
|
|
66
|
+
repoName: 'foo', // this repoName does not match 'kibana'
|
|
61
67
|
},
|
|
62
68
|
],
|
|
63
69
|
});
|
|
64
|
-
const
|
|
65
|
-
|
|
70
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
71
|
+
sourceCommit: mockSourceCommit,
|
|
72
|
+
latestBranchLabelMapping: {},
|
|
73
|
+
});
|
|
66
74
|
expect(expectedTargetPullRequests).toEqual([]);
|
|
67
75
|
});
|
|
68
76
|
it('should return empty when repoOwner does not match', () => {
|
|
@@ -75,20 +83,20 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
75
83
|
targetBranch: '6.x',
|
|
76
84
|
commitMessages: ['identical messages (#1234)'],
|
|
77
85
|
number: 5678,
|
|
78
|
-
repoOwner: 'foo', // this
|
|
86
|
+
repoOwner: 'foo', // this repoOwner does not match `elastic`
|
|
79
87
|
},
|
|
80
88
|
],
|
|
81
89
|
});
|
|
82
|
-
const
|
|
83
|
-
|
|
90
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
91
|
+
sourceCommit: mockSourceCommit,
|
|
92
|
+
latestBranchLabelMapping: {},
|
|
93
|
+
});
|
|
84
94
|
expect(expectedTargetPullRequests).toEqual([]);
|
|
85
95
|
});
|
|
86
96
|
it('should return empty when commit messages do not match', () => {
|
|
87
97
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
88
98
|
sourceCommit: { message: 'message one (#1234)' },
|
|
89
|
-
sourcePullRequest: {
|
|
90
|
-
number: 1234,
|
|
91
|
-
},
|
|
99
|
+
sourcePullRequest: { number: 1234 },
|
|
92
100
|
timelineItems: [
|
|
93
101
|
{
|
|
94
102
|
state: 'MERGED',
|
|
@@ -98,16 +106,16 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
98
106
|
},
|
|
99
107
|
],
|
|
100
108
|
});
|
|
101
|
-
const
|
|
102
|
-
|
|
109
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
110
|
+
sourceCommit: mockSourceCommit,
|
|
111
|
+
latestBranchLabelMapping: {},
|
|
112
|
+
});
|
|
103
113
|
expect(expectedTargetPullRequests).toEqual([]);
|
|
104
114
|
});
|
|
105
115
|
it('should return a result if commits messages are different but title includes message and number', () => {
|
|
106
116
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
107
117
|
sourceCommit: { message: 'message one (#1234)' },
|
|
108
|
-
sourcePullRequest: {
|
|
109
|
-
number: 1234,
|
|
110
|
-
},
|
|
118
|
+
sourcePullRequest: { number: 1234 },
|
|
111
119
|
timelineItems: [
|
|
112
120
|
{
|
|
113
121
|
state: 'MERGED',
|
|
@@ -118,8 +126,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
118
126
|
},
|
|
119
127
|
],
|
|
120
128
|
});
|
|
121
|
-
const
|
|
122
|
-
|
|
129
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
130
|
+
sourceCommit: mockSourceCommit,
|
|
131
|
+
latestBranchLabelMapping: {},
|
|
132
|
+
});
|
|
123
133
|
expect(expectedTargetPullRequests).toEqual([
|
|
124
134
|
{
|
|
125
135
|
branch: '6.x',
|
|
@@ -136,9 +146,7 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
136
146
|
it('should return empty when only pull request title (but not pull number) matches', () => {
|
|
137
147
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
138
148
|
sourceCommit: { message: 'message one (#1234)' },
|
|
139
|
-
sourcePullRequest: {
|
|
140
|
-
number: 1234,
|
|
141
|
-
},
|
|
149
|
+
sourcePullRequest: { number: 1234 },
|
|
142
150
|
timelineItems: [
|
|
143
151
|
{
|
|
144
152
|
state: 'MERGED',
|
|
@@ -149,16 +157,16 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
149
157
|
},
|
|
150
158
|
],
|
|
151
159
|
});
|
|
152
|
-
const
|
|
153
|
-
|
|
160
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
161
|
+
sourceCommit: mockSourceCommit,
|
|
162
|
+
latestBranchLabelMapping: {},
|
|
163
|
+
});
|
|
154
164
|
expect(expectedTargetPullRequests).toEqual([]);
|
|
155
165
|
});
|
|
156
166
|
it('should return a result when first line of a multiline commit message matches', () => {
|
|
157
167
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
158
168
|
sourceCommit: { message: 'message one (#1234)' },
|
|
159
|
-
sourcePullRequest: {
|
|
160
|
-
number: 1234,
|
|
161
|
-
},
|
|
169
|
+
sourcePullRequest: { number: 1234 },
|
|
162
170
|
timelineItems: [
|
|
163
171
|
{
|
|
164
172
|
state: 'MERGED',
|
|
@@ -168,8 +176,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
168
176
|
},
|
|
169
177
|
],
|
|
170
178
|
});
|
|
171
|
-
const
|
|
172
|
-
|
|
179
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
180
|
+
sourceCommit: mockSourceCommit,
|
|
181
|
+
latestBranchLabelMapping: {},
|
|
182
|
+
});
|
|
173
183
|
expect(expectedTargetPullRequests).toEqual([
|
|
174
184
|
{
|
|
175
185
|
branch: '6.x',
|
|
@@ -196,7 +206,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
196
206
|
'v8.0.0': 'master',
|
|
197
207
|
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
198
208
|
};
|
|
199
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
209
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
210
|
+
sourceCommit: mockSourceCommit,
|
|
211
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
212
|
+
});
|
|
200
213
|
expect(expectedTargetPullRequests).toEqual([
|
|
201
214
|
{ branch: '7.2', state: 'MISSING' },
|
|
202
215
|
{ branch: '7.1', state: 'MISSING' },
|
|
@@ -223,7 +236,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
223
236
|
'v8.0.0': 'master',
|
|
224
237
|
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
225
238
|
};
|
|
226
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
239
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
240
|
+
sourceCommit: mockSourceCommit,
|
|
241
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
242
|
+
});
|
|
227
243
|
expect(expectedTargetPullRequests).toEqual([
|
|
228
244
|
{
|
|
229
245
|
branch: '7.2',
|
|
@@ -275,7 +291,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
275
291
|
],
|
|
276
292
|
},
|
|
277
293
|
});
|
|
278
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
294
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
295
|
+
sourceCommit: mockSourceCommit,
|
|
296
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
297
|
+
});
|
|
279
298
|
expect(expectedTargetPullRequests).toEqual([
|
|
280
299
|
{ branch: '5.4', state: 'MISSING' },
|
|
281
300
|
{ branch: '5.5', state: 'MISSING' },
|
|
@@ -312,7 +331,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
312
331
|
labels: ['backport-to-dev', 'backport-to-v3.1.0'],
|
|
313
332
|
},
|
|
314
333
|
});
|
|
315
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
334
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
335
|
+
sourceCommit: mockSourceCommit,
|
|
336
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
337
|
+
});
|
|
316
338
|
expect(expectedTargetPullRequests).toEqual([
|
|
317
339
|
{ branch: 'dev', state: 'MISSING' },
|
|
318
340
|
{ branch: 'v3.1.0', state: 'MISSING' },
|
|
@@ -330,7 +352,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
330
352
|
labels: ['label-2'],
|
|
331
353
|
},
|
|
332
354
|
});
|
|
333
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
355
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
356
|
+
sourceCommit: mockSourceCommit,
|
|
357
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
358
|
+
});
|
|
334
359
|
expect(expectedTargetPullRequests).toEqual([
|
|
335
360
|
{ branch: 'branch-b', state: 'MISSING' },
|
|
336
361
|
]);
|
|
@@ -354,7 +379,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
354
379
|
},
|
|
355
380
|
],
|
|
356
381
|
});
|
|
357
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
382
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
383
|
+
sourceCommit: mockSourceCommit,
|
|
384
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
385
|
+
});
|
|
358
386
|
expect(expectedTargetPullRequests).toEqual([
|
|
359
387
|
{
|
|
360
388
|
branch: 'branch-3',
|
|
@@ -386,7 +414,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
386
414
|
},
|
|
387
415
|
],
|
|
388
416
|
});
|
|
389
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
417
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
418
|
+
sourceCommit: mockSourceCommit,
|
|
419
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
420
|
+
});
|
|
390
421
|
expect(expectedTargetPullRequests).toEqual([
|
|
391
422
|
{ branch: 'branch-1', state: 'MISSING' },
|
|
392
423
|
{ branch: 'branch-2', state: 'MISSING' },
|
|
@@ -413,7 +444,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
413
444
|
},
|
|
414
445
|
],
|
|
415
446
|
});
|
|
416
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(
|
|
447
|
+
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
448
|
+
sourceCommit: mockSourceCommit,
|
|
449
|
+
latestBranchLabelMapping: branchLabelMapping,
|
|
450
|
+
});
|
|
417
451
|
expect(expectedTargetPullRequests).toEqual([
|
|
418
452
|
{
|
|
419
453
|
branch: 'branch-3',
|
|
@@ -5,24 +5,6 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
|
|
|
5
5
|
const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
|
|
6
6
|
const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
|
|
7
7
|
const baseMockCommit = {
|
|
8
|
-
remoteConfigHistory: sourceCommit.remoteConfig
|
|
9
|
-
? {
|
|
10
|
-
edges: [
|
|
11
|
-
{
|
|
12
|
-
remoteConfig: {
|
|
13
|
-
committedDate: sourceCommit.remoteConfig.committedDate,
|
|
14
|
-
file: {
|
|
15
|
-
object: {
|
|
16
|
-
text: JSON.stringify({
|
|
17
|
-
branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
|
|
18
|
-
}),
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
}
|
|
25
|
-
: { edges: [] },
|
|
26
8
|
repository: {
|
|
27
9
|
name: 'kibana',
|
|
28
10
|
owner: { login: 'elastic' },
|
|
@@ -35,6 +17,24 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
|
|
|
35
17
|
if (!sourcePullRequest) {
|
|
36
18
|
return baseMockCommit;
|
|
37
19
|
}
|
|
20
|
+
const remoteConfigHistory = sourceCommit.remoteConfig
|
|
21
|
+
? {
|
|
22
|
+
edges: [
|
|
23
|
+
{
|
|
24
|
+
remoteConfig: {
|
|
25
|
+
committedDate: sourceCommit.remoteConfig.committedDate,
|
|
26
|
+
file: {
|
|
27
|
+
object: {
|
|
28
|
+
text: JSON.stringify({
|
|
29
|
+
branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
: { edges: [] };
|
|
38
38
|
return {
|
|
39
39
|
...baseMockCommit,
|
|
40
40
|
associatedPullRequests: {
|
|
@@ -42,6 +42,7 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
|
|
|
42
42
|
{
|
|
43
43
|
node: {
|
|
44
44
|
mergeCommit: {
|
|
45
|
+
remoteConfigHistory,
|
|
45
46
|
sha: sourceCommit.sha ?? defaultSourceCommitSha,
|
|
46
47
|
message: sourceCommit.message,
|
|
47
48
|
},
|
|
@@ -28,6 +28,7 @@ export interface SourcePullRequestNode {
|
|
|
28
28
|
}[];
|
|
29
29
|
};
|
|
30
30
|
mergeCommit: {
|
|
31
|
+
remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
|
|
31
32
|
sha: string;
|
|
32
33
|
message: string;
|
|
33
34
|
};
|
|
@@ -76,7 +77,6 @@ interface TimelineIssueEdge {
|
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
export declare type SourceCommitWithTargetPullRequest = {
|
|
79
|
-
remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
|
|
80
80
|
repository: {
|
|
81
81
|
name: string;
|
|
82
82
|
owner: {
|
|
@@ -99,5 +99,5 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
|
|
|
99
99
|
sourceBranch: string;
|
|
100
100
|
};
|
|
101
101
|
}): Commit;
|
|
102
|
-
export declare const
|
|
102
|
+
export declare const SourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
|
|
103
103
|
export {};
|
|
@@ -3,20 +3,12 @@ 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.
|
|
6
|
+
exports.SourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const remoteConfig_1 = require("../remoteConfig");
|
|
9
9
|
const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
|
|
10
10
|
function parseSourceCommit({ sourceCommit, options, }) {
|
|
11
11
|
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
12
|
-
// use info from associated pull request if available. Fall back to commit info
|
|
13
|
-
const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
|
|
14
|
-
const remoteConfig = sourceCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
|
|
15
|
-
const branchLabelMapping = remoteConfig
|
|
16
|
-
? (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping ??
|
|
17
|
-
options.branchLabelMapping
|
|
18
|
-
: options.branchLabelMapping;
|
|
19
|
-
const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(sourceCommit, branchLabelMapping);
|
|
20
12
|
return {
|
|
21
13
|
sourceCommit: {
|
|
22
14
|
committedDate: sourceCommit.committedDate,
|
|
@@ -33,15 +25,16 @@ function parseSourceCommit({ sourceCommit, options, }) {
|
|
|
33
25
|
},
|
|
34
26
|
}
|
|
35
27
|
: undefined,
|
|
36
|
-
sourceBranch,
|
|
37
|
-
expectedTargetPullRequests,
|
|
28
|
+
sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
|
|
29
|
+
expectedTargetPullRequests: (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
|
|
30
|
+
sourceCommit,
|
|
31
|
+
latestBranchLabelMapping: options.branchLabelMapping,
|
|
32
|
+
}),
|
|
38
33
|
};
|
|
39
34
|
}
|
|
40
35
|
exports.parseSourceCommit = parseSourceCommit;
|
|
41
|
-
exports.
|
|
42
|
-
fragment
|
|
43
|
-
...RemoteConfigHistory
|
|
44
|
-
|
|
36
|
+
exports.SourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
|
|
37
|
+
fragment SourceCommitWithTargetPullRequestFragment on Commit {
|
|
45
38
|
# Source Commit
|
|
46
39
|
repository {
|
|
47
40
|
name
|
|
@@ -68,6 +61,7 @@ exports.sourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
|
|
|
68
61
|
|
|
69
62
|
# source merge commit (the commit that actually went into the source branch)
|
|
70
63
|
mergeCommit {
|
|
64
|
+
...RemoteConfigHistoryFragment
|
|
71
65
|
sha: oid
|
|
72
66
|
message
|
|
73
67
|
}
|
|
File without changes
|
|
@@ -25,28 +25,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
const child_process_1 = require("child_process");
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
28
|
-
const child_process_promisified_1 = require("
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const TIMEOUT_IN_SECONDS =
|
|
33
|
-
jest.setTimeout(
|
|
28
|
+
const child_process_promisified_1 = require("../../services/child-process-promisified");
|
|
29
|
+
const packageVersion = __importStar(require("../../utils/packageVersion"));
|
|
30
|
+
const getDevAccessToken_1 = require("../private/getDevAccessToken");
|
|
31
|
+
const sandbox_1 = require("../sandbox");
|
|
32
|
+
const TIMEOUT_IN_SECONDS = 15;
|
|
33
|
+
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
|
|
34
34
|
const devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
35
35
|
describe('inquirer cli', () => {
|
|
36
36
|
it('--version', async () => {
|
|
37
|
-
const res = await
|
|
38
|
-
|
|
37
|
+
const res = await runBackportViaCli([`--version`], {
|
|
38
|
+
showLoadingSpinner: true,
|
|
39
|
+
});
|
|
40
|
+
expect(res).toEqual(process.env.npm_package_version);
|
|
39
41
|
});
|
|
40
42
|
it('-v', async () => {
|
|
41
|
-
const res = await
|
|
42
|
-
|
|
43
|
+
const res = await runBackportViaCli([`-v`], {
|
|
44
|
+
showLoadingSpinner: true,
|
|
45
|
+
});
|
|
46
|
+
expect(res).toEqual(process.env.npm_package_version);
|
|
43
47
|
});
|
|
44
48
|
it('PACKAGE_VERSION should match', async () => {
|
|
45
49
|
// @ts-expect-error
|
|
46
50
|
expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
|
|
47
51
|
});
|
|
48
52
|
it('--help', async () => {
|
|
49
|
-
const res = await
|
|
53
|
+
const res = await runBackportViaCli([`--help`]);
|
|
50
54
|
expect(res).toMatchInlineSnapshot(`
|
|
51
55
|
"entrypoint.cli.ts [args]
|
|
52
56
|
Options:
|
|
@@ -67,6 +71,7 @@ describe('inquirer cli', () => {
|
|
|
67
71
|
--dir Location where the temporary repository will be stored
|
|
68
72
|
[string]
|
|
69
73
|
--details Show details about each commit [boolean]
|
|
74
|
+
--dryRun Run backport locally without pushing to Github [boolean]
|
|
70
75
|
--editor Editor to be opened during conflict resolution [string]
|
|
71
76
|
--skipRemoteConfig Use local .backportrc.json config instead of loading from
|
|
72
77
|
Github [boolean]
|
|
@@ -109,7 +114,7 @@ describe('inquirer cli', () => {
|
|
|
109
114
|
`);
|
|
110
115
|
});
|
|
111
116
|
it('should return error when branch is missing', async () => {
|
|
112
|
-
const res = await
|
|
117
|
+
const res = await runBackportViaCli([
|
|
113
118
|
'--skip-remote-config',
|
|
114
119
|
'--repo-owner',
|
|
115
120
|
'backport-org',
|
|
@@ -128,7 +133,7 @@ describe('inquirer cli', () => {
|
|
|
128
133
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
129
134
|
await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
|
|
130
135
|
await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
|
|
131
|
-
const res = await
|
|
136
|
+
const res = await runBackportViaCli(['--accessToken', devAccessToken], {
|
|
132
137
|
cwd: sandboxPath,
|
|
133
138
|
waitForString: 'Select commit',
|
|
134
139
|
});
|
|
@@ -147,7 +152,7 @@ describe('inquirer cli', () => {
|
|
|
147
152
|
`);
|
|
148
153
|
});
|
|
149
154
|
it('should return error when access token is invalid', async () => {
|
|
150
|
-
const res = await
|
|
155
|
+
const res = await runBackportViaCli([
|
|
151
156
|
'--branch',
|
|
152
157
|
'foo',
|
|
153
158
|
'--repo-owner',
|
|
@@ -160,7 +165,7 @@ describe('inquirer cli', () => {
|
|
|
160
165
|
expect(res).toContain('Please check your access token and make sure it is valid');
|
|
161
166
|
});
|
|
162
167
|
it(`should return error when repo doesn't exist`, async () => {
|
|
163
|
-
const res = await
|
|
168
|
+
const res = await runBackportViaCli([
|
|
164
169
|
'--branch',
|
|
165
170
|
'foo',
|
|
166
171
|
'--repo-owner',
|
|
@@ -175,8 +180,7 @@ describe('inquirer cli', () => {
|
|
|
175
180
|
expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
176
181
|
});
|
|
177
182
|
it(`should list commits from master`, async () => {
|
|
178
|
-
|
|
179
|
-
const output = await runBackportAsync([
|
|
183
|
+
const output = await runBackportViaCli([
|
|
180
184
|
'--branch',
|
|
181
185
|
'foo',
|
|
182
186
|
'--repo-owner',
|
|
@@ -201,8 +205,7 @@ describe('inquirer cli', () => {
|
|
|
201
205
|
`);
|
|
202
206
|
});
|
|
203
207
|
it(`should filter commits by "since" and "until"`, async () => {
|
|
204
|
-
|
|
205
|
-
const output = await runBackportAsync([
|
|
208
|
+
const output = await runBackportViaCli([
|
|
206
209
|
'--branch',
|
|
207
210
|
'foo',
|
|
208
211
|
'--repo-owner',
|
|
@@ -225,7 +228,7 @@ describe('inquirer cli', () => {
|
|
|
225
228
|
`);
|
|
226
229
|
});
|
|
227
230
|
it(`should list commits from 7.x`, async () => {
|
|
228
|
-
const output = await
|
|
231
|
+
const output = await runBackportViaCli([
|
|
229
232
|
'--branch',
|
|
230
233
|
'foo',
|
|
231
234
|
'--repo-owner',
|
|
@@ -253,7 +256,7 @@ describe('inquirer cli', () => {
|
|
|
253
256
|
});
|
|
254
257
|
describe('repo: repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
|
|
255
258
|
it('should list commits', async () => {
|
|
256
|
-
const output = await
|
|
259
|
+
const output = await runBackportViaCli([
|
|
257
260
|
'--branch',
|
|
258
261
|
'foo',
|
|
259
262
|
'--repo',
|
|
@@ -273,7 +276,7 @@ describe('inquirer cli', () => {
|
|
|
273
276
|
`);
|
|
274
277
|
});
|
|
275
278
|
it('should attempt to backport by PR', async () => {
|
|
276
|
-
const output = await
|
|
279
|
+
const output = await runBackportViaCli([
|
|
277
280
|
'--branch',
|
|
278
281
|
'foo',
|
|
279
282
|
'--repo',
|
|
@@ -290,7 +293,7 @@ describe('inquirer cli', () => {
|
|
|
290
293
|
`);
|
|
291
294
|
});
|
|
292
295
|
it('should attempt to backport by commit sha', async () => {
|
|
293
|
-
const output = await
|
|
296
|
+
const output = await runBackportViaCli([
|
|
294
297
|
'--branch',
|
|
295
298
|
'foo',
|
|
296
299
|
'--repo',
|
|
@@ -299,18 +302,16 @@ describe('inquirer cli', () => {
|
|
|
299
302
|
'be59df6912a550c8cb49ba3e18be3e512f3d608c',
|
|
300
303
|
'--accessToken',
|
|
301
304
|
devAccessToken,
|
|
302
|
-
], { waitForString:
|
|
305
|
+
], { waitForString: `Backporting to foo:` });
|
|
303
306
|
expect(output).toMatchInlineSnapshot(`
|
|
304
307
|
"
|
|
305
|
-
Backporting to foo:
|
|
306
|
-
The branch \\"foo\\" is invalid or doesn't exist"
|
|
308
|
+
Backporting to foo:"
|
|
307
309
|
`);
|
|
308
310
|
});
|
|
309
311
|
});
|
|
310
312
|
describe('repo: different-merge-strategies', () => {
|
|
311
313
|
it('list all commits regardless how they were merged', async () => {
|
|
312
|
-
|
|
313
|
-
const output = await runBackportAsync([
|
|
314
|
+
const output = await runBackportViaCli([
|
|
314
315
|
'--branch',
|
|
315
316
|
'foo',
|
|
316
317
|
'--repo-owner',
|
|
@@ -343,8 +344,52 @@ describe('inquirer cli', () => {
|
|
|
343
344
|
`);
|
|
344
345
|
});
|
|
345
346
|
});
|
|
347
|
+
describe('repo: test-that-repo-can-be-cloned', () => {
|
|
348
|
+
let sandboxPath;
|
|
349
|
+
beforeAll(async () => {
|
|
350
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
351
|
+
filename: __filename,
|
|
352
|
+
specname: 'test-cloning',
|
|
353
|
+
});
|
|
354
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
355
|
+
});
|
|
356
|
+
function run() {
|
|
357
|
+
return runBackportViaCli([
|
|
358
|
+
'--repo',
|
|
359
|
+
'backport-org/test-that-repo-can-be-cloned',
|
|
360
|
+
'--branch',
|
|
361
|
+
'foo',
|
|
362
|
+
'--pr',
|
|
363
|
+
'1',
|
|
364
|
+
'--dir',
|
|
365
|
+
sandboxPath,
|
|
366
|
+
'--dry-run',
|
|
367
|
+
'--accessToken',
|
|
368
|
+
devAccessToken,
|
|
369
|
+
], { showLoadingSpinner: true, waitForString: 'Backporting to foo:' });
|
|
370
|
+
}
|
|
371
|
+
it('clones the repo on the very first run', async () => {
|
|
372
|
+
const output = await run();
|
|
373
|
+
expect(output).toContain('Cloning repository from github.com');
|
|
374
|
+
expect(output).toMatchInlineSnapshot(`
|
|
375
|
+
"- Initializing...
|
|
376
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
377
|
+
✔ 100% Cloning repository from github.com (one-time operation)
|
|
378
|
+
Backporting to foo:"
|
|
379
|
+
`);
|
|
380
|
+
});
|
|
381
|
+
it('does not clone the repo on subsequent runs', async () => {
|
|
382
|
+
const output = await run();
|
|
383
|
+
expect(output).not.toContain('Cloning repository from github.com');
|
|
384
|
+
expect(output).toMatchInlineSnapshot(`
|
|
385
|
+
"- Initializing...
|
|
386
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
387
|
+
Backporting to foo:"
|
|
388
|
+
`);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
346
391
|
});
|
|
347
|
-
function
|
|
392
|
+
function runBackportViaCli(cliArgs, { showLoadingSpinner, waitForString, cwd, } = {}) {
|
|
348
393
|
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
349
394
|
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
350
395
|
const proc = (0, child_process_1.spawn)(tsNodeBinary, [
|
|
@@ -363,20 +408,22 @@ function runBackportAsync(cliArgs, { waitForString, cwd, } = {}) {
|
|
|
363
408
|
}, TIMEOUT_IN_SECONDS * 1000);
|
|
364
409
|
proc.stdout.on('data', (chunk) => {
|
|
365
410
|
data += chunk;
|
|
366
|
-
const
|
|
411
|
+
const rawOutput = data.toString();
|
|
412
|
+
// remove ansi codes and whitespace
|
|
413
|
+
const output = (0, strip_ansi_1.default)(rawOutput).replace(/\s+$/gm, '');
|
|
367
414
|
if (!waitForString || output.includes(waitForString)) {
|
|
368
415
|
clearTimeout(timeout);
|
|
369
|
-
|
|
370
|
-
const strippedOutput = (0, strip_ansi_1.default)(output).replace(/\s+$/gm, '');
|
|
371
|
-
resolve(strippedOutput);
|
|
416
|
+
resolve(output);
|
|
372
417
|
}
|
|
373
418
|
});
|
|
374
|
-
//
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
419
|
+
// ora (loading spinner) is redirected to stderr
|
|
420
|
+
if (showLoadingSpinner) {
|
|
421
|
+
proc.stderr.on('data', (chunk) => {
|
|
422
|
+
data += chunk;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
378
425
|
proc.on('error', (err) => {
|
|
379
|
-
reject(`
|
|
426
|
+
reject(`runBackportViaCli failed with: ${err}`);
|
|
380
427
|
});
|
|
381
428
|
});
|
|
382
429
|
// kill child process
|
|
File without changes
|