backport 6.1.2 โ 6.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/README.md +39 -37
- package/dist/backportRun.d.ts +14 -0
- package/dist/backportRun.js +75 -0
- package/dist/entrypoint.api.d.ts +22 -0
- package/dist/entrypoint.api.js +57 -0
- package/dist/entrypoint.api.private.test.d.ts +1 -0
- package/dist/entrypoint.api.private.test.js +37 -0
- package/dist/entrypoint.module.d.ts +4 -1
- package/dist/entrypoint.module.js +10 -4
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +5 -1
- package/dist/options/ConfigOptions.d.ts +2 -0
- package/dist/options/cliArgs.d.ts +5 -1
- package/dist/options/cliArgs.js +24 -2
- package/dist/options/config/config.d.ts +6 -1
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/config.test.js +1 -1
- package/dist/options/config/getProjectConfig.d.ts +0 -0
- package/dist/options/config/getProjectConfig.js +1 -0
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +4 -8
- package/dist/options/config/globalConfig.test.js +2 -2
- package/dist/options/config/readConfigFile.d.ts +3 -1
- package/dist/options/options.d.ts +8 -1
- package/dist/options/options.js +9 -2
- package/dist/options/options.test.js +7 -3
- package/dist/react-components/0-loadOptions.d.ts +6 -0
- package/dist/react-components/0-loadOptions.js +45 -0
- package/dist/react-components/1-loadCommit.d.ts +8 -0
- package/dist/react-components/1-loadCommit.js +88 -0
- package/dist/react-components/1a-loadCommit.d.ts +5 -0
- package/dist/react-components/1a-loadCommit.js +76 -0
- package/dist/react-components/1b-commitChoices.d.ts +5 -0
- package/dist/react-components/1b-commitChoices.js +98 -0
- package/dist/react-components/2-commitChoices.d.ts +8 -0
- package/dist/react-components/2-commitChoices.js +96 -0
- package/dist/react-components/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/2-commitsPrompt.js +96 -0
- package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
- package/dist/react-components/2-targetBranchChoices.js +109 -0
- package/dist/react-components/3-cherrypick.d.ts +1 -0
- package/dist/react-components/3-cherrypick.js +2 -0
- package/dist/react-components/App.d.ts +2 -0
- package/dist/react-components/App.js +35 -0
- package/dist/react-components/BackportStateContext.d.ts +33 -0
- package/dist/react-components/BackportStateContext.js +42 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
- package/dist/react-components/CommitPrompt/getCommits.js +27 -0
- package/dist/react-components/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt.js +96 -0
- package/dist/react-components/CustomMultiSelect.d.ts +13 -0
- package/dist/react-components/CustomMultiSelect.js +21 -0
- package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
- package/dist/react-components/CustomMultiSelectItem.js +12 -0
- package/dist/react-components/CustomSelect.d.ts +14 -0
- package/dist/react-components/CustomSelect.js +34 -0
- package/dist/react-components/ErrorBoundary.d.ts +15 -0
- package/dist/react-components/ErrorBoundary.js +53 -0
- package/dist/react-components/MultiSelect.d.ts +7 -0
- package/dist/react-components/MultiSelect.js +16 -0
- package/dist/react-components/hooks/useAsync.d.ts +12 -0
- package/dist/react-components/hooks/useAsync.js +73 -0
- package/dist/runSequentially.test.js +10 -7
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
- package/dist/services/backportRun/backportRun.ci.js +81 -0
- package/dist/services/backportRun/backportRun.d.ts +14 -0
- package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
- package/dist/services/backportRun/backportRun.interactive.js +4 -0
- package/dist/services/backportRun/backportRun.js +14 -0
- package/dist/services/backportRun/backportState.d.ts +4 -0
- package/dist/services/backportRun/backportState.js +28 -0
- package/dist/services/backportRun/getCommits.d.ts +2 -0
- package/dist/services/backportRun/getCommits.js +20 -0
- package/dist/services/backportRun/runSequentially.d.ts +20 -0
- package/dist/services/backportRun/runSequentially.js +41 -0
- package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
- package/dist/services/backportRun/runSequentially.test.js +199 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
- package/dist/services/env.d.ts +2 -3
- package/dist/services/env.js +9 -10
- package/dist/services/env.test.js +0 -6
- package/dist/services/getCommits.d.ts +2 -0
- package/dist/services/getCommits.js +38 -0
- package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/services/getCommitsWithoutBackports.js +68 -0
- package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/services/getCommitsWithoutBackports.test.js +259 -0
- package/dist/services/getTargetBranches.d.ts +5 -0
- package/dist/services/getTargetBranches.js +60 -0
- package/dist/services/getTargetBranches.test.d.ts +1 -0
- package/dist/services/getTargetBranches.test.js +180 -0
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createPullRequest.js +1 -1
- 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 +40 -15
- package/dist/services/github/v3/createStatusComment.test.js +190 -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/fetchProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchProjectConfig.js +3 -3
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/logger.d.ts +0 -1
- package/dist/services/logger.js +3 -3
- package/dist/services/maybeSetupRepo.d.ts +2 -0
- package/dist/services/maybeSetupRepo.js +33 -0
- package/dist/services/maybeSetupRepo.test.d.ts +1 -0
- package/dist/services/maybeSetupRepo.test.js +78 -0
- 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/backport-e2e.private.test.d.ts +1 -0
- package/dist/test/backport-e2e.private.test.js +327 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
- package/dist/test/inquirer.private.test.js +1 -1
- 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/todo-delete.d.ts +1 -0
- package/dist/todo-delete.js +17 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.js +17 -2
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/maybeSetupRepo.js +0 -6
- package/dist/ui/maybeSetupRepo.test.js +8 -4
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -0
- package/dist/utils/sequentially.d.ts +1 -0
- package/dist/utils/sequentially.js +10 -0
- package/package.json +3 -3
- package/yarn.lock +462 -284
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCommentBody = exports.createStatusComment = void 0;
|
|
4
4
|
const rest_1 = require("@octokit/rest");
|
|
5
|
+
const redact_1 = require("../../../utils/redact");
|
|
5
6
|
const logger_1 = require("../../logger");
|
|
6
7
|
const commitFormatters_1 = require("../commitFormatters");
|
|
7
8
|
async function createStatusComment({ options, backportResponse, }) {
|
|
8
|
-
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken } = options;
|
|
9
|
+
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
|
|
10
|
+
if (!publishStatusComment) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
9
13
|
try {
|
|
10
14
|
const octokit = new rest_1.Octokit({
|
|
11
15
|
auth: accessToken,
|
|
12
16
|
baseUrl: githubApiBaseUrlV3,
|
|
13
17
|
log: logger_1.logger,
|
|
14
18
|
});
|
|
15
|
-
// don't post update if there are no new pull requests created
|
|
16
|
-
if (backportResponse.status === 'success') {
|
|
17
|
-
const hasOnlyUpdates = backportResponse.results.every((result) => result.status === 'success' && result.didUpdate);
|
|
18
|
-
if (hasOnlyUpdates) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
19
|
await Promise.all(backportResponse.commits.map((commit) => {
|
|
23
20
|
if (!commit.pullNumber) {
|
|
24
21
|
return;
|
|
@@ -28,11 +25,16 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
28
25
|
pullNumber: commit.pullNumber,
|
|
29
26
|
backportResponse,
|
|
30
27
|
});
|
|
28
|
+
// only post comment if there is a body
|
|
29
|
+
if (!body) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
31
32
|
return octokit.issues.createComment({
|
|
33
|
+
baseUrl: options.githubApiBaseUrlV3,
|
|
32
34
|
owner: repoOwner,
|
|
33
35
|
repo: repoName,
|
|
34
36
|
issue_number: commit.pullNumber,
|
|
35
|
-
body,
|
|
37
|
+
body: (0, redact_1.redact)(options.accessToken, body),
|
|
36
38
|
});
|
|
37
39
|
}));
|
|
38
40
|
}
|
|
@@ -43,6 +45,18 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
43
45
|
exports.createStatusComment = createStatusComment;
|
|
44
46
|
function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
45
47
|
const { repoName, repoOwner, autoMerge } = options;
|
|
48
|
+
// custom handling when running backport locally (as opposed to on CI)
|
|
49
|
+
if (!options.ci) {
|
|
50
|
+
// don't post comment when the overall process failed
|
|
51
|
+
if (backportResponse.status === 'failure') {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// only post a comment if all backports succeeded
|
|
55
|
+
const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
|
|
56
|
+
if (!didAllBackportsSucceed) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
46
60
|
const backportPRCommand = `\n### How to fix\nRe-run the backport manually:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\``;
|
|
47
61
|
const supportSection = '\n\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)';
|
|
48
62
|
if (backportResponse.status === 'failure') {
|
|
@@ -52,6 +66,10 @@ The pull request could not be backported due to the following error:
|
|
|
52
66
|
${backportPRCommand}${supportSection}`;
|
|
53
67
|
}
|
|
54
68
|
const tableBody = backportResponse.results
|
|
69
|
+
.filter((result) => {
|
|
70
|
+
// only post status updates for successful backports when running manually (non-ci)
|
|
71
|
+
return options.ci || result.status === 'success';
|
|
72
|
+
})
|
|
55
73
|
.map((result) => {
|
|
56
74
|
if (result.status === 'success') {
|
|
57
75
|
return [
|
|
@@ -60,7 +78,7 @@ ${backportPRCommand}${supportSection}`;
|
|
|
60
78
|
`[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
|
|
61
79
|
];
|
|
62
80
|
}
|
|
63
|
-
if (result.error.meta?.type === '
|
|
81
|
+
if (result.error.meta?.type === 'merge-conflict-due-to-missing-backports') {
|
|
64
82
|
const conflictingPullRequests = result.error.meta.commitsWithoutBackports.map((c) => {
|
|
65
83
|
return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)}](${c.commit.pullUrl})`;
|
|
66
84
|
});
|
|
@@ -80,16 +98,23 @@ ${backportPRCommand}${supportSection}`;
|
|
|
80
98
|
: '';
|
|
81
99
|
const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
|
|
82
100
|
const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
let header = '';
|
|
102
|
+
if (didAllBackportsSucceed) {
|
|
103
|
+
header = '## ๐ All backports created successfully';
|
|
104
|
+
}
|
|
105
|
+
else if (didAnyBackportsSucceed) {
|
|
106
|
+
header = '## ๐ Some backports could not be created';
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
header = '## ๐ All backports failed';
|
|
110
|
+
}
|
|
86
111
|
const autoMergeMessage = autoMerge && didAnyBackportsSucceed
|
|
87
112
|
? '\nNote: Successful backport PRs will be merged automatically after passing CI.'
|
|
88
113
|
: '';
|
|
89
114
|
const backportPRCommandMessage = !didAllBackportsSucceed
|
|
90
115
|
? `${backportPRCommand}`
|
|
91
116
|
: '';
|
|
92
|
-
return
|
|
93
|
-
${backportPRCommandMessage}${autoMergeMessage}${supportSection}
|
|
117
|
+
return `${header}\n\n${table}
|
|
118
|
+
${backportPRCommandMessage}${autoMergeMessage}${supportSection}`;
|
|
94
119
|
}
|
|
95
120
|
exports.getCommentBody = getCommentBody;
|
|
@@ -1,32 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nock_1 = __importDefault(require("nock"));
|
|
3
7
|
const HandledError_1 = require("../../HandledError");
|
|
4
8
|
const createStatusComment_1 = require("./createStatusComment");
|
|
9
|
+
describe('createStatusComment', () => {
|
|
10
|
+
it('redacts accessToken if it is included in the error message', async () => {
|
|
11
|
+
const accessToken = 'ghp_abcdefg';
|
|
12
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
13
|
+
.post('/repos/elastic/kibana/issues/100/comments')
|
|
14
|
+
.reply(200, 'some response');
|
|
15
|
+
let postedCommentBody = '';
|
|
16
|
+
scope.on('request', (req, interceptor, body) => {
|
|
17
|
+
postedCommentBody = JSON.parse(body).body;
|
|
18
|
+
});
|
|
19
|
+
await (0, createStatusComment_1.createStatusComment)({
|
|
20
|
+
options: {
|
|
21
|
+
repoName: 'kibana',
|
|
22
|
+
repoOwner: 'elastic',
|
|
23
|
+
accessToken,
|
|
24
|
+
backportBinary: 'node scripts/backport',
|
|
25
|
+
publishStatusComment: true,
|
|
26
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
27
|
+
ci: true,
|
|
28
|
+
},
|
|
29
|
+
backportResponse: {
|
|
30
|
+
commits: [{ pullNumber: 100 }],
|
|
31
|
+
status: 'failure',
|
|
32
|
+
errorMessage: `Error message containing very secret access token: ${accessToken}.`,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
expect(postedCommentBody).toContain('Error message containing very secret access token: <REDACTED>');
|
|
36
|
+
scope.done();
|
|
37
|
+
nock_1.default.cleanAll();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
5
40
|
describe('getCommentBody', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
options: {
|
|
41
|
+
describe('when an unknown error occurs', () => {
|
|
42
|
+
const getParams = (opts) => ({
|
|
43
|
+
options: {
|
|
44
|
+
backportBinary: 'node scripts/backport',
|
|
45
|
+
...opts,
|
|
46
|
+
},
|
|
9
47
|
pullNumber: 55,
|
|
10
48
|
backportResponse: {
|
|
11
49
|
status: 'failure',
|
|
12
50
|
errorMessage: 'A terrible error occured',
|
|
13
51
|
},
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
});
|
|
53
|
+
it('posts a comment when running on ci', () => {
|
|
54
|
+
const params = getParams({ ci: true });
|
|
55
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
56
|
+
"## ๐ Backport failed
|
|
57
|
+
The pull request could not be backported due to the following error:
|
|
58
|
+
\`A terrible error occured\`
|
|
59
|
+
|
|
60
|
+
### How to fix
|
|
61
|
+
Re-run the backport manually:
|
|
62
|
+
\`\`\`
|
|
63
|
+
node scripts/backport --pr 55
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
### Questions ?
|
|
67
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
68
|
+
`);
|
|
69
|
+
});
|
|
70
|
+
it('does not post a comment when running manually', () => {
|
|
71
|
+
const params = getParams({ ci: false });
|
|
72
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
73
|
+
});
|
|
23
74
|
});
|
|
24
|
-
|
|
25
|
-
|
|
75
|
+
describe('when all backports succeed', () => {
|
|
76
|
+
const getParams = (opts) => ({
|
|
26
77
|
options: {
|
|
27
78
|
repoName: 'kibana',
|
|
28
79
|
repoOwner: 'elastic',
|
|
29
80
|
autoMerge: true,
|
|
81
|
+
...opts,
|
|
30
82
|
},
|
|
31
83
|
pullNumber: 55,
|
|
32
84
|
backportResponse: {
|
|
@@ -46,24 +98,48 @@ describe('getCommentBody', () => {
|
|
|
46
98
|
},
|
|
47
99
|
],
|
|
48
100
|
},
|
|
49
|
-
})
|
|
50
|
-
|
|
101
|
+
});
|
|
102
|
+
it('posts a comment on ci', () => {
|
|
103
|
+
const params = getParams({ ci: true });
|
|
104
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
105
|
+
"## ๐ All backports created successfully
|
|
106
|
+
|
|
107
|
+
| Status | Branch | Result |
|
|
108
|
+
|:------:|:------:|:------|
|
|
109
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
110
|
+
|โ
|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
111
|
+
|
|
112
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
51
113
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
114
|
+
### Questions ?
|
|
115
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
116
|
+
`);
|
|
117
|
+
});
|
|
118
|
+
it('posts a comment when running locally', () => {
|
|
119
|
+
const params = getParams({ ci: false });
|
|
120
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
121
|
+
"## ๐ All backports created successfully
|
|
56
122
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
123
|
+
| Status | Branch | Result |
|
|
124
|
+
|:------:|:------:|:------|
|
|
125
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
126
|
+
|โ
|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
127
|
+
|
|
128
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
129
|
+
|
|
130
|
+
### Questions ?
|
|
131
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
132
|
+
`);
|
|
133
|
+
});
|
|
60
134
|
});
|
|
61
|
-
|
|
62
|
-
|
|
135
|
+
describe('when all backports fail', () => {
|
|
136
|
+
const getParams = (opts) => ({
|
|
63
137
|
options: {
|
|
64
138
|
repoName: 'kibana',
|
|
65
139
|
repoOwner: 'elastic',
|
|
66
140
|
autoMerge: true,
|
|
141
|
+
backportBinary: 'node scripts/backport',
|
|
142
|
+
...opts,
|
|
67
143
|
},
|
|
68
144
|
pullNumber: 55,
|
|
69
145
|
backportResponse: {
|
|
@@ -83,26 +159,40 @@ describe('getCommentBody', () => {
|
|
|
83
159
|
},
|
|
84
160
|
],
|
|
85
161
|
},
|
|
86
|
-
})
|
|
87
|
-
|
|
162
|
+
});
|
|
163
|
+
it('posts a comment on CI', () => {
|
|
164
|
+
const params = getParams({ ci: true });
|
|
165
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
166
|
+
"## ๐ All backports failed
|
|
88
167
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
168
|
+
| Status | Branch | Result |
|
|
169
|
+
|:------:|:------:|:------|
|
|
170
|
+
|โ|7.x|My boom error!|
|
|
171
|
+
|โ|7.1|My boom error!|
|
|
93
172
|
|
|
94
|
-
|
|
95
|
-
|
|
173
|
+
### How to fix
|
|
174
|
+
Re-run the backport manually:
|
|
175
|
+
\`\`\`
|
|
176
|
+
node scripts/backport --pr 55
|
|
177
|
+
\`\`\`
|
|
96
178
|
|
|
97
|
-
|
|
98
|
-
|
|
179
|
+
### Questions ?
|
|
180
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
181
|
+
`);
|
|
182
|
+
});
|
|
183
|
+
it('does not post a comment when running manaully', () => {
|
|
184
|
+
const params = getParams({ ci: false });
|
|
185
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
186
|
+
});
|
|
99
187
|
});
|
|
100
|
-
|
|
101
|
-
|
|
188
|
+
describe('when some backports fail', () => {
|
|
189
|
+
const getParams = (opts) => ({
|
|
102
190
|
options: {
|
|
103
191
|
repoName: 'kibana',
|
|
104
192
|
repoOwner: 'elastic',
|
|
105
193
|
autoMerge: true,
|
|
194
|
+
backportBinary: 'node scripts/backport',
|
|
195
|
+
...opts,
|
|
106
196
|
},
|
|
107
197
|
pullNumber: 55,
|
|
108
198
|
backportResponse: {
|
|
@@ -122,27 +212,41 @@ describe('getCommentBody', () => {
|
|
|
122
212
|
},
|
|
123
213
|
],
|
|
124
214
|
},
|
|
125
|
-
})
|
|
126
|
-
|
|
215
|
+
});
|
|
216
|
+
it('post a comment when running on CI', () => {
|
|
217
|
+
const params = getParams({ ci: true });
|
|
218
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
219
|
+
"## ๐ Some backports could not be created
|
|
127
220
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
221
|
+
| Status | Branch | Result |
|
|
222
|
+
|:------:|:------:|:------|
|
|
223
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
224
|
+
|โ|7.1|My boom error!|
|
|
132
225
|
|
|
133
|
-
|
|
134
|
-
|
|
226
|
+
### How to fix
|
|
227
|
+
Re-run the backport manually:
|
|
228
|
+
\`\`\`
|
|
229
|
+
node scripts/backport --pr 55
|
|
230
|
+
\`\`\`
|
|
231
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
135
232
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
233
|
+
### Questions ?
|
|
234
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
235
|
+
`);
|
|
236
|
+
});
|
|
237
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
238
|
+
const params = getParams({ ci: false });
|
|
239
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
240
|
+
});
|
|
139
241
|
});
|
|
140
|
-
|
|
141
|
-
|
|
242
|
+
describe('when some backports fail due to conflicts', () => {
|
|
243
|
+
const getParams = (opts) => ({
|
|
142
244
|
options: {
|
|
143
245
|
repoName: 'kibana',
|
|
144
246
|
repoOwner: 'elastic',
|
|
145
247
|
autoMerge: true,
|
|
248
|
+
backportBinary: 'node scripts/backport',
|
|
249
|
+
...opts,
|
|
146
250
|
},
|
|
147
251
|
pullNumber: 55,
|
|
148
252
|
backportResponse: {
|
|
@@ -159,13 +263,22 @@ describe('getCommentBody', () => {
|
|
|
159
263
|
targetBranch: '7.1',
|
|
160
264
|
errorMessage: 'My boom error!',
|
|
161
265
|
error: new HandledError_1.HandledError('Boom!', {
|
|
162
|
-
type: '
|
|
266
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
163
267
|
commitsWithoutBackports: [
|
|
164
268
|
{
|
|
165
269
|
//@ts-expect-error
|
|
166
270
|
commit: {
|
|
167
271
|
pullNumber: 5,
|
|
168
272
|
pullUrl: 'url-to-pr-5',
|
|
273
|
+
originalMessage: 'New Zealand commit message',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
//@ts-expect-error
|
|
278
|
+
commit: {
|
|
279
|
+
pullNumber: 44,
|
|
280
|
+
pullUrl: 'url-to-pr-44',
|
|
281
|
+
originalMessage: 'Australia commit',
|
|
169
282
|
},
|
|
170
283
|
},
|
|
171
284
|
],
|
|
@@ -176,34 +289,38 @@ describe('getCommentBody', () => {
|
|
|
176
289
|
targetBranch: '7.2',
|
|
177
290
|
errorMessage: 'My boom error!',
|
|
178
291
|
error: new HandledError_1.HandledError('Boom!', {
|
|
179
|
-
type: '
|
|
180
|
-
commitsWithoutBackports: [
|
|
181
|
-
{
|
|
182
|
-
//@ts-expect-error
|
|
183
|
-
commit: {
|
|
184
|
-
sha: 'acdefg',
|
|
185
|
-
originalMessage: 'Some long message\nin multiple lines',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
],
|
|
292
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
293
|
+
commitsWithoutBackports: [],
|
|
189
294
|
}),
|
|
190
295
|
},
|
|
191
296
|
],
|
|
192
297
|
},
|
|
193
|
-
})
|
|
194
|
-
|
|
298
|
+
});
|
|
299
|
+
it('posts a comment when running on CI', () => {
|
|
300
|
+
const params = getParams({ ci: true });
|
|
301
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
302
|
+
"## ๐ Some backports could not be created
|
|
195
303
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
304
|
+
| Status | Branch | Result |
|
|
305
|
+
|:------:|:------:|:------|
|
|
306
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
307
|
+
|โ|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)|
|
|
308
|
+
|โ|7.2|**Backport failed because of merge conflicts**|
|
|
201
309
|
|
|
202
|
-
|
|
203
|
-
|
|
310
|
+
### How to fix
|
|
311
|
+
Re-run the backport manually:
|
|
312
|
+
\`\`\`
|
|
313
|
+
node scripts/backport --pr 55
|
|
314
|
+
\`\`\`
|
|
315
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
204
316
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
317
|
+
### Questions ?
|
|
318
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
319
|
+
`);
|
|
320
|
+
});
|
|
321
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
322
|
+
const params = getParams({ ci: false });
|
|
323
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
324
|
+
});
|
|
208
325
|
});
|
|
209
326
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
5
|
+
const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
6
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
7
|
+
const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery");
|
|
8
|
+
describe('allFetchers', () => {
|
|
9
|
+
let devAccessToken;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
12
|
+
});
|
|
13
|
+
it('all fetchers return the same commit', async () => {
|
|
14
|
+
const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
15
|
+
accessToken: devAccessToken,
|
|
16
|
+
author: 'sqren',
|
|
17
|
+
historicalBranchLabelMappings: [],
|
|
18
|
+
maxNumber: 1,
|
|
19
|
+
repoName: 'kibana',
|
|
20
|
+
repoOwner: 'elastic',
|
|
21
|
+
sourceBranch: 'main',
|
|
22
|
+
dateSince: '2021-01-10T00:00:00Z',
|
|
23
|
+
dateUntil: '2022-01-01T00:00:00Z',
|
|
24
|
+
commitPaths: [],
|
|
25
|
+
});
|
|
26
|
+
const commitByAuthor = commitsByAuthor[0];
|
|
27
|
+
if (!commitByAuthor.pullNumber) {
|
|
28
|
+
throw new Error('Missing pullnumber!');
|
|
29
|
+
}
|
|
30
|
+
const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
31
|
+
repoOwner: 'elastic',
|
|
32
|
+
repoName: 'kibana',
|
|
33
|
+
accessToken: devAccessToken,
|
|
34
|
+
pullNumber: commitByAuthor.pullNumber,
|
|
35
|
+
sourceBranch: 'master',
|
|
36
|
+
historicalBranchLabelMappings: [],
|
|
37
|
+
});
|
|
38
|
+
const commitBySha = await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
39
|
+
repoOwner: 'elastic',
|
|
40
|
+
repoName: 'kibana',
|
|
41
|
+
accessToken: devAccessToken,
|
|
42
|
+
sha: commitByAuthor.sha,
|
|
43
|
+
sourceBranch: 'main',
|
|
44
|
+
historicalBranchLabelMappings: [],
|
|
45
|
+
});
|
|
46
|
+
const commitsBySearchQuery = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
|
|
47
|
+
repoOwner: 'elastic',
|
|
48
|
+
repoName: 'kibana',
|
|
49
|
+
accessToken: devAccessToken,
|
|
50
|
+
maxNumber: 1,
|
|
51
|
+
prFilter: `[APM] Add note about synthtrace to APM docs`,
|
|
52
|
+
sourceBranch: 'main',
|
|
53
|
+
});
|
|
54
|
+
expect(commitByAuthor).toEqual(commitByPullNumber);
|
|
55
|
+
expect(commitByAuthor).toEqual(commitBySha);
|
|
56
|
+
expect(commitByAuthor).toEqual(commitsBySearchQuery[0]);
|
|
57
|
+
expect(commitByAuthor).toEqual({
|
|
58
|
+
committedDate: '2021-12-20T14:20:16Z',
|
|
59
|
+
expectedTargetPullRequests: [
|
|
60
|
+
{
|
|
61
|
+
branch: '8.0',
|
|
62
|
+
mergeCommit: {
|
|
63
|
+
message: '[APM] Add note about synthtrace to APM docs (#121633) (#121643)\n\nCo-authored-by: Sรธren Louv-Jansen <soren.louv@elastic.co>',
|
|
64
|
+
sha: '842adfdeb5541b059231857522f9009771a46107',
|
|
65
|
+
},
|
|
66
|
+
number: 121643,
|
|
67
|
+
state: 'MERGED',
|
|
68
|
+
url: 'https://github.com/elastic/kibana/pull/121643',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
72
|
+
pullNumber: 121633,
|
|
73
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/121633',
|
|
74
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
75
|
+
sourceBranch: 'main',
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -15,7 +15,7 @@ async function fetchCommitByPullNumber(options) {
|
|
|
15
15
|
repository(owner: $repoOwner, name: $repoName) {
|
|
16
16
|
pullRequest(number: $pullNumber) {
|
|
17
17
|
mergeCommit {
|
|
18
|
-
|
|
18
|
+
...SourceCommitWithTargetPullRequest
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,12 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
2
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
3
26
|
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
27
|
+
const apiRequestV4Module = __importStar(require("../apiRequestV4"));
|
|
4
28
|
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
5
29
|
describe('fetchCommitByPullNumber', () => {
|
|
6
30
|
let devAccessToken;
|
|
7
31
|
beforeAll(async () => {
|
|
8
32
|
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
33
|
});
|
|
34
|
+
describe('snapshot request/response', () => {
|
|
35
|
+
let spy;
|
|
36
|
+
let commit;
|
|
37
|
+
beforeEach(async () => {
|
|
38
|
+
spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
|
|
39
|
+
commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
40
|
+
repoOwner: 'elastic',
|
|
41
|
+
repoName: 'kibana',
|
|
42
|
+
accessToken: devAccessToken,
|
|
43
|
+
pullNumber: 121633,
|
|
44
|
+
sourceBranch: 'master',
|
|
45
|
+
historicalBranchLabelMappings: [],
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it('makes the right queries', () => {
|
|
49
|
+
const queries = spy.mock.calls.reduce((acc, call) => {
|
|
50
|
+
const query = call[0].query;
|
|
51
|
+
const ast = (0, graphql_tag_1.default)(query);
|
|
52
|
+
//@ts-expect-error
|
|
53
|
+
const name = ast.definitions[0].name.value;
|
|
54
|
+
return { ...acc, [name]: query };
|
|
55
|
+
}, {});
|
|
56
|
+
const queryNames = Object.keys(queries);
|
|
57
|
+
expect(queryNames).toEqual(['CommitByPullNumber']);
|
|
58
|
+
queryNames.forEach((name) => {
|
|
59
|
+
expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('returns the correct response', async () => {
|
|
63
|
+
expect(commit).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
10
66
|
describe('when PR was merged', () => {
|
|
11
67
|
it('is returned', async () => {
|
|
12
68
|
const options = {
|
|
@@ -30,12 +86,20 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
30
86
|
state: 'MERGED',
|
|
31
87
|
number: 6,
|
|
32
88
|
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
89
|
+
mergeCommit: {
|
|
90
|
+
message: 'Add ๐ emoji (#5) (#6)',
|
|
91
|
+
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
92
|
+
},
|
|
33
93
|
},
|
|
34
94
|
{
|
|
35
95
|
branch: '7.8',
|
|
36
96
|
state: 'MERGED',
|
|
37
97
|
number: 7,
|
|
38
98
|
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
99
|
+
mergeCommit: {
|
|
100
|
+
message: 'Add ๐ emoji (#5) (#7)',
|
|
101
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
102
|
+
},
|
|
39
103
|
},
|
|
40
104
|
],
|
|
41
105
|
});
|