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
|
@@ -9,7 +9,7 @@ export interface Commit {
|
|
|
9
9
|
pullUrl?: string;
|
|
10
10
|
expectedTargetPullRequests: ExpectedTargetPullRequest[];
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface SourcePullRequestNode {
|
|
13
13
|
baseRefName: string;
|
|
14
14
|
url: string;
|
|
15
15
|
number: number;
|
|
@@ -18,8 +18,12 @@ export interface PullRequestNode {
|
|
|
18
18
|
name: string;
|
|
19
19
|
}[];
|
|
20
20
|
};
|
|
21
|
+
sourceMergeCommit: {
|
|
22
|
+
oid: string;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
21
25
|
timelineItems: {
|
|
22
|
-
edges:
|
|
26
|
+
edges: TimelineEdge[];
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
export declare type TimelineEdge = TimelinePullRequestEdge | TimelineIssueEdge;
|
|
@@ -32,10 +36,23 @@ export interface TimelinePullRequestEdge {
|
|
|
32
36
|
state: 'OPEN' | 'CLOSED' | 'MERGED';
|
|
33
37
|
baseRefName: string;
|
|
34
38
|
number: number;
|
|
39
|
+
targetMergeCommit: {
|
|
40
|
+
oid: string;
|
|
41
|
+
message: string;
|
|
42
|
+
} | null;
|
|
43
|
+
repository: {
|
|
44
|
+
name: string;
|
|
45
|
+
owner: {
|
|
46
|
+
login: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
35
49
|
commits: {
|
|
36
50
|
edges: Array<{
|
|
37
51
|
node: {
|
|
38
|
-
targetCommit:
|
|
52
|
+
targetCommit: {
|
|
53
|
+
message: string;
|
|
54
|
+
oid: string;
|
|
55
|
+
};
|
|
39
56
|
};
|
|
40
57
|
}>;
|
|
41
58
|
};
|
|
@@ -49,7 +66,7 @@ interface TimelineIssueEdge {
|
|
|
49
66
|
};
|
|
50
67
|
};
|
|
51
68
|
}
|
|
52
|
-
declare type
|
|
69
|
+
export declare type SourceCommitWithTargetPullRequest = {
|
|
53
70
|
repository: {
|
|
54
71
|
name: string;
|
|
55
72
|
owner: {
|
|
@@ -59,11 +76,9 @@ declare type InnerCommitNode = {
|
|
|
59
76
|
oid: string;
|
|
60
77
|
message: string;
|
|
61
78
|
committedDate: string;
|
|
62
|
-
};
|
|
63
|
-
export declare type SourceCommitWithTargetPullRequest = InnerCommitNode & {
|
|
64
79
|
associatedPullRequests: {
|
|
65
80
|
edges: {
|
|
66
|
-
node:
|
|
81
|
+
node: SourcePullRequestNode;
|
|
67
82
|
}[] | null;
|
|
68
83
|
};
|
|
69
84
|
};
|
|
@@ -76,7 +91,6 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
|
|
|
76
91
|
};
|
|
77
92
|
}): Commit;
|
|
78
93
|
export declare const sourceCommitWithTargetPullRequestFragment: {
|
|
79
|
-
name: string;
|
|
80
94
|
source: string;
|
|
81
95
|
};
|
|
82
96
|
export {};
|
|
@@ -6,7 +6,9 @@ const commitFormatters_1 = require("../github/commitFormatters");
|
|
|
6
6
|
const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
|
|
7
7
|
function parseSourceCommit({ sourceCommit, options, }) {
|
|
8
8
|
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
9
|
-
|
|
9
|
+
// use info from associated pull request if available. Fall back to commit info
|
|
10
|
+
const commitMessage = sourcePullRequest?.sourceMergeCommit.message ?? sourceCommit.message;
|
|
11
|
+
const commitSha = sourcePullRequest?.sourceMergeCommit.oid ?? sourceCommit.oid;
|
|
10
12
|
const pullNumber = sourcePullRequest?.number ?? (0, commitFormatters_1.extractPullNumber)(commitMessage);
|
|
11
13
|
const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
|
|
12
14
|
const branchLabelMapping = getBranchLabelMappingForCommit(sourceCommit, options.branchLabelMapping, options.historicalBranchLabelMappings);
|
|
@@ -14,7 +16,7 @@ function parseSourceCommit({ sourceCommit, options, }) {
|
|
|
14
16
|
return {
|
|
15
17
|
committedDate: sourceCommit.committedDate,
|
|
16
18
|
sourceBranch,
|
|
17
|
-
sha:
|
|
19
|
+
sha: commitSha,
|
|
18
20
|
originalMessage: commitMessage,
|
|
19
21
|
pullNumber,
|
|
20
22
|
pullUrl: sourcePullRequest?.url,
|
|
@@ -23,9 +25,9 @@ function parseSourceCommit({ sourceCommit, options, }) {
|
|
|
23
25
|
}
|
|
24
26
|
exports.parseSourceCommit = parseSourceCommit;
|
|
25
27
|
exports.sourceCommitWithTargetPullRequestFragment = {
|
|
26
|
-
name: 'SourceCommitWithTargetPullRequest',
|
|
27
28
|
source: /* GraphQL */ `
|
|
28
|
-
fragment
|
|
29
|
+
fragment SourceCommitWithTargetPullRequest on Commit {
|
|
30
|
+
# Source Commit
|
|
29
31
|
repository {
|
|
30
32
|
name
|
|
31
33
|
owner {
|
|
@@ -35,14 +37,11 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
35
37
|
oid
|
|
36
38
|
message
|
|
37
39
|
committedDate
|
|
38
|
-
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
...InnerCommitNode
|
|
41
|
+
# Source pull request: PR where source commit was merged in
|
|
42
42
|
associatedPullRequests(first: 1) {
|
|
43
43
|
edges {
|
|
44
44
|
node {
|
|
45
|
-
# Source PR
|
|
46
45
|
url
|
|
47
46
|
number
|
|
48
47
|
labels(first: 50) {
|
|
@@ -51,6 +50,14 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
baseRefName
|
|
53
|
+
|
|
54
|
+
# source merge commit (the commit that actually went into the source branch)
|
|
55
|
+
sourceMergeCommit: mergeCommit {
|
|
56
|
+
oid
|
|
57
|
+
message
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# (possible) backport pull requests referenced in the source pull request
|
|
54
61
|
timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
|
|
55
62
|
edges {
|
|
56
63
|
node {
|
|
@@ -58,8 +65,19 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
58
65
|
targetPullRequest: source {
|
|
59
66
|
__typename
|
|
60
67
|
|
|
61
|
-
# Target PRs
|
|
68
|
+
# Target PRs (backport PRs)
|
|
62
69
|
... on PullRequest {
|
|
70
|
+
# target merge commit: the backport commit that was merged into the target branch
|
|
71
|
+
targetMergeCommit: mergeCommit {
|
|
72
|
+
oid
|
|
73
|
+
message
|
|
74
|
+
}
|
|
75
|
+
repository {
|
|
76
|
+
name
|
|
77
|
+
owner {
|
|
78
|
+
login
|
|
79
|
+
}
|
|
80
|
+
}
|
|
63
81
|
url
|
|
64
82
|
title
|
|
65
83
|
state
|
|
@@ -69,7 +87,8 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
69
87
|
edges {
|
|
70
88
|
node {
|
|
71
89
|
targetCommit: commit {
|
|
72
|
-
|
|
90
|
+
message
|
|
91
|
+
oid
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
@@ -96,6 +96,10 @@ describe('parseSourceCommit', () => {
|
|
|
96
96
|
number: 5678,
|
|
97
97
|
state: 'MERGED',
|
|
98
98
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
99
|
+
mergeCommit: {
|
|
100
|
+
message: 'My commit message (#66)',
|
|
101
|
+
sha: 'target-merge-commit-sha',
|
|
102
|
+
},
|
|
99
103
|
},
|
|
100
104
|
{
|
|
101
105
|
branch: '6.2',
|
|
@@ -170,7 +174,7 @@ describe('parseSourceCommit', () => {
|
|
|
170
174
|
});
|
|
171
175
|
it('returns the correct source commit', () => {
|
|
172
176
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
173
|
-
sourceCommit: { message: 'My commit message (#1234)' },
|
|
177
|
+
sourceCommit: { message: 'My commit message (#1234)', sha: 'my-sha' },
|
|
174
178
|
sourcePullRequest: {
|
|
175
179
|
number: 1234,
|
|
176
180
|
labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
|
|
@@ -207,6 +211,10 @@ describe('parseSourceCommit', () => {
|
|
|
207
211
|
number: 5678,
|
|
208
212
|
state: 'MERGED',
|
|
209
213
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
214
|
+
mergeCommit: {
|
|
215
|
+
message: 'My commit message (#1234)',
|
|
216
|
+
sha: 'target-merge-commit-sha',
|
|
217
|
+
},
|
|
210
218
|
},
|
|
211
219
|
{
|
|
212
220
|
branch: '6.2',
|
|
@@ -222,7 +230,7 @@ describe('parseSourceCommit', () => {
|
|
|
222
230
|
originalMessage: 'My commit message (#1234)',
|
|
223
231
|
pullNumber: 1234,
|
|
224
232
|
pullUrl: 'https://github.com/elastic/kibana/pull/1234',
|
|
225
|
-
sha: '
|
|
233
|
+
sha: 'my-sha',
|
|
226
234
|
sourceBranch: 'source-branch-from-associated-pull-request',
|
|
227
235
|
});
|
|
228
236
|
});
|
|
@@ -38,7 +38,7 @@ describe('inquirer cli', () => {
|
|
|
38
38
|
]);
|
|
39
39
|
expect(res).toMatchInlineSnapshot(`
|
|
40
40
|
"Please specify a target branch: \\"--branch 6.1\\".
|
|
41
|
-
|
|
41
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
42
42
|
`);
|
|
43
43
|
});
|
|
44
44
|
it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
|
|
@@ -49,20 +49,9 @@ describe('inquirer cli', () => {
|
|
|
49
49
|
'--accessToken',
|
|
50
50
|
devAccessToken,
|
|
51
51
|
]);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
2. Bump dependencies
|
|
56
|
-
3. Add support for historical branch label mappings (#282)
|
|
57
|
-
4. Add status comment (#281)
|
|
58
|
-
5. Add \`--reviewer\` option (#280)
|
|
59
|
-
6. By default append \\"(cherry picked from commit...)\\" to commit message. Disab
|
|
60
|
-
le with \`--no-cherrypick-ref\` (#279)
|
|
61
|
-
7. Improve git unit tests (#278)
|
|
62
|
-
8. Add tests for \`getCommitsWithoutBackports\`
|
|
63
|
-
9. Add Details View and \`--details\` flag (#277)
|
|
64
|
-
10.Feature: Show hint about missing backports (#276)"
|
|
65
|
-
`);
|
|
52
|
+
const lineCount = res.split('\n').length;
|
|
53
|
+
expect(lineCount).toBe(11);
|
|
54
|
+
expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
|
|
66
55
|
});
|
|
67
56
|
it('should return error when access token is invalid', async () => {
|
|
68
57
|
const res = await runBackportAsync([
|
|
@@ -76,9 +76,14 @@ describe('integration', () => {
|
|
|
76
76
|
Array [
|
|
77
77
|
Object {
|
|
78
78
|
"base": "7.x",
|
|
79
|
-
"body": "
|
|
79
|
+
"body": "# Backport
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
This is an automatic backport to \`7.x\` of:
|
|
82
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
83
|
+
|
|
84
|
+
### Questions ?
|
|
85
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
86
|
+
",
|
|
82
87
|
"head": "sqren:backport/7.x/commit-5bf29b7d",
|
|
83
88
|
"title": "[7.x] Add ❤️ emoji",
|
|
84
89
|
},
|
|
@@ -207,9 +212,14 @@ describe('integration', () => {
|
|
|
207
212
|
Array [
|
|
208
213
|
Object {
|
|
209
214
|
"base": "7.x",
|
|
210
|
-
"body": "
|
|
215
|
+
"body": "# Backport
|
|
216
|
+
|
|
217
|
+
This is an automatic backport to \`7.x\` of:
|
|
218
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
211
219
|
|
|
212
|
-
|
|
220
|
+
### Questions ?
|
|
221
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
222
|
+
",
|
|
213
223
|
"head": "backport-org:backport/7.x/commit-5bf29b7d",
|
|
214
224
|
"title": "[7.x] Add ❤️ emoji",
|
|
215
225
|
},
|
package/dist/test/nockHelpers.js
CHANGED
|
@@ -18,9 +18,7 @@ function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.mockGqlRequest = mockGqlRequest;
|
|
20
20
|
function getGqlName(query) {
|
|
21
|
-
const obj = (0, graphql_tag_1.default)
|
|
22
|
-
${query}
|
|
23
|
-
`;
|
|
21
|
+
const obj = (0, graphql_tag_1.default)(query);
|
|
24
22
|
// @ts-expect-error
|
|
25
23
|
return obj.definitions[0].name.value;
|
|
26
24
|
}
|
|
@@ -111,11 +111,14 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
111
111
|
Array [
|
|
112
112
|
Object {
|
|
113
113
|
"base": "6.x",
|
|
114
|
-
"body": "
|
|
114
|
+
"body": "# Backport
|
|
115
|
+
|
|
116
|
+
This is an automatic backport to 6.x of:
|
|
115
117
|
- #1000
|
|
116
118
|
- #2000
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
### Questions ?
|
|
121
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
119
122
|
|
|
120
123
|
myPrSuffix",
|
|
121
124
|
"head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
|
|
@@ -195,9 +198,14 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
195
198
|
Array [
|
|
196
199
|
Object {
|
|
197
200
|
"base": "6.x",
|
|
198
|
-
"body": "
|
|
201
|
+
"body": "# Backport
|
|
202
|
+
|
|
203
|
+
This is an automatic backport to 6.x of:
|
|
204
|
+
- My original commit message (mySha)
|
|
199
205
|
|
|
200
|
-
|
|
206
|
+
### Questions ?
|
|
207
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
208
|
+
",
|
|
201
209
|
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
202
210
|
"title": "[6.x] My original commit message",
|
|
203
211
|
},
|
|
@@ -263,9 +271,14 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
263
271
|
Array [
|
|
264
272
|
Object {
|
|
265
273
|
"base": "6.x",
|
|
266
|
-
"body": "
|
|
274
|
+
"body": "# Backport
|
|
275
|
+
|
|
276
|
+
This is an automatic backport to 6.x of:
|
|
277
|
+
- My original commit message (mySha)
|
|
267
278
|
|
|
268
|
-
|
|
279
|
+
### Questions ?
|
|
280
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
281
|
+
",
|
|
269
282
|
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
270
283
|
"title": "[6.x] My original commit message",
|
|
271
284
|
},
|
|
@@ -9,13 +9,4 @@ export declare function cherrypickAndCreateTargetPullRequest({ options, commits,
|
|
|
9
9
|
number: number;
|
|
10
10
|
didUpdate: boolean;
|
|
11
11
|
}>;
|
|
12
|
-
export declare function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }: {
|
|
13
|
-
options: ValidConfigOptions;
|
|
14
|
-
commit: Commit;
|
|
15
|
-
targetBranch: string;
|
|
16
|
-
conflictingFiles: string[];
|
|
17
|
-
}): Promise<{
|
|
18
|
-
formatted: string;
|
|
19
|
-
commit: Commit;
|
|
20
|
-
}[]>;
|
|
21
12
|
export declare function getBackportBranchName(targetBranch: string, commits: Commit[]): string;
|
|
@@ -3,7 +3,7 @@ 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.getBackportBranchName = exports.
|
|
6
|
+
exports.getBackportBranchName = exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
9
|
const ora = require("ora");
|
|
@@ -17,10 +17,10 @@ const addLabelsToPullRequest_1 = require("../services/github/v3/addLabelsToPullR
|
|
|
17
17
|
const addReviewersToPullRequest_1 = require("../services/github/v3/addReviewersToPullRequest");
|
|
18
18
|
const createPullRequest_1 = require("../services/github/v3/createPullRequest");
|
|
19
19
|
const enablePullRequestAutoMerge_1 = require("../services/github/v4/enablePullRequestAutoMerge");
|
|
20
|
-
const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
21
20
|
const logger_1 = require("../services/logger");
|
|
22
21
|
const prompts_1 = require("../services/prompts");
|
|
23
22
|
const sequentially_1 = require("../services/sequentially");
|
|
23
|
+
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
24
24
|
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
|
|
25
25
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
26
26
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
@@ -83,44 +83,6 @@ async function backportViaFilesystem({ options, prPayload, commits, targetBranch
|
|
|
83
83
|
await (0, git_1.deleteBackportBranch)({ options, backportBranch });
|
|
84
84
|
return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
85
85
|
}
|
|
86
|
-
// when the user is facing a git conflict we should help them understand
|
|
87
|
-
// why the conflict occurs. In many cases it's because one or more commits haven't been backported yet
|
|
88
|
-
async function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }) {
|
|
89
|
-
const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
90
|
-
...options,
|
|
91
|
-
author: null,
|
|
92
|
-
commitPaths: conflictingFiles,
|
|
93
|
-
});
|
|
94
|
-
return (await Promise.all(commitsInConflictingPaths
|
|
95
|
-
.filter((c) => {
|
|
96
|
-
// exclude the commit we are currently trying to backport
|
|
97
|
-
if (c.sha === commit.sha) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
// exclude commits that are newer than the commit we are trying to backport
|
|
101
|
-
if (c.committedDate > commit.committedDate) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
const alreadyBackported = c.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state === 'MERGED');
|
|
105
|
-
if (alreadyBackported) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
109
|
-
})
|
|
110
|
-
.slice(0, 10) // limit to max 10 commits
|
|
111
|
-
.map(async (c) => {
|
|
112
|
-
const isCommitInBranch = await (0, git_1.getIsCommitInBranch)(options, c.sha);
|
|
113
|
-
return { c, isCommitInBranch };
|
|
114
|
-
})))
|
|
115
|
-
.filter(({ isCommitInBranch }) => !isCommitInBranch)
|
|
116
|
-
.map(({ c }) => {
|
|
117
|
-
// get pull request for the target branch (if it exists)
|
|
118
|
-
const unmergedPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch);
|
|
119
|
-
const formatted = ` - ${(0, commitFormatters_1.getFirstLine)(c.originalMessage)}${unmergedPr?.state === 'OPEN' ? chalk_1.default.gray(' (backport pending)') : ''}${c.pullUrl ? `\n ${c.pullUrl}` : ''}`;
|
|
120
|
-
return { formatted, commit: c };
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
|
|
124
86
|
/*
|
|
125
87
|
* Returns the name of the backport branch without remote name
|
|
126
88
|
*
|
|
@@ -141,13 +103,14 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
141
103
|
exports.getBackportBranchName = getBackportBranchName;
|
|
142
104
|
async function waitForCherrypick(options, commit, targetBranch) {
|
|
143
105
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.originalMessage))}`;
|
|
106
|
+
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
144
107
|
const cherrypickSpinner = ora(spinnerText).start();
|
|
145
108
|
let conflictingFiles;
|
|
146
109
|
let unstagedFiles;
|
|
147
110
|
let needsResolving;
|
|
148
111
|
try {
|
|
149
112
|
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
150
|
-
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
|
|
113
|
+
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha, mergedTargetPullRequest));
|
|
151
114
|
// no conflicts encountered
|
|
152
115
|
if (!needsResolving) {
|
|
153
116
|
cherrypickSpinner.succeed();
|
|
@@ -177,23 +140,23 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
177
140
|
}
|
|
178
141
|
autoResolveSpinner.fail();
|
|
179
142
|
}
|
|
180
|
-
const commitsWithoutBackports = await getCommitsWithoutBackports({
|
|
143
|
+
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
181
144
|
options,
|
|
182
145
|
commit,
|
|
183
146
|
targetBranch,
|
|
184
147
|
conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
|
|
185
148
|
});
|
|
186
|
-
(0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
|
|
187
|
-
if (commitsWithoutBackports.length > 0) {
|
|
188
|
-
(0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following commits to "${targetBranch}":`));
|
|
189
|
-
(0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
|
|
190
|
-
}
|
|
191
149
|
if (options.ci) {
|
|
192
150
|
throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
|
|
193
|
-
type: '
|
|
151
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
194
152
|
commitsWithoutBackports,
|
|
195
153
|
});
|
|
196
154
|
}
|
|
155
|
+
(0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
|
|
156
|
+
if (commitsWithoutBackports.length > 0) {
|
|
157
|
+
(0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following commits to "${targetBranch}":`));
|
|
158
|
+
(0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
|
|
159
|
+
}
|
|
197
160
|
/*
|
|
198
161
|
* Commit could not be cleanly cherrypicked: Initiating conflict resolution
|
|
199
162
|
*/
|