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,377 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const createPullRequest_1 = require("./createPullRequest");
4
+ describe('getPullRequestBody', () => {
5
+ it('when single pull request is backported', () => {
6
+ expect((0, createPullRequest_1.getPullRequestBody)({
7
+ options: {},
8
+ commits: [
9
+ {
10
+ author: {
11
+ email: 'soren.louv@elastic.co',
12
+ name: 'Søren Louv-Jansen',
13
+ },
14
+ sourcePullRequest: {
15
+ number: 55,
16
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
17
+ mergeCommit: {
18
+ sha: 'abcdefghi',
19
+ message: 'My commit message (#55)',
20
+ },
21
+ },
22
+ sourceCommit: {
23
+ committedDate: '2020',
24
+ sha: 'abcdefghi',
25
+ message: 'My commit message (#55)',
26
+ },
27
+ expectedTargetPullRequests: [],
28
+ sourceBranch: 'master',
29
+ },
30
+ ],
31
+ targetBranch: '7.x',
32
+ })).toMatchInlineSnapshot(`
33
+ "# Backport
34
+
35
+ This will backport the following commits from \`master\` to \`7.x\`:
36
+ - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
37
+
38
+ <!--- Backport version: 1.2.3-mocked -->
39
+
40
+ ### Questions ?
41
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
42
+ `);
43
+ });
44
+ it('when a single commit (non pull request) is backported', () => {
45
+ expect((0, createPullRequest_1.getPullRequestBody)({
46
+ options: {},
47
+ commits: [
48
+ {
49
+ author: {
50
+ email: 'soren.louv@elastic.co',
51
+ name: 'Søren Louv-Jansen',
52
+ },
53
+ sourceCommit: {
54
+ committedDate: '',
55
+ sha: 'abcdefghijklmw',
56
+ message: 'My commit message',
57
+ },
58
+ sourceBranch: 'main',
59
+ expectedTargetPullRequests: [],
60
+ },
61
+ ],
62
+ targetBranch: '7.x',
63
+ })).toMatchInlineSnapshot(`
64
+ "# Backport
65
+
66
+ This will backport the following commits from \`main\` to \`7.x\`:
67
+ - My commit message (abcdefgh)
68
+
69
+ <!--- Backport version: 1.2.3-mocked -->
70
+
71
+ ### Questions ?
72
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
73
+ `);
74
+ });
75
+ it('when multiple commits are backported', () => {
76
+ expect((0, createPullRequest_1.getPullRequestBody)({
77
+ options: {},
78
+ commits: [
79
+ {
80
+ author: {
81
+ email: 'soren.louv@elastic.co',
82
+ name: 'Søren Louv-Jansen',
83
+ },
84
+ sourcePullRequest: {
85
+ number: 55,
86
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
87
+ mergeCommit: {
88
+ sha: 'abcdefghijklm',
89
+ message: 'My commit message (#55)',
90
+ },
91
+ },
92
+ sourceCommit: {
93
+ committedDate: '',
94
+ sha: 'abcdefghijklm',
95
+ message: 'My commit message (#55)',
96
+ },
97
+ sourceBranch: 'main',
98
+ expectedTargetPullRequests: [],
99
+ },
100
+ {
101
+ author: {
102
+ email: 'soren.louv@elastic.co',
103
+ name: 'Søren Louv-Jansen',
104
+ },
105
+ sourceCommit: {
106
+ committedDate: '',
107
+ sha: 'qwertyuiop',
108
+ message: 'Another commit message',
109
+ },
110
+ sourceBranch: 'main',
111
+ expectedTargetPullRequests: [],
112
+ },
113
+ ],
114
+ targetBranch: '7.x',
115
+ })).toMatchInlineSnapshot(`
116
+ "# Backport
117
+
118
+ This will backport the following commits from \`main\` to \`7.x\`:
119
+ - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
120
+ - Another commit message (qwertyui)
121
+
122
+ <!--- Backport version: 1.2.3-mocked -->
123
+
124
+ ### Questions ?
125
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
126
+ `);
127
+ });
128
+ it('when a PR is merged (instead of squashed) and the individual commits are selected', () => {
129
+ expect((0, createPullRequest_1.getPullRequestBody)({
130
+ options: {},
131
+ commits: [
132
+ {
133
+ sourceCommit: {
134
+ committedDate: '2022-02-07T23:53:14Z',
135
+ message: 'Merge strategy: Second commit',
136
+ sha: 'e8df5eaa4db7b94474b48e2320b02d33a830d9fb',
137
+ },
138
+ author: {
139
+ email: 'soren.louv@elastic.co',
140
+ name: 'Søren Louv-Jansen',
141
+ },
142
+ sourcePullRequest: {
143
+ number: 1,
144
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
145
+ mergeCommit: {
146
+ message: 'Merge pull request #1 from backport-org/merge-strategy\n\nMerge commits to `main`',
147
+ sha: '0db7f1ac1233461563d8708511d1c14adbab46da',
148
+ },
149
+ },
150
+ sourceBranch: 'main',
151
+ expectedTargetPullRequests: [],
152
+ },
153
+ {
154
+ sourceCommit: {
155
+ committedDate: '2022-02-07T23:51:59Z',
156
+ message: 'Merge strategy: First commit',
157
+ sha: '5411b1c1144093e422220008f23f2c2b909ed113',
158
+ },
159
+ author: {
160
+ email: 'soren.louv@elastic.co',
161
+ name: 'Søren Louv-Jansen',
162
+ },
163
+ sourcePullRequest: {
164
+ number: 1,
165
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
166
+ mergeCommit: {
167
+ message: 'Merge pull request #1 from backport-org/merge-strategy\n\nMerge commits to `main`',
168
+ sha: '0db7f1ac1233461563d8708511d1c14adbab46da',
169
+ },
170
+ },
171
+ sourceBranch: 'main',
172
+ expectedTargetPullRequests: [],
173
+ },
174
+ ],
175
+ targetBranch: '7.x',
176
+ })).toMatchInlineSnapshot(`
177
+ "# Backport
178
+
179
+ This will backport the following commits from \`main\` to \`7.x\`:
180
+ - [Merge strategy: Second commit](https://github.com/backport-org/different-merge-strategies/pull/1)
181
+ - [Merge strategy: First commit](https://github.com/backport-org/different-merge-strategies/pull/1)
182
+
183
+ <!--- Backport version: 1.2.3-mocked -->
184
+
185
+ ### Questions ?
186
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
187
+ `);
188
+ });
189
+ it('replaces template variables in PR description', () => {
190
+ expect((0, createPullRequest_1.getPullRequestBody)({
191
+ options: {
192
+ prDescription: 'Backporting the following to {targetBranch}:\n{commitMessages}',
193
+ },
194
+ commits: [
195
+ {
196
+ author: {
197
+ email: 'soren.louv@elastic.co',
198
+ name: 'Søren Louv-Jansen',
199
+ },
200
+ sourcePullRequest: {
201
+ number: 55,
202
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
203
+ mergeCommit: {
204
+ sha: 'abcdefghijklm',
205
+ message: 'My commit message (#55)',
206
+ },
207
+ },
208
+ sourceCommit: {
209
+ committedDate: '',
210
+ sha: 'abcdefghijklm',
211
+ message: 'My commit message (#55)',
212
+ },
213
+ sourceBranch: 'main',
214
+ expectedTargetPullRequests: [],
215
+ },
216
+ {
217
+ author: {
218
+ email: 'soren.louv@elastic.co',
219
+ name: 'Søren Louv-Jansen',
220
+ },
221
+ sourceCommit: {
222
+ committedDate: '',
223
+ sha: 'qwertyuiop',
224
+ message: 'Another commit message',
225
+ },
226
+ sourceBranch: 'main',
227
+ expectedTargetPullRequests: [],
228
+ },
229
+ ],
230
+ targetBranch: '7.x',
231
+ })).toMatchInlineSnapshot(`
232
+ "Backporting the following to 7.x:
233
+ - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
234
+ - Another commit message (qwertyui)"
235
+ `);
236
+ });
237
+ it('appends text to the default descriptions', () => {
238
+ expect((0, createPullRequest_1.getPullRequestBody)({
239
+ options: {
240
+ prDescription: '{defaultPrDescription}\n\ntext to append',
241
+ },
242
+ commits: [
243
+ {
244
+ author: {
245
+ email: 'soren.louv@elastic.co',
246
+ name: 'Søren Louv-Jansen',
247
+ },
248
+ sourcePullRequest: {
249
+ number: 55,
250
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
251
+ mergeCommit: {
252
+ sha: 'abcdefghijklm',
253
+ message: 'My commit message (#55)',
254
+ },
255
+ },
256
+ sourceCommit: {
257
+ committedDate: '',
258
+ sha: 'abcdefghijklm',
259
+ message: 'My commit message (#55)',
260
+ },
261
+ sourceBranch: 'main',
262
+ expectedTargetPullRequests: [],
263
+ },
264
+ {
265
+ author: {
266
+ email: 'soren.louv@elastic.co',
267
+ name: 'Søren Louv-Jansen',
268
+ },
269
+ sourceCommit: {
270
+ committedDate: '',
271
+ sha: 'qwertyuiop',
272
+ message: 'Another commit message',
273
+ },
274
+ sourceBranch: 'main',
275
+ expectedTargetPullRequests: [],
276
+ },
277
+ ],
278
+ targetBranch: '7.x',
279
+ })).toMatchInlineSnapshot(`
280
+ "# Backport
281
+
282
+ This will backport the following commits from \`main\` to \`7.x\`:
283
+ - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
284
+ - Another commit message (qwertyui)
285
+
286
+ <!--- Backport version: 1.2.3-mocked -->
287
+
288
+ ### Questions ?
289
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
290
+
291
+ text to append"
292
+ `);
293
+ });
294
+ });
295
+ describe('getTitle', () => {
296
+ it('has the default title', () => {
297
+ expect((0, createPullRequest_1.getTitle)({
298
+ options: {},
299
+ commits: [
300
+ {
301
+ author: {
302
+ email: 'soren.louv@elastic.co',
303
+ name: 'Søren Louv-Jansen',
304
+ },
305
+ sourceBranch: 'main',
306
+ sourcePullRequest: {
307
+ number: 55,
308
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
309
+ mergeCommit: {
310
+ sha: 'abcdefghi',
311
+ message: 'My commit message (#55)',
312
+ },
313
+ },
314
+ sourceCommit: {
315
+ committedDate: '2020',
316
+ sha: 'abcdefghi',
317
+ message: 'My commit message (#55)',
318
+ },
319
+ expectedTargetPullRequests: [],
320
+ },
321
+ {
322
+ author: {
323
+ email: 'soren.louv@elastic.co',
324
+ name: 'Søren Louv-Jansen',
325
+ },
326
+ sourcePullRequest: {
327
+ number: 56,
328
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/56',
329
+ mergeCommit: {
330
+ sha: 'jklmnopqr',
331
+ message: 'Another commit message (#56)',
332
+ },
333
+ },
334
+ sourceCommit: {
335
+ committedDate: '2020',
336
+ sha: 'jklmnopqr',
337
+ message: 'Another commit message (#56)',
338
+ },
339
+ sourceBranch: 'main',
340
+ expectedTargetPullRequests: [],
341
+ },
342
+ ],
343
+ targetBranch: '7.x',
344
+ })).toEqual('[7.x] My commit message (#55) | Another commit message (#56)');
345
+ });
346
+ it('replaces template variables in PR title', () => {
347
+ expect((0, createPullRequest_1.getTitle)({
348
+ options: {
349
+ prTitle: 'Branch: "{targetBranch}". Messages: {commitMessages}',
350
+ },
351
+ commits: [
352
+ {
353
+ author: {
354
+ email: 'soren.louv@elastic.co',
355
+ name: 'Søren Louv-Jansen',
356
+ },
357
+ sourcePullRequest: {
358
+ number: 55,
359
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
360
+ mergeCommit: {
361
+ sha: 'abcdefghi',
362
+ message: 'My commit message (#55)',
363
+ },
364
+ },
365
+ sourceCommit: {
366
+ committedDate: '',
367
+ sha: 'abcdefghi',
368
+ message: 'My commit message (#55)',
369
+ },
370
+ sourceBranch: 'main',
371
+ expectedTargetPullRequests: [],
372
+ },
373
+ ],
374
+ targetBranch: '7.x',
375
+ })).toEqual('Branch: "7.x". Messages: My commit message (#55)');
376
+ });
377
+ });