backport 7.2.0-beta.2 → 7.3.0-beta.1

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.
Files changed (135) hide show
  1. package/README.md +10 -5
  2. package/dist/entrypoint.cli.d.ts +0 -1
  3. package/dist/entrypoint.cli.js +0 -1
  4. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  5. package/dist/entrypoint.cli.private.test.js +47 -0
  6. package/dist/options/ConfigOptions.d.ts +2 -0
  7. package/dist/options/cliArgs.test.d.ts +1 -0
  8. package/dist/options/cliArgs.test.js +182 -0
  9. package/dist/options/config/config.d.ts +2 -0
  10. package/dist/options/config/config.test.d.ts +1 -0
  11. package/dist/options/config/config.test.js +32 -0
  12. package/dist/options/config/globalConfig.test.d.ts +1 -0
  13. package/dist/options/config/globalConfig.test.js +61 -0
  14. package/dist/options/config/projectConfig.test.d.ts +1 -0
  15. package/dist/options/config/projectConfig.test.js +109 -0
  16. package/dist/options/config/readConfigFile.d.ts +2 -0
  17. package/dist/options/options.d.ts +2 -0
  18. package/dist/options/options.test.d.ts +1 -0
  19. package/dist/options/options.test.js +384 -0
  20. package/dist/runSequentially.js +2 -2
  21. package/dist/runSequentially.test.d.ts +1 -0
  22. package/dist/runSequentially.test.js +243 -0
  23. package/dist/scripts/postinstall.test.d.ts +1 -0
  24. package/dist/scripts/postinstall.test.js +53 -0
  25. package/dist/services/env.test.d.ts +1 -0
  26. package/dist/services/env.test.js +21 -0
  27. package/dist/services/git.d.ts +11 -4
  28. package/dist/services/git.integration.test.d.ts +1 -0
  29. package/dist/services/git.integration.test.js +286 -0
  30. package/dist/services/git.js +34 -16
  31. package/dist/services/git.test.d.ts +1 -0
  32. package/dist/services/git.test.js +543 -0
  33. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  34. package/dist/services/github/commitFormatters.test.js +11 -0
  35. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  36. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  37. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  38. package/dist/services/github/v3/createPullRequest.test.js +377 -0
  39. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  40. package/dist/services/github/v3/createStatusComment.test.js +396 -0
  41. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  42. package/dist/services/github/v4/apiRequestV4.test.js +109 -0
  43. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  44. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  45. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  46. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  47. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  48. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +94 -0
  49. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +135 -0
  51. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +117 -0
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
  55. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  56. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  57. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +104 -0
  59. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  60. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  61. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  62. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  63. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  64. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  65. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
  66. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
  67. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  68. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  69. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  70. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +176 -0
  71. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  72. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  73. package/dist/services/prompt.test.d.ts +1 -0
  74. package/dist/services/prompt.test.js +139 -0
  75. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  76. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  77. package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
  78. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
  79. package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
  80. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  81. package/dist/services/sourceCommit/parseSourceCommit.test.js +226 -0
  82. package/dist/test/ExecError.d.ts +16 -0
  83. package/dist/test/ExecError.js +15 -0
  84. package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
  85. package/dist/test/e2e/cli/cli.private.test.js +215 -0
  86. package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
  87. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
  88. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
  89. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
  90. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
  91. package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
  92. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
  93. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
  94. package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
  95. package/dist/test/e2e/cli.e2e.private.test.js +433 -0
  96. package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
  97. package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
  98. package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
  99. package/dist/test/e2e/module.e2e.private.test.js +369 -0
  100. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  101. package/dist/test/handleUnbackportedPullRequests.private.test.js +56 -0
  102. package/dist/test/mockConfigFiles.d.ts +5 -0
  103. package/dist/test/mockConfigFiles.js +21 -0
  104. package/dist/test/mocks.d.ts +10 -0
  105. package/dist/test/mocks.js +23 -0
  106. package/dist/test/nockHelpers.d.ts +16 -0
  107. package/dist/test/nockHelpers.js +36 -0
  108. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  109. package/dist/test/private/getDevAccessToken.js +12 -0
  110. package/dist/test/sandbox.d.ts +5 -0
  111. package/dist/test/sandbox.js +43 -0
  112. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  113. package/dist/test/setupFiles/automatic-mocks.js +63 -0
  114. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  115. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  116. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +469 -0
  117. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  118. package/dist/ui/getCommitsWithoutBackports.test.js +331 -0
  119. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  120. package/dist/ui/getTargetBranches.test.js +200 -0
  121. package/dist/ui/maybeSetupRepo.js +7 -3
  122. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  123. package/dist/ui/maybeSetupRepo.test.js +238 -0
  124. package/dist/ui/ora.d.ts +1 -1
  125. package/dist/ui/ora.js +2 -2
  126. package/dist/ui/setupRepo.d.ts +3 -0
  127. package/dist/ui/setupRepo.js +88 -0
  128. package/dist/ui/setupRepo.test.d.ts +1 -0
  129. package/dist/ui/setupRepo.test.js +288 -0
  130. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  131. package/dist/utils/excludeUndefined.test.js +24 -0
  132. package/dist/utils/packageVersion.d.ts +1 -1
  133. package/dist/utils/packageVersion.js +1 -1
  134. package/package.json +6 -6
  135. package/yarn.lock +3 -3
