backport 7.4.0 → 8.0.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/README.md +12 -13
- package/dist/backportRun.d.ts +8 -3
- package/dist/backportRun.js +54 -42
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +8 -3
- package/dist/entrypoint.module.js +3 -11
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/options/cliArgs.d.ts +9 -4
- package/dist/options/cliArgs.js +28 -15
- package/dist/options/cliArgs.test.js +3 -3
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +13 -10
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -3
- package/dist/options/options.test.js +5 -1
- package/dist/runSequentially.d.ts +6 -2
- package/dist/runSequentially.js +23 -7
- package/dist/scripts/postinstall.js +1 -0
- package/dist/scripts/postinstall.test.js +5 -1
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/HandledError.js +2 -2
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +188 -122
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -124
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +3 -1
- package/dist/services/github/v3/createStatusComment.js +14 -15
- package/dist/services/github/v3/createStatusComment.test.js +15 -5
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +194 -12
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +26 -19
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +5 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +1 -1
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +414 -695
|
@@ -32,7 +32,7 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
return octokit.issues.createComment({
|
|
35
|
-
baseUrl:
|
|
35
|
+
baseUrl: githubApiBaseUrlV3,
|
|
36
36
|
owner: repoOwner,
|
|
37
37
|
repo: repoName,
|
|
38
38
|
issue_number: commit.sourcePullRequest.number,
|
|
@@ -41,7 +41,7 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
44
|
-
logger_1.logger.info(`Could not create status comment `, e
|
|
44
|
+
logger_1.logger.info(`Could not create status comment `, e);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.createStatusComment = createStatusComment;
|
|
@@ -49,8 +49,8 @@ function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
|
49
49
|
const { repoName, repoOwner, autoMerge } = options;
|
|
50
50
|
// custom handling when running backport locally (as opposed to on CI)
|
|
51
51
|
if (!options.ci) {
|
|
52
|
-
//
|
|
53
|
-
if (backportResponse.status
|
|
52
|
+
// only post successful backports when not running in CI
|
|
53
|
+
if (backportResponse.status !== 'success') {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
// only post a comment if all backports succeeded
|
|
@@ -60,15 +60,15 @@ function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
const packageVersionSection = `\n<!--- Backport version: ${packageVersion_1.PACKAGE_VERSION} -->`;
|
|
63
|
-
const manualBackportCommand = `\n### Manual backport\nTo create the backport manually run:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n
|
|
64
|
-
const questionsAndLinkToBackport = '\n
|
|
65
|
-
if (backportResponse.status === '
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return `## ⚪ Backport skipped
|
|
63
|
+
const manualBackportCommand = `\n### Manual backport\nTo create the backport manually run:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\`\n`;
|
|
64
|
+
const questionsAndLinkToBackport = '\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)\n';
|
|
65
|
+
if (backportResponse.status === 'aborted' &&
|
|
66
|
+
backportResponse.error.errorContext.code === 'no-branches-exception') {
|
|
67
|
+
return `## ⚪ Backport skipped
|
|
69
68
|
The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
|
|
70
69
|
${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
71
|
-
|
|
70
|
+
}
|
|
71
|
+
if (backportResponse.status !== 'success') {
|
|
72
72
|
return `## 💔 Backport failed
|
|
73
73
|
The pull request could not be backported due to the following error:
|
|
74
74
|
\`${backportResponse.error.message}\`
|
|
@@ -106,7 +106,7 @@ ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
|
106
106
|
.map((line) => line.join('|'))
|
|
107
107
|
.join('|\n|');
|
|
108
108
|
const table = backportResponse.results.length
|
|
109
|
-
?
|
|
109
|
+
? `\n\n| Status | Branch | Result |\n|:------:|:------:|:------|\n|${tableBody}|\n`
|
|
110
110
|
: '';
|
|
111
111
|
const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
|
|
112
112
|
const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
|
|
@@ -121,12 +121,11 @@ ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
|
121
121
|
header = '## 💔 All backports failed';
|
|
122
122
|
}
|
|
123
123
|
const autoMergeMessage = autoMerge && didAnyBackportsSucceed
|
|
124
|
-
? '\nNote: Successful backport PRs will be merged automatically after passing CI
|
|
124
|
+
? '\nNote: Successful backport PRs will be merged automatically after passing CI.\n'
|
|
125
125
|
: '';
|
|
126
126
|
const backportPRCommandMessage = !didAllBackportsSucceed
|
|
127
127
|
? `${manualBackportCommand}`
|
|
128
128
|
: '';
|
|
129
|
-
return `${header}
|
|
130
|
-
${backportPRCommandMessage}${autoMergeMessage}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
129
|
+
return `${header}${table}${autoMergeMessage}${backportPRCommandMessage}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
131
130
|
}
|
|
132
131
|
exports.getCommentBody = getCommentBody;
|
|
@@ -65,6 +65,7 @@ describe('getCommentBody', () => {
|
|
|
65
65
|
|
|
66
66
|
### Questions ?
|
|
67
67
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
68
|
+
|
|
68
69
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
69
70
|
`);
|
|
70
71
|
});
|
|
@@ -114,6 +115,7 @@ describe('getCommentBody', () => {
|
|
|
114
115
|
|
|
115
116
|
### Questions ?
|
|
116
117
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
118
|
+
|
|
117
119
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
118
120
|
`);
|
|
119
121
|
});
|
|
@@ -131,6 +133,7 @@ describe('getCommentBody', () => {
|
|
|
131
133
|
|
|
132
134
|
### Questions ?
|
|
133
135
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
136
|
+
|
|
134
137
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
135
138
|
`);
|
|
136
139
|
});
|
|
@@ -149,12 +152,12 @@ describe('getCommentBody', () => {
|
|
|
149
152
|
status: 'success',
|
|
150
153
|
results: [
|
|
151
154
|
{
|
|
152
|
-
status: '
|
|
155
|
+
status: 'unhandled-error',
|
|
153
156
|
targetBranch: '7.x',
|
|
154
157
|
error: new Error('My boom error!'),
|
|
155
158
|
},
|
|
156
159
|
{
|
|
157
|
-
status: '
|
|
160
|
+
status: 'unhandled-error',
|
|
158
161
|
targetBranch: '7.1',
|
|
159
162
|
error: new Error('My boom error!'),
|
|
160
163
|
},
|
|
@@ -179,6 +182,7 @@ describe('getCommentBody', () => {
|
|
|
179
182
|
|
|
180
183
|
### Questions ?
|
|
181
184
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
185
|
+
|
|
182
186
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
183
187
|
`);
|
|
184
188
|
});
|
|
@@ -224,15 +228,17 @@ describe('getCommentBody', () => {
|
|
|
224
228
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
225
229
|
|❌|7.1|My boom error!|
|
|
226
230
|
|
|
231
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
232
|
+
|
|
227
233
|
### Manual backport
|
|
228
234
|
To create the backport manually run:
|
|
229
235
|
\`\`\`
|
|
230
236
|
node scripts/backport --pr 55
|
|
231
237
|
\`\`\`
|
|
232
|
-
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
233
238
|
|
|
234
239
|
### Questions ?
|
|
235
240
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
241
|
+
|
|
236
242
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
237
243
|
`);
|
|
238
244
|
});
|
|
@@ -341,15 +347,17 @@ describe('getCommentBody', () => {
|
|
|
341
347
|
|❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
|
|
342
348
|
|❌|7.2|**Backport failed because of merge conflicts**|
|
|
343
349
|
|
|
350
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
351
|
+
|
|
344
352
|
### Manual backport
|
|
345
353
|
To create the backport manually run:
|
|
346
354
|
\`\`\`
|
|
347
355
|
node scripts/backport --pr 55
|
|
348
356
|
\`\`\`
|
|
349
|
-
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
350
357
|
|
|
351
358
|
### Questions ?
|
|
352
359
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
360
|
+
|
|
353
361
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
354
362
|
`);
|
|
355
363
|
});
|
|
@@ -369,7 +377,8 @@ describe('getCommentBody', () => {
|
|
|
369
377
|
},
|
|
370
378
|
pullNumber: 55,
|
|
371
379
|
backportResponse: {
|
|
372
|
-
status: '
|
|
380
|
+
status: 'aborted',
|
|
381
|
+
commits: [],
|
|
373
382
|
error: new HandledError_1.HandledError({ code: 'no-branches-exception' }),
|
|
374
383
|
},
|
|
375
384
|
});
|
|
@@ -387,6 +396,7 @@ describe('getCommentBody', () => {
|
|
|
387
396
|
|
|
388
397
|
### Questions ?
|
|
389
398
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
399
|
+
|
|
390
400
|
<!--- Backport version: 1.2.3-mocked -->"
|
|
391
401
|
`);
|
|
392
402
|
});
|
|
@@ -43,10 +43,8 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
43
43
|
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
44
44
|
}
|
|
45
45
|
catch (e) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e.stack);
|
|
49
|
-
}
|
|
46
|
+
spinner.fail();
|
|
47
|
+
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/services/logger.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const promises_1 = require("fs/promises");
|
|
4
|
+
async function init() {
|
|
5
|
+
try {
|
|
6
|
+
await (0, promises_1.writeFile)('foo.txt', 'foo', {
|
|
7
|
+
flag: 'wx',
|
|
8
|
+
mode: 0o600, // give the owner read-write privleges, no access for others
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
const a = e instanceof Error;
|
|
13
|
+
console.log(a);
|
|
14
|
+
console.log(e.constructor.name);
|
|
15
|
+
if (isErrnoError(e)) {
|
|
16
|
+
console.log(e.path);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
init();
|
|
21
|
+
function isErrnoError(error) {
|
|
22
|
+
return error instanceof Error && 'code' in error;
|
|
23
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -20,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
const child_process_promisified_1 = require("../../../services/child-process-promisified");
|
|
27
|
+
const env_1 = require("../../../services/env");
|
|
23
28
|
const packageVersion = __importStar(require("../../../utils/packageVersion"));
|
|
24
29
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
25
30
|
const sandbox_1 = require("../../sandbox");
|
|
@@ -63,8 +68,7 @@ describe('entrypoint cli', () => {
|
|
|
63
68
|
--projectConfigFile, --config Path to project config [string]
|
|
64
69
|
--since ISO-8601 date for filtering commits [string]
|
|
65
70
|
--until ISO-8601 date for filtering commits [string]
|
|
66
|
-
--dir
|
|
67
|
-
[string]
|
|
71
|
+
--dir Path to temporary backport repo [string]
|
|
68
72
|
--details Show details about each commit [boolean]
|
|
69
73
|
--dryRun Run backport locally without pushing to Github [boolean]
|
|
70
74
|
--editor Editor to be opened during conflict resolution [string]
|
|
@@ -112,7 +116,7 @@ describe('entrypoint cli', () => {
|
|
|
112
116
|
Or contact me directly: https://twitter.com/sorenlouv"
|
|
113
117
|
`);
|
|
114
118
|
});
|
|
115
|
-
it('should
|
|
119
|
+
it('should output error when branch is missing', async () => {
|
|
116
120
|
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
117
121
|
'--skip-remote-config',
|
|
118
122
|
'--repo=backport-org/backport-e2e',
|
|
@@ -123,6 +127,14 @@ describe('entrypoint cli', () => {
|
|
|
123
127
|
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
124
128
|
`);
|
|
125
129
|
});
|
|
130
|
+
it('should output error when access token is invalid', async () => {
|
|
131
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
132
|
+
'--branch=foo',
|
|
133
|
+
'--repo=foo/bar',
|
|
134
|
+
'--accessToken=some-token',
|
|
135
|
+
]);
|
|
136
|
+
expect(res).toContain('Please check your access token and make sure it is valid');
|
|
137
|
+
});
|
|
126
138
|
it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
|
|
127
139
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
128
140
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
@@ -146,22 +158,53 @@ describe('entrypoint cli', () => {
|
|
|
146
158
|
10.Add package.json"
|
|
147
159
|
`);
|
|
148
160
|
});
|
|
149
|
-
it(
|
|
161
|
+
it(`should output error when repo doesn't exist`, async () => {
|
|
150
162
|
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
151
163
|
'--branch=foo',
|
|
152
164
|
'--repo=foo/bar',
|
|
153
|
-
'--
|
|
165
|
+
'--author=sqren',
|
|
166
|
+
`--accessToken=${accessToken}`,
|
|
154
167
|
]);
|
|
155
|
-
expect(res).
|
|
168
|
+
expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
156
169
|
});
|
|
157
|
-
it(`should
|
|
170
|
+
it(`should output error when given branch is invalid`, async () => {
|
|
158
171
|
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
159
172
|
'--branch=foo',
|
|
160
|
-
'--repo=
|
|
161
|
-
'--
|
|
173
|
+
'--repo=backport-org/backport-e2e',
|
|
174
|
+
'--pr=9',
|
|
162
175
|
`--accessToken=${accessToken}`,
|
|
163
|
-
]);
|
|
164
|
-
expect(res).toMatchInlineSnapshot(`
|
|
176
|
+
], { waitForString: "is invalid or doesn't exist" });
|
|
177
|
+
expect(res).toMatchInlineSnapshot(`
|
|
178
|
+
"
|
|
179
|
+
Backporting to foo:
|
|
180
|
+
The branch \\"foo\\" is invalid or doesn't exist"
|
|
181
|
+
`);
|
|
182
|
+
});
|
|
183
|
+
it(`should output merge conflict`, async () => {
|
|
184
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
185
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
186
|
+
'--pr=12',
|
|
187
|
+
'--branch=7.x',
|
|
188
|
+
`--accessToken=${accessToken}`,
|
|
189
|
+
'--dry-run',
|
|
190
|
+
], {
|
|
191
|
+
waitForString: 'Press ENTER when the conflicts',
|
|
192
|
+
});
|
|
193
|
+
const backportDir = (0, env_1.getBackportDirPath)();
|
|
194
|
+
expect(res.replaceAll(backportDir, '<HOMEDIR>')).toMatchInlineSnapshot(`
|
|
195
|
+
"
|
|
196
|
+
Backporting to 7.x:
|
|
197
|
+
The commit could not be backported due to conflicts
|
|
198
|
+
Please fix the conflicts in <HOMEDIR>/repositories/backport-org/repo-with-conflicts
|
|
199
|
+
Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\":
|
|
200
|
+
- Change Barca to Braithwaite (#8) (backport missing)
|
|
201
|
+
https://github.com/backport-org/repo-with-conflicts/pull/8
|
|
202
|
+
? Fix the following conflicts manually:
|
|
203
|
+
Conflicting files:
|
|
204
|
+
- <HOMEDIR>/repositories/backport-org/repo-with-conflicts/la-liga.
|
|
205
|
+
md
|
|
206
|
+
Press ENTER when the conflicts are resolved and files are staged (Y/n)"
|
|
207
|
+
`);
|
|
165
208
|
});
|
|
166
209
|
it(`should list commits from master`, async () => {
|
|
167
210
|
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
@@ -216,4 +259,143 @@ describe('entrypoint cli', () => {
|
|
|
216
259
|
6. Bump to 8.0.0"
|
|
217
260
|
`);
|
|
218
261
|
});
|
|
262
|
+
describe('ci failure cases', () => {
|
|
263
|
+
it(`when access token is missing`, async () => {
|
|
264
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci']);
|
|
265
|
+
const backportResult = JSON.parse(output);
|
|
266
|
+
expect(backportResult.status).toBe('failure');
|
|
267
|
+
expect(backportResult.errorMessage).toEqual('Access token missing. It must be explicitly supplied when using "--ci" option. Example: --access-token very-secret');
|
|
268
|
+
});
|
|
269
|
+
it(`when argument is invalid`, async () => {
|
|
270
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci', '--foo']);
|
|
271
|
+
const backportResult = JSON.parse(output);
|
|
272
|
+
expect(backportResult.status).toBe('failure');
|
|
273
|
+
expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
|
|
274
|
+
});
|
|
275
|
+
it('when `--repo` is invalid', async () => {
|
|
276
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
277
|
+
'--repo=backport-org/backport-e2e-foo',
|
|
278
|
+
'--ci',
|
|
279
|
+
`--accessToken=${accessToken}`,
|
|
280
|
+
]);
|
|
281
|
+
const backportResult = JSON.parse(output);
|
|
282
|
+
expect(backportResult.status).toBe('failure');
|
|
283
|
+
expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
|
|
284
|
+
});
|
|
285
|
+
it('when `--sha` is invalid', async () => {
|
|
286
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
287
|
+
'--repo=backport-org/backport-e2e',
|
|
288
|
+
'--sha=abcdefg',
|
|
289
|
+
'--ci',
|
|
290
|
+
`--accessToken=${accessToken}`,
|
|
291
|
+
]);
|
|
292
|
+
const backportResult = JSON.parse(output);
|
|
293
|
+
expect(backportResult.status).toBe('failure');
|
|
294
|
+
expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
|
|
295
|
+
});
|
|
296
|
+
it('when `--branch` is invalid', async () => {
|
|
297
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
298
|
+
'--repo=backport-org/backport-e2e',
|
|
299
|
+
'--pr=9',
|
|
300
|
+
'--branch=foobar',
|
|
301
|
+
'--ci',
|
|
302
|
+
`--accessToken=${accessToken}`,
|
|
303
|
+
]);
|
|
304
|
+
const backportResult = JSON.parse(output);
|
|
305
|
+
expect(backportResult.status).toBe('success');
|
|
306
|
+
expect(backportResult.results[0]).toEqual({
|
|
307
|
+
error: {
|
|
308
|
+
errorContext: {
|
|
309
|
+
code: 'message-only-exception',
|
|
310
|
+
message: 'The branch "foobar" is invalid or doesn\'t exist',
|
|
311
|
+
},
|
|
312
|
+
name: 'HandledError',
|
|
313
|
+
},
|
|
314
|
+
status: 'handled-error',
|
|
315
|
+
targetBranch: 'foobar',
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
it('when `--pr` is invalid', async () => {
|
|
319
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
320
|
+
'--repo=backport-org/backport-e2e',
|
|
321
|
+
'--pr=900',
|
|
322
|
+
'--branch=foobar',
|
|
323
|
+
'--ci',
|
|
324
|
+
`--accessToken=${accessToken}`,
|
|
325
|
+
]);
|
|
326
|
+
const backportResult = JSON.parse(output);
|
|
327
|
+
expect(backportResult.status).toEqual('failure');
|
|
328
|
+
expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
|
|
329
|
+
});
|
|
330
|
+
it('when having conflicts', async () => {
|
|
331
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
332
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
333
|
+
'--pr=12',
|
|
334
|
+
'--branch=7.x',
|
|
335
|
+
'--ci',
|
|
336
|
+
`--accessToken=${accessToken}`,
|
|
337
|
+
]);
|
|
338
|
+
const backportResult = JSON.parse(output);
|
|
339
|
+
expect(backportResult.status).toEqual('success');
|
|
340
|
+
expect(
|
|
341
|
+
//@ts-expect-error
|
|
342
|
+
backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
|
|
343
|
+
});
|
|
344
|
+
it('when `--source-branch` is invalid', async () => {
|
|
345
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
346
|
+
'--repo=backport-org/backport-e2e',
|
|
347
|
+
'--pr=9',
|
|
348
|
+
'--branch=7.x',
|
|
349
|
+
'--source-branch=foo',
|
|
350
|
+
'--ci',
|
|
351
|
+
`--accessToken=${accessToken}`,
|
|
352
|
+
]);
|
|
353
|
+
const backportResult = JSON.parse(output);
|
|
354
|
+
expect(backportResult.status).toBe('success');
|
|
355
|
+
expect(backportResult.results[0]).toEqual({
|
|
356
|
+
error: {
|
|
357
|
+
context: {
|
|
358
|
+
cmdArgs: ['checkout', 'foo'],
|
|
359
|
+
code: 1,
|
|
360
|
+
stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
|
|
361
|
+
stdout: '',
|
|
362
|
+
},
|
|
363
|
+
name: 'SpawnError',
|
|
364
|
+
},
|
|
365
|
+
status: 'unhandled-error',
|
|
366
|
+
targetBranch: '7.x',
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
it('when PR is not merged', async () => {
|
|
370
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
371
|
+
'--repo=backport-org/backport-e2e',
|
|
372
|
+
'--pr=12',
|
|
373
|
+
'--ci',
|
|
374
|
+
`--accessToken=${accessToken}`,
|
|
375
|
+
]);
|
|
376
|
+
const backportResult = JSON.parse(output);
|
|
377
|
+
expect(backportResult.status).toBe('failure');
|
|
378
|
+
expect(backportResult.error).toEqual({
|
|
379
|
+
errorContext: {
|
|
380
|
+
code: 'message-only-exception',
|
|
381
|
+
message: 'The PR #12 is not merged',
|
|
382
|
+
},
|
|
383
|
+
name: 'HandledError',
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
it('when target branch is missing', async () => {
|
|
387
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
388
|
+
'--repo=backport-org/backport-e2e',
|
|
389
|
+
'--pr=9',
|
|
390
|
+
'--ci',
|
|
391
|
+
`--accessToken=${accessToken}`,
|
|
392
|
+
]);
|
|
393
|
+
const backportResult = JSON.parse(output);
|
|
394
|
+
expect(backportResult.status).toBe('aborted');
|
|
395
|
+
expect(backportResult.error).toEqual({
|
|
396
|
+
errorContext: { code: 'no-branches-exception' },
|
|
397
|
+
name: 'HandledError',
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
219
401
|
});
|
|
@@ -4,7 +4,7 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
|
4
4
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
5
5
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
6
|
describe('repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
|
|
7
|
-
it('
|
|
7
|
+
it('lists commits', async () => {
|
|
8
8
|
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
9
9
|
'--branch=foo',
|
|
10
10
|
'--repo=backport-org/repo-with-backportrc-removed',
|
|
@@ -21,29 +21,30 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
|
|
|
21
21
|
7. Create .backportrc.json"
|
|
22
22
|
`);
|
|
23
23
|
});
|
|
24
|
-
it('
|
|
24
|
+
it('backports via pr', async () => {
|
|
25
25
|
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
26
|
-
'--branch=
|
|
26
|
+
'--branch=production',
|
|
27
27
|
'--repo=backport-org/repo-with-backportrc-removed',
|
|
28
28
|
'--pr=1',
|
|
29
29
|
`--accessToken=${accessToken}`,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
'--dry-run',
|
|
31
|
+
], {
|
|
32
|
+
waitForString: `Dry run complete`,
|
|
33
|
+
showOra: true,
|
|
34
|
+
});
|
|
35
|
+
expect(output).toContain('Cherry-picking: Merge pull request #1 from backport-org/add-readme');
|
|
36
36
|
});
|
|
37
|
-
it('
|
|
37
|
+
it('backport by commit sha', async () => {
|
|
38
38
|
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
39
|
-
'--branch=
|
|
39
|
+
'--branch=production',
|
|
40
40
|
'--repo=backport-org/repo-with-backportrc-removed',
|
|
41
41
|
'--sha=be59df6912a550c8cb49ba3e18be3e512f3d608c',
|
|
42
42
|
`--accessToken=${accessToken}`,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
'--dry-run',
|
|
44
|
+
], {
|
|
45
|
+
waitForString: `Dry run complete`,
|
|
46
|
+
showOra: true,
|
|
47
|
+
});
|
|
48
|
+
expect(output).toContain('Cherry-picking: Create README.me');
|
|
48
49
|
});
|
|
49
50
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function runBackportViaCli(cliArgs: string[], { showOra, waitForString, cwd, }?: {
|
|
1
|
+
export declare function runBackportViaCli(cliArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
|
|
2
|
+
timeoutSeconds?: number;
|
|
2
3
|
showOra?: boolean;
|
|
3
4
|
waitForString?: string;
|
|
4
5
|
cwd?: string;
|