backport 6.1.3 → 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/dist/entrypoint.module.d.ts +2 -0
- package/dist/entrypoint.module.js +5 -1
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +1 -1
- package/dist/options/cliArgs.d.ts +2 -0
- package/dist/options/cliArgs.js +14 -1
- package/dist/options/config/globalConfig.js +1 -1
- package/dist/options/options.d.ts +4 -0
- package/dist/options/options.js +3 -1
- package/dist/options/options.test.js +3 -1
- package/dist/runSequentially.test.js +7 -5
- 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.test.js +3 -3
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +31 -11
- package/dist/services/github/v3/createStatusComment.test.js +139 -86
- 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/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 +20 -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/integration/integration.private.test.js +2 -2
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -4
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.js +17 -2
- package/package.json +3 -3
- package/yarn.lock +462 -284
|
@@ -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
|
});
|
|
@@ -78,7 +78,7 @@ describe('integration', () => {
|
|
|
78
78
|
"base": "7.x",
|
|
79
79
|
"body": "# Backport
|
|
80
80
|
|
|
81
|
-
This is an automatic backport to 7.x of:
|
|
81
|
+
This is an automatic backport to \`7.x\` of:
|
|
82
82
|
- Add ❤️ emoji (5bf29b7d)
|
|
83
83
|
|
|
84
84
|
### Questions ?
|
|
@@ -214,7 +214,7 @@ describe('integration', () => {
|
|
|
214
214
|
"base": "7.x",
|
|
215
215
|
"body": "# Backport
|
|
216
216
|
|
|
217
|
-
This is an automatic backport to 7.x of:
|
|
217
|
+
This is an automatic backport to \`7.x\` of:
|
|
218
218
|
- Add ❤️ emoji (5bf29b7d)
|
|
219
219
|
|
|
220
220
|
### Questions ?
|
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
|
}
|
|
@@ -103,13 +103,14 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
103
103
|
exports.getBackportBranchName = getBackportBranchName;
|
|
104
104
|
async function waitForCherrypick(options, commit, targetBranch) {
|
|
105
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);
|
|
106
107
|
const cherrypickSpinner = ora(spinnerText).start();
|
|
107
108
|
let conflictingFiles;
|
|
108
109
|
let unstagedFiles;
|
|
109
110
|
let needsResolving;
|
|
110
111
|
try {
|
|
111
112
|
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
112
|
-
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
|
|
113
|
+
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha, mergedTargetPullRequest));
|
|
113
114
|
// no conflicts encountered
|
|
114
115
|
if (!needsResolving) {
|
|
115
116
|
cherrypickSpinner.succeed();
|
|
@@ -147,7 +148,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
147
148
|
});
|
|
148
149
|
if (options.ci) {
|
|
149
150
|
throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
|
|
150
|
-
type: '
|
|
151
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
151
152
|
commitsWithoutBackports,
|
|
152
153
|
});
|
|
153
154
|
}
|
|
@@ -110,7 +110,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
110
110
|
"base": "6.x",
|
|
111
111
|
"body": "# Backport
|
|
112
112
|
|
|
113
|
-
This is an automatic backport to 6.x of:
|
|
113
|
+
This is an automatic backport to \`6.x\` of:
|
|
114
114
|
- #1000
|
|
115
115
|
- #2000
|
|
116
116
|
|
|
@@ -197,7 +197,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
197
197
|
"base": "6.x",
|
|
198
198
|
"body": "# Backport
|
|
199
199
|
|
|
200
|
-
This is an automatic backport to 6.x of:
|
|
200
|
+
This is an automatic backport to \`6.x\` of:
|
|
201
201
|
- My original commit message (mySha)
|
|
202
202
|
|
|
203
203
|
### Questions ?
|
|
@@ -251,7 +251,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
251
251
|
options,
|
|
252
252
|
commits: [
|
|
253
253
|
{
|
|
254
|
-
committedDate: '
|
|
254
|
+
committedDate: '2021-08-18T16:11:38Z',
|
|
255
255
|
sourceBranch: '7.x',
|
|
256
256
|
sha: 'mySha',
|
|
257
257
|
originalMessage: 'My original commit message',
|
|
@@ -270,7 +270,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
270
270
|
"base": "6.x",
|
|
271
271
|
"body": "# Backport
|
|
272
272
|
|
|
273
|
-
This is an automatic backport to 6.x of:
|
|
273
|
+
This is an automatic backport to \`6.x\` of:
|
|
274
274
|
- My original commit message (mySha)
|
|
275
275
|
|
|
276
276
|
### Questions ?
|
|
@@ -320,6 +320,8 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
320
320
|
Object {
|
|
321
321
|
"authorId": null,
|
|
322
322
|
"commitPath": "conflicting-file.txt",
|
|
323
|
+
"dateSince": null,
|
|
324
|
+
"dateUntil": "2021-08-18T16:11:38Z",
|
|
323
325
|
"maxNumber": 10,
|
|
324
326
|
"repoName": "kibana",
|
|
325
327
|
"repoOwner": "elastic",
|
package/dist/ui/getCommits.js
CHANGED
|
@@ -35,7 +35,7 @@ async function getCommits(options) {
|
|
|
35
35
|
pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
|
|
36
36
|
});
|
|
37
37
|
// add styles to make it look like a prompt question
|
|
38
|
-
spinner.stopAndPersist(getOraPersistsOption('Select pull request', commit.originalMessage));
|
|
38
|
+
spinner.stopAndPersist(getOraPersistsOption('Select pull request', (0, commitFormatters_1.getFirstLine)(commit.originalMessage)));
|
|
39
39
|
return [commit];
|
|
40
40
|
}
|
|
41
41
|
if (options.ci) {
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCommitsWithoutBackports = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const git_1 = require("../services/git");
|
|
8
9
|
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
9
10
|
const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
10
11
|
// when the user is facing a git conflict we should help them understand
|
|
@@ -20,9 +21,11 @@ conflictingFiles, }) {
|
|
|
20
21
|
const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
21
22
|
...options,
|
|
22
23
|
author: null,
|
|
24
|
+
dateSince: null,
|
|
25
|
+
dateUntil: commit.committedDate,
|
|
23
26
|
commitPaths: conflictingFiles,
|
|
24
27
|
});
|
|
25
|
-
|
|
28
|
+
const promises = await Promise.all(commitsInConflictingPaths
|
|
26
29
|
.filter((c) => {
|
|
27
30
|
// exclude the commit we are currently trying to backport
|
|
28
31
|
if (c.sha === commit.sha) {
|
|
@@ -41,7 +44,19 @@ conflictingFiles, }) {
|
|
|
41
44
|
return hasUnmergedPr;
|
|
42
45
|
})
|
|
43
46
|
.slice(0, 10) // limit to max 10 commits
|
|
44
|
-
.map((c) => {
|
|
47
|
+
.map(async (c) => {
|
|
48
|
+
const results = await Promise.all(c.expectedTargetPullRequests.map(async (targetPr) => {
|
|
49
|
+
if (!targetPr.mergeCommit) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return (0, git_1.getIsCommitInBranch)(options, targetPr.mergeCommit.sha);
|
|
53
|
+
}));
|
|
54
|
+
const isCommitInBranch = results.some((inBranch) => inBranch === true);
|
|
55
|
+
return { c, isCommitInBranch };
|
|
56
|
+
}));
|
|
57
|
+
return promises
|
|
58
|
+
.filter(({ isCommitInBranch }) => !isCommitInBranch)
|
|
59
|
+
.map(({ c }) => {
|
|
45
60
|
// get pull request for the target branch (if it exists)
|
|
46
61
|
const pendingBackportPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
|
|
47
62
|
const formatted = pendingBackportPr
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"branches",
|
|
15
15
|
"branching"
|
|
16
16
|
],
|
|
17
|
-
"version": "6.1.
|
|
17
|
+
"version": "6.1.4",
|
|
18
18
|
"main": "./dist/entrypoint.module.js",
|
|
19
19
|
"types": "dist/entrypoint.module.d.ts",
|
|
20
20
|
"bin": {
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"graphql-config": "^4.1.0",
|
|
96
96
|
"graphql-tag": "^2.12.6",
|
|
97
97
|
"husky": "^7.0.4",
|
|
98
|
-
"jest": "^27.4.
|
|
98
|
+
"jest": "^27.4.7",
|
|
99
99
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
100
|
-
"lint-staged": "^12.1.
|
|
100
|
+
"lint-staged": "^12.1.7",
|
|
101
101
|
"nock": "^13.2.1",
|
|
102
102
|
"prettier": "^2.5.1",
|
|
103
103
|
"strip-ansi": "^6.0.1",
|