@@ -0,0 +1,396 @@
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-mocked -->"
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-mocked -->"
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-mocked -->"
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-mocked -->"
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-mocked -->"
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
+ {
270
+ formatted: 'some-formatted-text',
271
+ commit: {
272
+ author: {
273
+ email: 'soren.louv@elastic.co',
274
+ name: 'Søren Louv-Jansen',
275
+ },
276
+ sourceBranch: 'master',
277
+ sourcePullRequest: {
278
+ number: 5,
279
+ url: 'url-to-pr-5',
280
+ mergeCommit: {
281
+ sha: '',
282
+ message: 'New Zealand commit message',
283
+ },
284
+ },
285
+ sourceCommit: {
286
+ committedDate: '',
287
+ sha: '',
288
+ message: 'New Zealand commit message',
289
+ },
290
+ expectedTargetPullRequests: [],
291
+ },
292
+ },
293
+ {
294
+ formatted: 'some-formatted-text',
295
+ commit: {
296
+ author: {
297
+ email: 'soren.louv@elastic.co',
298
+ name: 'Søren Louv-Jansen',
299
+ },
300
+ sourceBranch: 'master',
301
+ sourcePullRequest: {
302
+ number: 44,
303
+ url: 'url-to-pr-44',
304
+ mergeCommit: {
305
+ sha: '',
306
+ message: 'Australia commit',
307
+ },
308
+ },
309
+ sourceCommit: {
310
+ committedDate: '',
311
+ sha: '',
312
+ message: 'Australia commit',
313
+ },
314
+ expectedTargetPullRequests: [],
315
+ },
316
+ },
317
+ ],
318
+ }),
319
+ },
320
+ {
321
+ status: 'failure',
322
+ targetBranch: '7.2',
323
+ error: new HandledError_1.HandledError({
324
+ code: 'merge-conflict-exception',
325
+ commitsWithoutBackports: [],
326
+ }),
327
+ },
328
+ ],
329
+ },
330
+ });
331
+ it('posts a comment when running on CI', () => {
332
+ const params = getParams({ ci: true });
333
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
334
+ "## 💔 Some backports could not be created
335
+
336
+ | Status | Branch | Result |
337
+ |:------:|:------:|:------|
338
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
339
+ |❌|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)|
340
+ |❌|7.2|**Backport failed because of merge conflicts**|
341
+
342
+ ### Manual backport
343
+ To create the backport manually run:
344
+ \`\`\`
345
+ node scripts/backport --pr 55
346
+ \`\`\`
347
+ Note: Successful backport PRs will be merged automatically after passing CI.
348
+
349
+ ### Questions ?
350
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
351
+ <!--- Backport version: 1.2.3-mocked -->"
352
+ `);
353
+ });
354
+ it('does not post a comment when running manually because some backports failed', () => {
355
+ const params = getParams({ ci: false });
356
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
357
+ });
358
+ });
359
+ describe('when all backports fail due to missing branches', () => {
360
+ const getParams = (opts) => ({
361
+ options: {
362
+ repoName: 'kibana',
363
+ repoOwner: 'elastic',
364
+ autoMerge: true,
365
+ backportBinary: 'node scripts/backport',
366
+ ...opts,
367
+ },
368
+ pullNumber: 55,
369
+ backportResponse: {
370
+ status: 'failure',
371
+ error: new HandledError_1.HandledError({ code: 'no-branches-exception' }),
372
+ },
373
+ });
374
+ it('posts a comment when running on CI', () => {
375
+ const params = getParams({ ci: true });
376
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
377
+ "## ⚪ Backport skipped
378
+ 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.
379
+
380
+ ### Manual backport
381
+ To create the backport manually run:
382
+ \`\`\`
383
+ node scripts/backport --pr 55
384
+ \`\`\`
385
+
386
+ ### Questions ?
387
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
388
+ <!--- Backport version: 1.2.3-mocked -->"
389
+ `);
390
+ });
391
+ it('does not post a comment when running manually', () => {
392
+ const params = getParams({ ci: false });
393
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
394
+ });
395
+ });
396
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
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 graphql_tag_1 = __importDefault(require("graphql-tag"));
7
+ const nock_1 = __importDefault(require("nock"));
8
+ const nockHelpers_1 = require("../../../test/nockHelpers");
9
+ const HandledError_1 = require("../../HandledError");
10
+ const apiRequestV4_1 = require("./apiRequestV4");
11
+ describe('apiRequestV4', () => {
12
+ afterEach(() => {
13
+ nock_1.default.cleanAll();
14
+ });
15
+ describe('when request succeeds', () => {
16
+ let res;
17
+ let commitsByAuthorCalls;
18
+ beforeEach(async () => {
19
+ commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
20
+ name: 'MyQuery',
21
+ statusCode: 200,
22
+ body: { data: { viewer: { login: 'sqren' } } },
23
+ });
24
+ res = await (0, apiRequestV4_1.apiRequestV4)({
25
+ accessToken: 'myAccessToken',
26
+ githubApiBaseUrlV4: 'http://localhost/graphql',
27
+ query: (0, graphql_tag_1.default) `
28
+ query MyQuery {
29
+ viewer {
30
+ login
31
+ }
32
+ }
33
+ `,
34
+ variables: { foo: 'bar' },
35
+ });
36
+ });
37
+ it('should return correct response', async () => {
38
+ expect(res).toEqual({ viewer: { login: 'sqren' } });
39
+ });
40
+ it('should call with correct args', async () => {
41
+ expect(commitsByAuthorCalls).toMatchInlineSnapshot(`
42
+ Array [
43
+ Object {
44
+ "query": "query MyQuery {
45
+ viewer {
46
+ login
47
+ }
48
+ }",
49
+ "variables": Object {
50
+ "foo": "bar",
51
+ },
52
+ },
53
+ ]
54
+ `);
55
+ });
56
+ });
57
+ describe('when request fails with error messages', () => {
58
+ beforeEach(() => {
59
+ (0, nockHelpers_1.mockGqlRequest)({
60
+ name: 'MyQuery',
61
+ statusCode: 200,
62
+ body: {
63
+ errors: [{ message: 'some error' }, { message: 'some other error' }],
64
+ },
65
+ });
66
+ });
67
+ it('should return error containing the error messages', async () => {
68
+ return expect((0, apiRequestV4_1.apiRequestV4)({
69
+ accessToken: 'myAccessToken',
70
+ githubApiBaseUrlV4: 'http://localhost/graphql',
71
+ query: (0, graphql_tag_1.default) `
72
+ query MyQuery {
73
+ viewer {
74
+ login
75
+ }
76
+ }
77
+ `,
78
+ variables: {
79
+ foo: 'bar',
80
+ },
81
+ })).rejects.toThrowError(new HandledError_1.HandledError(`some error,some other error (Github API v4)`));
82
+ });
83
+ });
84
+ describe('when request fails without error messages', () => {
85
+ beforeEach(() => {
86
+ (0, nockHelpers_1.mockGqlRequest)({
87
+ name: 'MyQuery',
88
+ statusCode: 500,
89
+ body: { data: { foo: 'bar' } },
90
+ });
91
+ });
92
+ it('should return parsed github error', async () => {
93
+ return expect((0, apiRequestV4_1.apiRequestV4)({
94
+ accessToken: 'myAccessToken',
95
+ githubApiBaseUrlV4: 'http://localhost/graphql',
96
+ query: (0, graphql_tag_1.default) `
97
+ query MyQuery {
98
+ viewer {
99
+ login
100
+ }
101
+ }
102
+ `,
103
+ variables: {
104
+ foo: 'bar',
105
+ },
106
+ })).rejects.toThrowError('Request failed with status code 500');
107
+ });
108
+ });
109
+ });
@@ -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 = (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
+ });
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchAuthorId_1 = require("./fetchAuthorId");
5
+ describe('fetchAuthorId', () => {
6
+ let devAccessToken;
7
+ beforeAll(() => {
8
+ devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ describe('author = null', () => {
11
+ it('returns null', async () => {
12
+ const options = {
13
+ accessToken: devAccessToken,
14
+ author: null,
15
+ };
16
+ expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual(null);
17
+ });
18
+ });
19
+ describe('author is "sqren"', () => {
20
+ it('returns author id', async () => {
21
+ const options = {
22
+ accessToken: devAccessToken,
23
+ author: 'sqren',
24
+ };
25
+ expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
26
+ });
27
+ });
28
+ });