backport 6.3.0-beta → 6.3.0-beta-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/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.e2e.private.test.js +278 -0
- package/dist/entrypoint.cli.js +0 -0
- package/dist/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +46 -0
- package/dist/options/ConfigOptions.d.ts +3 -2
- package/dist/options/cliArgs.d.ts +1 -0
- package/dist/options/cliArgs.js +24 -4
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +170 -0
- package/dist/options/config/config.d.ts +2 -7
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/config/readConfigFile.d.ts +2 -7
- package/dist/options/options.d.ts +2 -7
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +369 -0
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +218 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +267 -0
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +518 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +325 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +386 -0
- package/dist/services/github/v3/index.d.ts +1 -0
- package/dist/services/github/v3/index.js +61 -0
- package/dist/services/github/v4/apiRequestV4.js +10 -2
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +82 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -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 -7
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -10
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +15 -24
- package/dist/services/github/v4/getOptionsFromGithub/query.js +17 -25
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/logger.d.ts +3 -15
- package/dist/services/logger.js +10 -50
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +134 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
- package/dist/test/backport-e2e.mutation.test.js +347 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +32 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +59 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +198 -0
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +204 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +5 -3
- package/yarn.lock +5 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const HandledError_1 = require("../../HandledError");
|
|
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: [{ sourcePullRequest: { number: 100 } }],
|
|
31
|
+
status: 'failure',
|
|
32
|
+
error: new Error(`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
|
+
});
|
|
40
|
+
describe('getCommentBody', () => {
|
|
41
|
+
describe('when an unknown error occurs', () => {
|
|
42
|
+
const getParams = (opts) => ({
|
|
43
|
+
options: {
|
|
44
|
+
backportBinary: 'node scripts/backport',
|
|
45
|
+
...opts,
|
|
46
|
+
},
|
|
47
|
+
pullNumber: 55,
|
|
48
|
+
backportResponse: {
|
|
49
|
+
status: 'failure',
|
|
50
|
+
error: new Error('A terrible error occured'),
|
|
51
|
+
},
|
|
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
|
+
### Manual backport
|
|
61
|
+
To create the backport manually run:
|
|
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
|
+
<!--- Backport version: 1.2.3 -->"
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
it('does not post a comment when running manually', () => {
|
|
72
|
+
const params = getParams({ ci: false });
|
|
73
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('when all backports succeed', () => {
|
|
77
|
+
const getParams = (opts) => ({
|
|
78
|
+
options: {
|
|
79
|
+
repoName: 'kibana',
|
|
80
|
+
repoOwner: 'elastic',
|
|
81
|
+
autoMerge: true,
|
|
82
|
+
...opts,
|
|
83
|
+
},
|
|
84
|
+
pullNumber: 55,
|
|
85
|
+
backportResponse: {
|
|
86
|
+
status: 'success',
|
|
87
|
+
results: [
|
|
88
|
+
{
|
|
89
|
+
status: 'success',
|
|
90
|
+
targetBranch: '7.x',
|
|
91
|
+
pullRequestNumber: 55,
|
|
92
|
+
pullRequestUrl: 'url-to-pr',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
status: 'success',
|
|
96
|
+
targetBranch: '7.1',
|
|
97
|
+
pullRequestNumber: 66,
|
|
98
|
+
pullRequestUrl: 'url-to-pr',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
it('posts a comment on ci', () => {
|
|
104
|
+
const params = getParams({ ci: true });
|
|
105
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
106
|
+
"## 💚 All backports created successfully
|
|
107
|
+
|
|
108
|
+
| Status | Branch | Result |
|
|
109
|
+
|:------:|:------:|:------|
|
|
110
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
111
|
+
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
112
|
+
|
|
113
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
114
|
+
|
|
115
|
+
### Questions ?
|
|
116
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
117
|
+
<!--- Backport version: 1.2.3 -->"
|
|
118
|
+
`);
|
|
119
|
+
});
|
|
120
|
+
it('posts a comment when running locally', () => {
|
|
121
|
+
const params = getParams({ ci: false });
|
|
122
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
123
|
+
"## 💚 All backports created successfully
|
|
124
|
+
|
|
125
|
+
| Status | Branch | Result |
|
|
126
|
+
|:------:|:------:|:------|
|
|
127
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
128
|
+
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
129
|
+
|
|
130
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
131
|
+
|
|
132
|
+
### Questions ?
|
|
133
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
134
|
+
<!--- Backport version: 1.2.3 -->"
|
|
135
|
+
`);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('when all backports fail', () => {
|
|
139
|
+
const getParams = (opts) => ({
|
|
140
|
+
options: {
|
|
141
|
+
repoName: 'kibana',
|
|
142
|
+
repoOwner: 'elastic',
|
|
143
|
+
autoMerge: true,
|
|
144
|
+
backportBinary: 'node scripts/backport',
|
|
145
|
+
...opts,
|
|
146
|
+
},
|
|
147
|
+
pullNumber: 55,
|
|
148
|
+
backportResponse: {
|
|
149
|
+
status: 'success',
|
|
150
|
+
results: [
|
|
151
|
+
{
|
|
152
|
+
status: 'failure',
|
|
153
|
+
targetBranch: '7.x',
|
|
154
|
+
error: new Error('My boom error!'),
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
status: 'failure',
|
|
158
|
+
targetBranch: '7.1',
|
|
159
|
+
error: new Error('My boom error!'),
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
it('posts a comment on CI', () => {
|
|
165
|
+
const params = getParams({ ci: true });
|
|
166
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
167
|
+
"## 💔 All backports failed
|
|
168
|
+
|
|
169
|
+
| Status | Branch | Result |
|
|
170
|
+
|:------:|:------:|:------|
|
|
171
|
+
|❌|7.x|My boom error!|
|
|
172
|
+
|❌|7.1|My boom error!|
|
|
173
|
+
|
|
174
|
+
### Manual backport
|
|
175
|
+
To create the backport manually run:
|
|
176
|
+
\`\`\`
|
|
177
|
+
node scripts/backport --pr 55
|
|
178
|
+
\`\`\`
|
|
179
|
+
|
|
180
|
+
### Questions ?
|
|
181
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
182
|
+
<!--- Backport version: 1.2.3 -->"
|
|
183
|
+
`);
|
|
184
|
+
});
|
|
185
|
+
it('does not post a comment when running manaully', () => {
|
|
186
|
+
const params = getParams({ ci: false });
|
|
187
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('when some backports fail', () => {
|
|
191
|
+
const getParams = (opts) => ({
|
|
192
|
+
options: {
|
|
193
|
+
repoName: 'kibana',
|
|
194
|
+
repoOwner: 'elastic',
|
|
195
|
+
autoMerge: true,
|
|
196
|
+
backportBinary: 'node scripts/backport',
|
|
197
|
+
...opts,
|
|
198
|
+
},
|
|
199
|
+
pullNumber: 55,
|
|
200
|
+
backportResponse: {
|
|
201
|
+
status: 'success',
|
|
202
|
+
results: [
|
|
203
|
+
{
|
|
204
|
+
status: 'success',
|
|
205
|
+
targetBranch: '7.x',
|
|
206
|
+
pullRequestNumber: 55,
|
|
207
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
status: 'failure',
|
|
211
|
+
targetBranch: '7.1',
|
|
212
|
+
error: new Error('My boom error!'),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
it('post a comment when running on CI', () => {
|
|
218
|
+
const params = getParams({ ci: true });
|
|
219
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
220
|
+
"## 💔 Some backports could not be created
|
|
221
|
+
|
|
222
|
+
| Status | Branch | Result |
|
|
223
|
+
|:------:|:------:|:------|
|
|
224
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
225
|
+
|❌|7.1|My boom error!|
|
|
226
|
+
|
|
227
|
+
### Manual backport
|
|
228
|
+
To create the backport manually run:
|
|
229
|
+
\`\`\`
|
|
230
|
+
node scripts/backport --pr 55
|
|
231
|
+
\`\`\`
|
|
232
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
233
|
+
|
|
234
|
+
### Questions ?
|
|
235
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
236
|
+
<!--- Backport version: 1.2.3 -->"
|
|
237
|
+
`);
|
|
238
|
+
});
|
|
239
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
240
|
+
const params = getParams({ ci: false });
|
|
241
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
describe('when some backports fail due to conflicts', () => {
|
|
245
|
+
const getParams = (opts) => ({
|
|
246
|
+
options: {
|
|
247
|
+
repoName: 'kibana',
|
|
248
|
+
repoOwner: 'elastic',
|
|
249
|
+
autoMerge: true,
|
|
250
|
+
backportBinary: 'node scripts/backport',
|
|
251
|
+
...opts,
|
|
252
|
+
},
|
|
253
|
+
pullNumber: 55,
|
|
254
|
+
backportResponse: {
|
|
255
|
+
status: 'success',
|
|
256
|
+
results: [
|
|
257
|
+
{
|
|
258
|
+
status: 'success',
|
|
259
|
+
targetBranch: '7.x',
|
|
260
|
+
pullRequestNumber: 55,
|
|
261
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
status: 'failure',
|
|
265
|
+
targetBranch: '7.1',
|
|
266
|
+
error: new HandledError_1.HandledError({
|
|
267
|
+
code: 'merge-conflict-exception',
|
|
268
|
+
commitsWithoutBackports: [
|
|
269
|
+
//@ts-expect-error
|
|
270
|
+
{
|
|
271
|
+
commit: {
|
|
272
|
+
sourceBranch: 'master',
|
|
273
|
+
sourcePullRequest: {
|
|
274
|
+
number: 5,
|
|
275
|
+
url: 'url-to-pr-5',
|
|
276
|
+
mergeCommit: {
|
|
277
|
+
sha: '',
|
|
278
|
+
message: 'New Zealand commit message',
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
sourceCommit: {
|
|
282
|
+
committedDate: '',
|
|
283
|
+
sha: '',
|
|
284
|
+
message: 'New Zealand commit message',
|
|
285
|
+
},
|
|
286
|
+
expectedTargetPullRequests: [],
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
//@ts-expect-error
|
|
291
|
+
commit: {
|
|
292
|
+
sourcePullRequest: {
|
|
293
|
+
number: 44,
|
|
294
|
+
url: 'url-to-pr-44',
|
|
295
|
+
mergeCommit: {
|
|
296
|
+
sha: '',
|
|
297
|
+
message: 'Australia commit',
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
sourceCommit: {
|
|
301
|
+
committedDate: '',
|
|
302
|
+
sha: '',
|
|
303
|
+
message: 'Australia commit',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
}),
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
status: 'failure',
|
|
312
|
+
targetBranch: '7.2',
|
|
313
|
+
error: new HandledError_1.HandledError({
|
|
314
|
+
code: 'merge-conflict-exception',
|
|
315
|
+
commitsWithoutBackports: [],
|
|
316
|
+
}),
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
it('posts a comment when running on CI', () => {
|
|
322
|
+
const params = getParams({ ci: true });
|
|
323
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
324
|
+
"## 💔 Some backports could not be created
|
|
325
|
+
|
|
326
|
+
| Status | Branch | Result |
|
|
327
|
+
|:------:|:------:|:------|
|
|
328
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
329
|
+
|❌|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)|
|
|
330
|
+
|❌|7.2|**Backport failed because of merge conflicts**|
|
|
331
|
+
|
|
332
|
+
### Manual backport
|
|
333
|
+
To create the backport manually run:
|
|
334
|
+
\`\`\`
|
|
335
|
+
node scripts/backport --pr 55
|
|
336
|
+
\`\`\`
|
|
337
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
338
|
+
|
|
339
|
+
### Questions ?
|
|
340
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
341
|
+
<!--- Backport version: 1.2.3 -->"
|
|
342
|
+
`);
|
|
343
|
+
});
|
|
344
|
+
it('does not post a comment when running manually because some backports failed', () => {
|
|
345
|
+
const params = getParams({ ci: false });
|
|
346
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
describe('when all backports fail due to missing branches', () => {
|
|
350
|
+
const getParams = (opts) => ({
|
|
351
|
+
options: {
|
|
352
|
+
repoName: 'kibana',
|
|
353
|
+
repoOwner: 'elastic',
|
|
354
|
+
autoMerge: true,
|
|
355
|
+
backportBinary: 'node scripts/backport',
|
|
356
|
+
...opts,
|
|
357
|
+
},
|
|
358
|
+
pullNumber: 55,
|
|
359
|
+
backportResponse: {
|
|
360
|
+
status: 'failure',
|
|
361
|
+
error: new HandledError_1.HandledError({ code: 'no-branches-exception' }),
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
it('posts a comment when running on CI', () => {
|
|
365
|
+
const params = getParams({ ci: true });
|
|
366
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
367
|
+
"## ⚪ Backport skipped
|
|
368
|
+
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.
|
|
369
|
+
|
|
370
|
+
### Manual backport
|
|
371
|
+
To create the backport manually run:
|
|
372
|
+
\`\`\`
|
|
373
|
+
node scripts/backport --pr 55
|
|
374
|
+
\`\`\`
|
|
375
|
+
|
|
376
|
+
### Questions ?
|
|
377
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
378
|
+
<!--- Backport version: 1.2.3 -->"
|
|
379
|
+
`);
|
|
380
|
+
});
|
|
381
|
+
it('does not post a comment when running manually', () => {
|
|
382
|
+
const params = getParams({ ci: false });
|
|
383
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const core = __importStar(require("@actions/core"));
|
|
23
|
+
const exec_1 = require("@actions/exec");
|
|
24
|
+
const github_1 = require("@actions/github");
|
|
25
|
+
const backport_1 = require("backport");
|
|
26
|
+
async function init() {
|
|
27
|
+
const { payload, repo } = github_1.context;
|
|
28
|
+
if (!payload.pull_request) {
|
|
29
|
+
throw Error('Only pull_request events are supported.');
|
|
30
|
+
}
|
|
31
|
+
const pullRequest = payload.pull_request;
|
|
32
|
+
const prAuthor = pullRequest.user.login;
|
|
33
|
+
const accessToken = core.getInput('github_token', { required: true });
|
|
34
|
+
const commitUser = core.getInput('commit_user', { required: false });
|
|
35
|
+
const commitEmail = core.getInput('commit_email', { required: false });
|
|
36
|
+
const autoMerge = core.getInput('auto_merge', { required: false }) === 'true';
|
|
37
|
+
const autoMergeMethod = core.getInput('auto_merge_method', {
|
|
38
|
+
required: false,
|
|
39
|
+
});
|
|
40
|
+
const targetPRLabels = core
|
|
41
|
+
.getInput('target_pr_labels', { required: false })
|
|
42
|
+
.split(',')
|
|
43
|
+
.map((label) => label.trim());
|
|
44
|
+
await (0, exec_1.exec)(`git config --global user.name "${commitUser}"`);
|
|
45
|
+
await (0, exec_1.exec)(`git config --global user.email "${commitEmail}"`);
|
|
46
|
+
await (0, backport_1.backportRun)({
|
|
47
|
+
repoOwner: repo.owner,
|
|
48
|
+
repoName: repo.repo,
|
|
49
|
+
accessToken,
|
|
50
|
+
ci: true,
|
|
51
|
+
pullNumber: pullRequest.number,
|
|
52
|
+
targetPRLabels: targetPRLabels,
|
|
53
|
+
assignees: [prAuthor],
|
|
54
|
+
autoMerge: autoMerge,
|
|
55
|
+
autoMergeMethod: autoMergeMethod,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
init().catch((error) => {
|
|
59
|
+
console.error('An error occurred', error);
|
|
60
|
+
core.setFailed(error.message);
|
|
61
|
+
});
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
9
|
const HandledError_1 = require("../../HandledError");
|
|
9
10
|
const logger_1 = require("../../logger");
|
|
10
11
|
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
|
|
@@ -46,9 +47,11 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
46
47
|
}
|
|
47
48
|
exports.apiRequestV4 = apiRequestV4;
|
|
48
49
|
function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
|
|
49
|
-
|
|
50
|
+
const gqlQueryName = getGqlQueryName(query);
|
|
51
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${axiosResponse.status})`);
|
|
50
52
|
const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
|
|
51
|
-
logMethod(
|
|
53
|
+
logMethod(`Query name ${gqlQueryName}`);
|
|
54
|
+
logMethod(`Query: ${query}`);
|
|
52
55
|
logMethod('Variables:', variables);
|
|
53
56
|
logMethod('Response headers:', axiosResponse.headers);
|
|
54
57
|
logMethod('Response data:', axiosResponse.data);
|
|
@@ -63,3 +66,8 @@ class GithubV4Exception extends Error {
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
exports.GithubV4Exception = GithubV4Exception;
|
|
69
|
+
function getGqlQueryName(query) {
|
|
70
|
+
const ast = (0, graphql_tag_1.default)(query);
|
|
71
|
+
//@ts-expect-error
|
|
72
|
+
return ast.definitions[0].name.value;
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const nockHelpers_1 = require("../../../test/nockHelpers");
|
|
8
|
+
const HandledError_1 = require("../../HandledError");
|
|
9
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
10
|
+
describe('apiRequestV4', () => {
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
nock_1.default.cleanAll();
|
|
13
|
+
});
|
|
14
|
+
describe('when request succeeds', () => {
|
|
15
|
+
let res;
|
|
16
|
+
let commitsByAuthorCalls;
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
19
|
+
name: 'MyQuery',
|
|
20
|
+
statusCode: 200,
|
|
21
|
+
body: { data: { hello: 'world' } },
|
|
22
|
+
});
|
|
23
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
24
|
+
accessToken: 'myAccessToken',
|
|
25
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
26
|
+
query: 'query MyQuery{ foo }',
|
|
27
|
+
variables: { foo: 'bar' },
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('should return correct response', async () => {
|
|
31
|
+
expect(res).toEqual({ hello: 'world' });
|
|
32
|
+
});
|
|
33
|
+
it('should call with correct args', async () => {
|
|
34
|
+
expect(commitsByAuthorCalls).toEqual([
|
|
35
|
+
{
|
|
36
|
+
query: 'query MyQuery{ foo }',
|
|
37
|
+
variables: { foo: 'bar' },
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('when request fails with error messages', () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
45
|
+
name: 'MyQuery',
|
|
46
|
+
statusCode: 200,
|
|
47
|
+
body: {
|
|
48
|
+
errors: [{ message: 'some error' }, { message: 'some other error' }],
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should return error containing the error messages', async () => {
|
|
53
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
54
|
+
accessToken: 'myAccessToken',
|
|
55
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
56
|
+
query: 'query MyQuery{ foo }',
|
|
57
|
+
variables: {
|
|
58
|
+
foo: 'bar',
|
|
59
|
+
},
|
|
60
|
+
})).rejects.toThrowError(new HandledError_1.HandledError(`some error,some other error (Github API v4)`));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('when request fails without error messages', () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
66
|
+
name: 'MyQuery',
|
|
67
|
+
statusCode: 500,
|
|
68
|
+
body: { data: { foo: 'bar' } },
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it('should return parsed github error', async () => {
|
|
72
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
73
|
+
accessToken: 'myAccessToken',
|
|
74
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
75
|
+
query: 'query MyQuery{ foo }',
|
|
76
|
+
variables: {
|
|
77
|
+
foo: 'bar',
|
|
78
|
+
},
|
|
79
|
+
})).rejects.toThrowError('Request failed with status code 500');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const rest_1 = require("@octokit/rest");
|
|
8
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
9
|
+
const createPullRequest_1 = require("../v3/createPullRequest");
|
|
10
|
+
const disablePullRequestAutoMerge_1 = require("./disablePullRequestAutoMerge");
|
|
11
|
+
const enablePullRequestAutoMerge_1 = require("./enablePullRequestAutoMerge");
|
|
12
|
+
const fetchPullRequestAutoMergeMethod_1 = require("./fetchPullRequestAutoMergeMethod");
|
|
13
|
+
// The test repo requires auto-merge being enabled in options, as well as all merge types enabled (merge, squash, rebase)
|
|
14
|
+
// The test pull requests should be open, and not currently able to be merged (e.g. because it requires an approval),
|
|
15
|
+
// otherwise it will be merged when auto-merge is turned on
|
|
16
|
+
const TEST_REPO_OWNER = 'backport-org';
|
|
17
|
+
const TEST_REPO_NAME = 'repo-with-auto-merge-enabled';
|
|
18
|
+
// commit to create new branch from
|
|
19
|
+
// https://github.com/backport-org/repo-with-auto-merge-enabled/commit/1a88d210f90a22e2a06253c5760909833dc820e9
|
|
20
|
+
const COMMIT_SHA = '1a88d210f90a22e2a06253c5760909833dc820e9';
|
|
21
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
async function closePr(octokit, pullNumber) {
|
|
23
|
+
await octokit.pulls.update({
|
|
24
|
+
owner: TEST_REPO_OWNER,
|
|
25
|
+
repo: TEST_REPO_NAME,
|
|
26
|
+
pull_number: pullNumber,
|
|
27
|
+
state: 'closed',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function createPr(options, branchName) {
|
|
31
|
+
const prPayload = {
|
|
32
|
+
base: 'main',
|
|
33
|
+
head: branchName,
|
|
34
|
+
body: 'testing...',
|
|
35
|
+
owner: TEST_REPO_OWNER,
|
|
36
|
+
repo: TEST_REPO_NAME,
|
|
37
|
+
title: 'my pr title',
|
|
38
|
+
};
|
|
39
|
+
const { number } = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
40
|
+
return number;
|
|
41
|
+
}
|
|
42
|
+
async function deleteBranch(octokit, branchName) {
|
|
43
|
+
await octokit.git.deleteRef({
|
|
44
|
+
owner: TEST_REPO_OWNER,
|
|
45
|
+
repo: TEST_REPO_NAME,
|
|
46
|
+
ref: `heads/${branchName}`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function createBranch(octokit, branchName, sha) {
|
|
50
|
+
await octokit.git.createRef({
|
|
51
|
+
owner: TEST_REPO_OWNER,
|
|
52
|
+
repo: TEST_REPO_NAME,
|
|
53
|
+
ref: `refs/heads/${branchName}`,
|
|
54
|
+
sha,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// causes flaky test runs on CI because parallel builds are racing each other
|
|
58
|
+
// might also be an issue with Github's API being slow at updating after a mutation happens
|
|
59
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
60
|
+
describe.skip('enablePullRequestAutoMerge', () => {
|
|
61
|
+
let pullNumber;
|
|
62
|
+
let branchName;
|
|
63
|
+
let octokit;
|
|
64
|
+
let options;
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
67
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
68
|
+
branchName = `test-${randomString}`;
|
|
69
|
+
options = {
|
|
70
|
+
accessToken,
|
|
71
|
+
repoOwner: TEST_REPO_OWNER,
|
|
72
|
+
repoName: TEST_REPO_NAME,
|
|
73
|
+
};
|
|
74
|
+
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
75
|
+
await createBranch(octokit, branchName, COMMIT_SHA);
|
|
76
|
+
pullNumber = await createPr(options, branchName);
|
|
77
|
+
});
|
|
78
|
+
// cleanup
|
|
79
|
+
afterAll(async () => {
|
|
80
|
+
await closePr(octokit, pullNumber);
|
|
81
|
+
await deleteBranch(octokit, branchName);
|
|
82
|
+
});
|
|
83
|
+
// reset auto-merge state between runs
|
|
84
|
+
afterEach(async () => {
|
|
85
|
+
await (0, disablePullRequestAutoMerge_1.disablePullRequestAutoMerge)(options, pullNumber);
|
|
86
|
+
});
|
|
87
|
+
it('should initially have auto-merge disabled', async () => {
|
|
88
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
89
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
90
|
+
});
|
|
91
|
+
it('should enable auto-merge via merge', async () => {
|
|
92
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
93
|
+
// ensure Github API reflects the change before querying
|
|
94
|
+
await sleep(100);
|
|
95
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
96
|
+
expect(autoMergeMethod).toBe('MERGE');
|
|
97
|
+
});
|
|
98
|
+
it('should not enable auto-merge via rebase because it is disallowed', async () => {
|
|
99
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'rebase' }, pullNumber);
|
|
100
|
+
// ensure Github API reflects the change before querying
|
|
101
|
+
await sleep(100);
|
|
102
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
103
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
104
|
+
});
|
|
105
|
+
it('should enable auto-merge via squash', async () => {
|
|
106
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'squash' }, pullNumber);
|
|
107
|
+
// ensure Github API reflects the change before querying
|
|
108
|
+
await sleep(100);
|
|
109
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
110
|
+
expect(autoMergeMethod).toBe('SQUASH');
|
|
111
|
+
});
|
|
112
|
+
});
|