backport 6.1.1 โ 6.1.5
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 +83 -70
- 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 +3 -0
- package/dist/options/cliArgs.d.ts +5 -1
- package/dist/options/cliArgs.js +24 -2
- package/dist/options/cliArgs.test.js +0 -7
- package/dist/options/config/config.d.ts +7 -1
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/config.test.js +1 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +4 -8
- package/dist/options/config/readConfigFile.d.ts +4 -1
- package/dist/options/options.d.ts +10 -1
- package/dist/options/options.js +10 -2
- package/dist/options/options.test.js +113 -123
- package/dist/runSequentially.test.js +8 -5
- package/dist/services/HandledError.d.ts +1 -1
- 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/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 +50 -27
- 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/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 +3 -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/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/inquirer.private.test.js +4 -15
- 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.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/ui/maybeSetupRepo.js +0 -6
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -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,16 +45,31 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
43
45
|
exports.createStatusComment = createStatusComment;
|
|
44
46
|
function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
45
47
|
const { repoName, repoOwner, autoMerge } = options;
|
|
46
|
-
|
|
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
|
+
}
|
|
60
|
+
const backportPRCommand = `\n### How to fix\nRe-run the backport manually:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\``;
|
|
61
|
+
const supportSection = '\n\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)';
|
|
47
62
|
if (backportResponse.status === 'failure') {
|
|
48
63
|
return `## ๐ Backport failed
|
|
49
64
|
The pull request could not be backported due to the following error:
|
|
50
65
|
\`${backportResponse.errorMessage}\`
|
|
51
|
-
|
|
52
|
-
${backportPRCommand}
|
|
53
|
-
`;
|
|
66
|
+
${backportPRCommand}${supportSection}`;
|
|
54
67
|
}
|
|
55
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
|
+
})
|
|
56
73
|
.map((result) => {
|
|
57
74
|
if (result.status === 'success') {
|
|
58
75
|
return [
|
|
@@ -61,17 +78,15 @@ ${backportPRCommand}
|
|
|
61
78
|
`[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
|
|
62
79
|
];
|
|
63
80
|
}
|
|
64
|
-
if (result.error.meta?.type === '
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
return ` - [#${c.commit.pullNumber}](${c.commit.pullUrl})`;
|
|
68
|
-
}
|
|
69
|
-
return ` - ${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)} (${(0, commitFormatters_1.getShortSha)(c.commit.sha)})`;
|
|
81
|
+
if (result.error.meta?.type === 'merge-conflict-due-to-missing-backports') {
|
|
82
|
+
const conflictingPullRequests = result.error.meta.commitsWithoutBackports.map((c) => {
|
|
83
|
+
return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)}](${c.commit.pullUrl})`;
|
|
70
84
|
});
|
|
85
|
+
const conflictSection = `<br><br>You might need to backport the following PRs to ${result.targetBranch}:<br>${conflictingPullRequests.join('<br>')}`;
|
|
71
86
|
return [
|
|
72
87
|
'โ',
|
|
73
88
|
result.targetBranch,
|
|
74
|
-
|
|
89
|
+
`**Backport failed because of merge conflicts**${conflictingPullRequests.length > 0 ? conflictSection : ''}`,
|
|
75
90
|
];
|
|
76
91
|
}
|
|
77
92
|
return ['โ', result.targetBranch, result.errorMessage];
|
|
@@ -79,19 +94,27 @@ ${backportPRCommand}
|
|
|
79
94
|
.map((line) => line.join('|'))
|
|
80
95
|
.join('|\n|');
|
|
81
96
|
const table = backportResponse.results.length
|
|
82
|
-
? `| Status | Branch | Result |\n
|
|
97
|
+
? `| Status | Branch | Result |\n|:------:|:------:|:------|\n|${tableBody}|`
|
|
83
98
|
: '';
|
|
84
99
|
const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
|
|
85
100
|
const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}
|
|
89
111
|
const autoMergeMessage = autoMerge && didAnyBackportsSucceed
|
|
90
|
-
? '
|
|
112
|
+
? '\nNote: Successful backport PRs will be merged automatically after passing CI.'
|
|
91
113
|
: '';
|
|
92
114
|
const backportPRCommandMessage = !didAllBackportsSucceed
|
|
93
|
-
? `${backportPRCommand}
|
|
115
|
+
? `${backportPRCommand}`
|
|
94
116
|
: '';
|
|
95
|
-
return
|
|
117
|
+
return `${header}\n\n${table}
|
|
118
|
+
${backportPRCommandMessage}${autoMergeMessage}${supportSection}`;
|
|
96
119
|
}
|
|
97
120
|
exports.getCommentBody = getCommentBody;
|
|
@@ -3,30 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const HandledError_1 = require("../../HandledError");
|
|
4
4
|
const createStatusComment_1 = require("./createStatusComment");
|
|
5
5
|
describe('getCommentBody', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
options: {
|
|
6
|
+
describe('when an unknown error occurs', () => {
|
|
7
|
+
const getParams = (opts) => ({
|
|
8
|
+
options: {
|
|
9
|
+
backportBinary: 'node scripts/backport',
|
|
10
|
+
...opts,
|
|
11
|
+
},
|
|
9
12
|
pullNumber: 55,
|
|
10
13
|
backportResponse: {
|
|
11
14
|
status: 'failure',
|
|
12
15
|
errorMessage: 'A terrible error occured',
|
|
13
16
|
},
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
});
|
|
18
|
+
it('posts a comment when running on ci', () => {
|
|
19
|
+
const params = getParams({ ci: true });
|
|
20
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
21
|
+
"## ๐ Backport failed
|
|
22
|
+
The pull request could not be backported due to the following error:
|
|
23
|
+
\`A terrible error occured\`
|
|
24
|
+
|
|
25
|
+
### How to fix
|
|
26
|
+
Re-run the backport manually:
|
|
27
|
+
\`\`\`
|
|
28
|
+
node scripts/backport --pr 55
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
### Questions ?
|
|
32
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it('does not post a comment when running manually', () => {
|
|
36
|
+
const params = getParams({ ci: false });
|
|
37
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
38
|
+
});
|
|
23
39
|
});
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
describe('when all backports succeed', () => {
|
|
41
|
+
const getParams = (opts) => ({
|
|
26
42
|
options: {
|
|
27
43
|
repoName: 'kibana',
|
|
28
44
|
repoOwner: 'elastic',
|
|
29
45
|
autoMerge: true,
|
|
46
|
+
...opts,
|
|
30
47
|
},
|
|
31
48
|
pullNumber: 55,
|
|
32
49
|
backportResponse: {
|
|
@@ -46,24 +63,48 @@ describe('getCommentBody', () => {
|
|
|
46
63
|
},
|
|
47
64
|
],
|
|
48
65
|
},
|
|
49
|
-
})
|
|
50
|
-
|
|
66
|
+
});
|
|
67
|
+
it('posts a comment on ci', () => {
|
|
68
|
+
const params = getParams({ ci: true });
|
|
69
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
70
|
+
"## ๐ All backports created successfully
|
|
71
|
+
|
|
72
|
+
| Status | Branch | Result |
|
|
73
|
+
|:------:|:------:|:------|
|
|
74
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
75
|
+
|โ
|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
51
76
|
|
|
52
|
-
|
|
53
|
-
|:------:|:------:|:------:|
|
|
54
|
-
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
55
|
-
|โ
|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
77
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
56
78
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
### Questions ?
|
|
80
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
81
|
+
`);
|
|
82
|
+
});
|
|
83
|
+
it('posts a comment when running locally', () => {
|
|
84
|
+
const params = getParams({ ci: false });
|
|
85
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
86
|
+
"## ๐ All backports created successfully
|
|
87
|
+
|
|
88
|
+
| Status | Branch | Result |
|
|
89
|
+
|:------:|:------:|:------|
|
|
90
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
91
|
+
|โ
|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
92
|
+
|
|
93
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
94
|
+
|
|
95
|
+
### Questions ?
|
|
96
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
97
|
+
`);
|
|
98
|
+
});
|
|
60
99
|
});
|
|
61
|
-
|
|
62
|
-
|
|
100
|
+
describe('when all backports fail', () => {
|
|
101
|
+
const getParams = (opts) => ({
|
|
63
102
|
options: {
|
|
64
103
|
repoName: 'kibana',
|
|
65
104
|
repoOwner: 'elastic',
|
|
66
105
|
autoMerge: true,
|
|
106
|
+
backportBinary: 'node scripts/backport',
|
|
107
|
+
...opts,
|
|
67
108
|
},
|
|
68
109
|
pullNumber: 55,
|
|
69
110
|
backportResponse: {
|
|
@@ -83,26 +124,40 @@ describe('getCommentBody', () => {
|
|
|
83
124
|
},
|
|
84
125
|
],
|
|
85
126
|
},
|
|
86
|
-
})
|
|
87
|
-
|
|
127
|
+
});
|
|
128
|
+
it('posts a comment on CI', () => {
|
|
129
|
+
const params = getParams({ ci: true });
|
|
130
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
131
|
+
"## ๐ All backports failed
|
|
88
132
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
133
|
+
| Status | Branch | Result |
|
|
134
|
+
|:------:|:------:|:------|
|
|
135
|
+
|โ|7.x|My boom error!|
|
|
136
|
+
|โ|7.1|My boom error!|
|
|
93
137
|
|
|
94
|
-
|
|
95
|
-
|
|
138
|
+
### How to fix
|
|
139
|
+
Re-run the backport manually:
|
|
140
|
+
\`\`\`
|
|
141
|
+
node scripts/backport --pr 55
|
|
142
|
+
\`\`\`
|
|
96
143
|
|
|
97
|
-
|
|
98
|
-
|
|
144
|
+
### Questions ?
|
|
145
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
146
|
+
`);
|
|
147
|
+
});
|
|
148
|
+
it('does not post a comment when running manaully', () => {
|
|
149
|
+
const params = getParams({ ci: false });
|
|
150
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
151
|
+
});
|
|
99
152
|
});
|
|
100
|
-
|
|
101
|
-
|
|
153
|
+
describe('when some backports fail', () => {
|
|
154
|
+
const getParams = (opts) => ({
|
|
102
155
|
options: {
|
|
103
156
|
repoName: 'kibana',
|
|
104
157
|
repoOwner: 'elastic',
|
|
105
158
|
autoMerge: true,
|
|
159
|
+
backportBinary: 'node scripts/backport',
|
|
160
|
+
...opts,
|
|
106
161
|
},
|
|
107
162
|
pullNumber: 55,
|
|
108
163
|
backportResponse: {
|
|
@@ -122,27 +177,41 @@ describe('getCommentBody', () => {
|
|
|
122
177
|
},
|
|
123
178
|
],
|
|
124
179
|
},
|
|
125
|
-
})
|
|
126
|
-
|
|
180
|
+
});
|
|
181
|
+
it('post a comment when running on CI', () => {
|
|
182
|
+
const params = getParams({ ci: true });
|
|
183
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
184
|
+
"## ๐ Some backports could not be created
|
|
127
185
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
186
|
+
| Status | Branch | Result |
|
|
187
|
+
|:------:|:------:|:------|
|
|
188
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
189
|
+
|โ|7.1|My boom error!|
|
|
132
190
|
|
|
133
|
-
|
|
134
|
-
|
|
191
|
+
### How to fix
|
|
192
|
+
Re-run the backport manually:
|
|
193
|
+
\`\`\`
|
|
194
|
+
node scripts/backport --pr 55
|
|
195
|
+
\`\`\`
|
|
196
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
135
197
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
198
|
+
### Questions ?
|
|
199
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
200
|
+
`);
|
|
201
|
+
});
|
|
202
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
203
|
+
const params = getParams({ ci: false });
|
|
204
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
205
|
+
});
|
|
139
206
|
});
|
|
140
|
-
|
|
141
|
-
|
|
207
|
+
describe('when some backports fail due to conflicts', () => {
|
|
208
|
+
const getParams = (opts) => ({
|
|
142
209
|
options: {
|
|
143
210
|
repoName: 'kibana',
|
|
144
211
|
repoOwner: 'elastic',
|
|
145
212
|
autoMerge: true,
|
|
213
|
+
backportBinary: 'node scripts/backport',
|
|
214
|
+
...opts,
|
|
146
215
|
},
|
|
147
216
|
pullNumber: 55,
|
|
148
217
|
backportResponse: {
|
|
@@ -159,13 +228,22 @@ describe('getCommentBody', () => {
|
|
|
159
228
|
targetBranch: '7.1',
|
|
160
229
|
errorMessage: 'My boom error!',
|
|
161
230
|
error: new HandledError_1.HandledError('Boom!', {
|
|
162
|
-
type: '
|
|
231
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
163
232
|
commitsWithoutBackports: [
|
|
164
233
|
{
|
|
165
234
|
//@ts-expect-error
|
|
166
235
|
commit: {
|
|
167
236
|
pullNumber: 5,
|
|
168
237
|
pullUrl: 'url-to-pr-5',
|
|
238
|
+
originalMessage: 'New Zealand commit message',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
//@ts-expect-error
|
|
243
|
+
commit: {
|
|
244
|
+
pullNumber: 44,
|
|
245
|
+
pullUrl: 'url-to-pr-44',
|
|
246
|
+
originalMessage: 'Australia commit',
|
|
169
247
|
},
|
|
170
248
|
},
|
|
171
249
|
],
|
|
@@ -176,34 +254,38 @@ describe('getCommentBody', () => {
|
|
|
176
254
|
targetBranch: '7.2',
|
|
177
255
|
errorMessage: 'My boom error!',
|
|
178
256
|
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
|
-
],
|
|
257
|
+
type: 'merge-conflict-due-to-missing-backports',
|
|
258
|
+
commitsWithoutBackports: [],
|
|
189
259
|
}),
|
|
190
260
|
},
|
|
191
261
|
],
|
|
192
262
|
},
|
|
193
|
-
})
|
|
194
|
-
|
|
263
|
+
});
|
|
264
|
+
it('posts a comment when running on CI', () => {
|
|
265
|
+
const params = getParams({ ci: true });
|
|
266
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
267
|
+
"## ๐ Some backports could not be created
|
|
195
268
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
269
|
+
| Status | Branch | Result |
|
|
270
|
+
|:------:|:------:|:------|
|
|
271
|
+
|โ
|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
272
|
+
|โ|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)|
|
|
273
|
+
|โ|7.2|**Backport failed because of merge conflicts**|
|
|
201
274
|
|
|
202
|
-
|
|
203
|
-
|
|
275
|
+
### How to fix
|
|
276
|
+
Re-run the backport manually:
|
|
277
|
+
\`\`\`
|
|
278
|
+
node scripts/backport --pr 55
|
|
279
|
+
\`\`\`
|
|
280
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
204
281
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
282
|
+
### Questions ?
|
|
283
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
284
|
+
`);
|
|
285
|
+
});
|
|
286
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
287
|
+
const params = getParams({ ci: false });
|
|
288
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
289
|
+
});
|
|
208
290
|
});
|
|
209
291
|
});
|
|
@@ -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
|
});
|