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

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 (129) hide show
  1. package/dist/entrypoint.cli.js +0 -0
  2. package/dist/entrypoint.module.d.ts +4 -3
  3. package/dist/entrypoint.module.js +2 -7
  4. package/dist/options/ConfigOptions.d.ts +1 -1
  5. package/dist/options/cliArgs.d.ts +1 -0
  6. package/dist/options/cliArgs.js +4 -0
  7. package/dist/options/config/config.d.ts +1 -1
  8. package/dist/options/config/readConfigFile.d.ts +1 -1
  9. package/dist/options/options.d.ts +2 -1
  10. package/dist/services/github/v3/createStatusComment.js +1 -1
  11. package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
  12. package/dist/services/github/v4/apiRequestV4.js +15 -14
  13. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
  14. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  15. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  16. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
  17. package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  19. package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
  20. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  21. package/dist/services/remoteConfig.js +2 -2
  22. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  23. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  24. package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
  25. package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
  26. package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
  27. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
  28. package/dist/ui/getCommits.js +6 -4
  29. package/dist/ui/maybeSetupRepo.js +7 -14
  30. package/dist/utils/packageVersion.d.ts +1 -1
  31. package/dist/utils/packageVersion.js +1 -1
  32. package/package.json +9 -9
  33. package/yarn.lock +121 -114
  34. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  35. package/dist/entrypoint.cli.e2e.private.test.js +0 -386
  36. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  37. package/dist/entrypoint.cli.private.test.js +0 -46
  38. package/dist/options/cliArgs.test.d.ts +0 -1
  39. package/dist/options/cliArgs.test.js +0 -182
  40. package/dist/options/config/config.test.d.ts +0 -1
  41. package/dist/options/config/config.test.js +0 -32
  42. package/dist/options/config/globalConfig.test.d.ts +0 -1
  43. package/dist/options/config/globalConfig.test.js +0 -61
  44. package/dist/options/config/projectConfig.test.d.ts +0 -1
  45. package/dist/options/config/projectConfig.test.js +0 -109
  46. package/dist/options/options.test.d.ts +0 -1
  47. package/dist/options/options.test.js +0 -384
  48. package/dist/runSequentially.test.d.ts +0 -1
  49. package/dist/runSequentially.test.js +0 -219
  50. package/dist/scripts/postinstall.test.d.ts +0 -1
  51. package/dist/scripts/postinstall.test.js +0 -53
  52. package/dist/services/env.test.d.ts +0 -1
  53. package/dist/services/env.test.js +0 -21
  54. package/dist/services/git.integration.test.d.ts +0 -1
  55. package/dist/services/git.integration.test.js +0 -320
  56. package/dist/services/git.test.d.ts +0 -1
  57. package/dist/services/git.test.js +0 -532
  58. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  59. package/dist/services/github/commitFormatters.test.js +0 -11
  60. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  61. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  62. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  63. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  64. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  65. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  66. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  67. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  68. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  69. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  70. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  71. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  72. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  73. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  74. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  75. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -134
  76. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  77. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -116
  78. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  79. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -195
  80. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  81. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -152
  82. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  83. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  84. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  85. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  86. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  87. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  88. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  89. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -117
  90. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  91. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  92. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  93. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -159
  94. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  95. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  96. package/dist/services/prompt.test.d.ts +0 -1
  97. package/dist/services/prompt.test.js +0 -134
  98. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  99. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  100. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  101. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -225
  102. package/dist/test/ExecError.d.ts +0 -16
  103. package/dist/test/ExecError.js +0 -15
  104. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  105. package/dist/test/backport-e2e.mutation.test.js +0 -347
  106. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  107. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  108. package/dist/test/mockConfigFiles.d.ts +0 -5
  109. package/dist/test/mockConfigFiles.js +0 -21
  110. package/dist/test/mocks.d.ts +0 -10
  111. package/dist/test/mocks.js +0 -23
  112. package/dist/test/nockHelpers.d.ts +0 -16
  113. package/dist/test/nockHelpers.js +0 -36
  114. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  115. package/dist/test/private/getDevAccessToken.js +0 -12
  116. package/dist/test/sandbox.d.ts +0 -5
  117. package/dist/test/sandbox.js +0 -43
  118. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  119. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  120. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  121. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -459
  122. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  123. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  124. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  125. package/dist/ui/getTargetBranches.test.js +0 -198
  126. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  127. package/dist/ui/maybeSetupRepo.test.js +0 -204
  128. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  129. package/dist/utils/excludeUndefined.test.js +0 -24
@@ -1,311 +0,0 @@
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
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
26
- const git = __importStar(require("../services/git"));
27
- const fetchCommitsByAuthorModule = __importStar(require("../services/github/v4/fetchCommits/fetchCommitsByAuthor"));
28
- const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
29
- describe('getCommitsWithoutBackports', () => {
30
- afterEach(() => {
31
- jest.restoreAllMocks();
32
- });
33
- describe('expectedTargetPullRequests', () => {
34
- function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
35
- // simulate 1 unbackported commit
36
- jest
37
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
38
- .mockResolvedValueOnce([
39
- {
40
- sourceCommit: {
41
- committedDate: '10',
42
- message: 'First commit (#1)',
43
- sha: 'xyz',
44
- },
45
- sourcePullRequest: {
46
- url: 'https://www.github.com/foo/bar/pull/123',
47
- number: 123,
48
- mergeCommit: {
49
- message: 'First commit (#1)',
50
- sha: 'xyz',
51
- },
52
- },
53
- expectedTargetPullRequests,
54
- sourceBranch: 'main',
55
- },
56
- ]);
57
- // simulate commit is definitely not backported
58
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
59
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
60
- options: {},
61
- commit: {
62
- sourceCommit: {
63
- committedDate: '100',
64
- message: 'Second commit (#2)',
65
- sha: 'abc',
66
- },
67
- expectedTargetPullRequests: [],
68
- sourceBranch: 'main',
69
- },
70
- targetBranch: '7.x',
71
- conflictingFiles: ['/foo/bar/baz.ts'],
72
- });
73
- }
74
- it('should not unbackported commits if no backports were expected', async () => {
75
- const commitsWithoutBackports = await setupExpectedPullRequests({
76
- expectedTargetPullRequests: [],
77
- });
78
- expect(commitsWithoutBackports.length).toEqual(0);
79
- });
80
- it('should display as missing if a backport is CLOSED', async () => {
81
- const commitsWithoutBackports = await setupExpectedPullRequests({
82
- expectedTargetPullRequests: [
83
- {
84
- state: 'CLOSED',
85
- branch: '7.x',
86
- number: 456,
87
- url: 'https://www.github.com/foo/bar/pull/456',
88
- },
89
- ],
90
- });
91
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
92
- });
93
- it('should display as missing if a backport is MISSING', async () => {
94
- const commitsWithoutBackports = await setupExpectedPullRequests({
95
- expectedTargetPullRequests: [{ state: 'MISSING', branch: '7.x' }],
96
- });
97
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
98
- });
99
- it('should display as pending if a backport is OPEN', async () => {
100
- const commitsWithoutBackports = await setupExpectedPullRequests({
101
- expectedTargetPullRequests: [
102
- {
103
- state: 'OPEN',
104
- branch: '7.x',
105
- url: 'https://www.github.com/foo/bar/pull/456',
106
- number: 456,
107
- },
108
- ],
109
- });
110
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
111
- });
112
- it('should not display commit as unbackported if a backport was MERGED', async () => {
113
- const commitsWithoutBackports = await setupExpectedPullRequests({
114
- expectedTargetPullRequests: [
115
- {
116
- state: 'MERGED',
117
- branch: '7.x',
118
- number: 456,
119
- url: 'https://www.github.com/foo/bar/pull/456',
120
- },
121
- ],
122
- });
123
- expect(commitsWithoutBackports).toEqual([]);
124
- });
125
- });
126
- describe('commitDate', () => {
127
- function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
128
- // simulate 1 commit with a pending backport
129
- jest
130
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
131
- .mockResolvedValueOnce([
132
- {
133
- sourceCommit: {
134
- committedDate: offendingCommitDate,
135
- message: 'First commit (#1)',
136
- sha: 'xyz',
137
- },
138
- sourcePullRequest: {
139
- number: 123,
140
- url: 'https://www.github.com/foo/bar/pull/123',
141
- mergeCommit: {
142
- message: 'First commit (#1)',
143
- sha: 'xyz',
144
- },
145
- },
146
- sourceBranch: 'main',
147
- expectedTargetPullRequests: [
148
- {
149
- state: 'OPEN',
150
- branch: '7.x',
151
- number: 456,
152
- url: 'https://www.github.com/foo/bar/pull/456',
153
- },
154
- ],
155
- },
156
- ]);
157
- // simulate commit is definitely not backported
158
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
159
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
160
- options: {},
161
- commit: {
162
- sourceCommit: {
163
- committedDate: currentCommitDate,
164
- message: 'Second commit (#2)',
165
- sha: 'abc',
166
- },
167
- sourcePullRequest: {
168
- number: 123,
169
- url: 'https://www.github.com/foo/bar/pull/123',
170
- mergeCommit: {
171
- message: 'Second commit (#2)',
172
- sha: 'abc',
173
- },
174
- },
175
- sourceBranch: 'main',
176
- expectedTargetPullRequests: [],
177
- },
178
- targetBranch: '7.x',
179
- conflictingFiles: ['/foo/bar/baz.ts'],
180
- });
181
- }
182
- it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
183
- const commitsWithoutBackports = await setupCommitDateDiff({
184
- offendingCommitDate: '100',
185
- currentCommitDate: '10',
186
- });
187
- expect(commitsWithoutBackports).toEqual([]);
188
- });
189
- it('should display commit as unbackport if is older than the commit currently being backported', async () => {
190
- const commitsWithoutBackports = await setupCommitDateDiff({
191
- offendingCommitDate: '10',
192
- currentCommitDate: '100',
193
- });
194
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
195
- });
196
- });
197
- describe('targetBranch', () => {
198
- function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
199
- // return mock commits that also touched the conflicting files
200
- jest
201
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
202
- .mockResolvedValueOnce([
203
- {
204
- sourceCommit: {
205
- committedDate: '10',
206
- message: 'First commit (#1)',
207
- sha: 'xyz',
208
- },
209
- sourcePullRequest: {
210
- number: 123,
211
- url: 'https://www.github.com/foo/bar/pull/123',
212
- mergeCommit: {
213
- message: 'First commit (#1)',
214
- sha: 'xyz',
215
- },
216
- },
217
- sourceBranch: 'main',
218
- expectedTargetPullRequests: [
219
- {
220
- branch: offendingCommitTargetBranch,
221
- state: 'OPEN',
222
- url: 'https://www.github.com/foo/bar/pull/456',
223
- number: 456,
224
- },
225
- ],
226
- },
227
- ]);
228
- // simulate commit is definitely not backported
229
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
230
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
231
- options: {},
232
- // commit that is being backported
233
- commit: {
234
- sourceCommit: {
235
- committedDate: '100',
236
- message: 'Second commit (#2)',
237
- sha: 'abc',
238
- },
239
- sourcePullRequest: {
240
- url: 'https://www.github.com/foo/bar/pull/123',
241
- number: 123,
242
- mergeCommit: {
243
- message: 'Second commit (#2)',
244
- sha: 'abc',
245
- },
246
- },
247
- expectedTargetPullRequests: [],
248
- sourceBranch: 'main',
249
- },
250
- targetBranch: currentCommitTargetBranch,
251
- conflictingFiles: ['/foo/bar/baz.ts'],
252
- });
253
- }
254
- it('should display backport as pending if target branches match', async () => {
255
- const commitsWithoutBackports = await setupTargetBranchDiff({
256
- offendingCommitTargetBranch: '7.x',
257
- currentCommitTargetBranch: '7.x',
258
- });
259
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
260
- });
261
- it("should not display commit if target branches don't match", async () => {
262
- const commitsWithoutBackports = await setupTargetBranchDiff({
263
- offendingCommitTargetBranch: '7.x',
264
- currentCommitTargetBranch: '8.x',
265
- });
266
- expect(commitsWithoutBackports.length).toBe(0);
267
- });
268
- });
269
- describe("when conflicting commit doesn't have an associated pull request", () => {
270
- it('should be ignored', async () => {
271
- jest
272
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
273
- .mockResolvedValueOnce([
274
- {
275
- sourceCommit: {
276
- committedDate: '10',
277
- sha: 'xyz',
278
- message: 'First commit (#1)',
279
- },
280
- expectedTargetPullRequests: [],
281
- sourceBranch: 'main',
282
- },
283
- ]);
284
- // simulate commit is definitely not backported
285
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
286
- const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
287
- options: {},
288
- commit: {
289
- sourceCommit: {
290
- committedDate: '100',
291
- message: 'Second commit (#2)',
292
- sha: 'abc',
293
- },
294
- sourcePullRequest: {
295
- url: 'https://www.github.com/foo/bar/pull/123',
296
- number: 123,
297
- mergeCommit: {
298
- message: 'Second commit (#2)',
299
- sha: 'abc',
300
- },
301
- },
302
- expectedTargetPullRequests: [],
303
- sourceBranch: 'main',
304
- },
305
- targetBranch: '7.x',
306
- conflictingFiles: ['/foo/bar/baz.ts'],
307
- });
308
- expect(commitsWithoutBackports.length).toEqual(0);
309
- });
310
- });
311
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,198 +0,0 @@
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 prompts = __importStar(require("../services/prompts"));
23
- const getTargetBranches_1 = require("./getTargetBranches");
24
- describe('getTargetBranches', () => {
25
- let promptSpy;
26
- beforeEach(() => {
27
- jest.clearAllMocks();
28
- promptSpy = jest
29
- .spyOn(prompts, 'promptForTargetBranches')
30
- .mockResolvedValueOnce(['branchA']);
31
- });
32
- describe('when `options.targetBranches` is empty', () => {
33
- let branches;
34
- beforeEach(async () => {
35
- const options = {
36
- targetBranches: [],
37
- targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
38
- multipleBranches: false,
39
- };
40
- const commits = [
41
- {
42
- sourceCommit: {
43
- committedDate: 'aaa',
44
- message: 'hey',
45
- sha: 'abcd',
46
- },
47
- sourcePullRequest: {
48
- url: 'foo',
49
- number: 1337,
50
- mergeCommit: {
51
- message: 'hey',
52
- sha: 'abcd',
53
- },
54
- },
55
- sourceBranch: '7.x',
56
- expectedTargetPullRequests: [],
57
- },
58
- ];
59
- branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
60
- });
61
- it('should return branches from prompt', () => {
62
- expect(branches).toEqual(['branchA']);
63
- });
64
- it('should call prompt with correct args', () => {
65
- expect(promptSpy).toHaveBeenLastCalledWith({
66
- targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
67
- isMultipleChoice: false,
68
- });
69
- });
70
- });
71
- describe('when `options.targetBranches` is not empty', () => {
72
- let branches;
73
- beforeEach(() => {
74
- branches = (0, getTargetBranches_1.getTargetBranches)({
75
- targetBranches: ['branchA', 'branchB'],
76
- targetBranchChoices: [],
77
- multipleBranches: false,
78
- }, []);
79
- });
80
- it('should return branches from `options.branches`', () => {
81
- expect(branches).toEqual(['branchA', 'branchB']);
82
- });
83
- it('should not call prompt', () => {
84
- expect(promptSpy).not.toHaveBeenCalled();
85
- });
86
- });
87
- describe('when ci=true', () => {
88
- it('should throw when there are no missing backports', () => {
89
- const commits = [];
90
- expect(() => {
91
- return (0, getTargetBranches_1.getTargetBranches)({
92
- expectedTargetPullRequests: [],
93
- ci: true,
94
- }, commits);
95
- }).toThrow('There are no branches to backport to. Aborting.');
96
- });
97
- it('should return missing backports', () => {
98
- const commits = [
99
- {
100
- expectedTargetPullRequests: [
101
- { branch: '7.2', state: 'MERGED' },
102
- { branch: '7.1', state: 'OPEN' },
103
- { branch: '7.x', state: 'MISSING' },
104
- ],
105
- },
106
- ];
107
- const targetBranches = (0, getTargetBranches_1.getTargetBranches)({ ci: true }, commits);
108
- expect(targetBranches).toEqual(['7.x']);
109
- });
110
- });
111
- describe('when `expectedTargetPullRequests` is missing a backport to 7.x', () => {
112
- let targetBranchChoices;
113
- beforeEach(async () => {
114
- const options = {
115
- targetBranches: [],
116
- multipleBranches: true,
117
- targetBranchChoices: [
118
- { name: 'master' },
119
- { name: '7.x' },
120
- { name: '7.7' },
121
- { name: '7.6' },
122
- { name: '7.5' },
123
- ],
124
- branchLabelMapping: {},
125
- sourceBranch: 'master',
126
- };
127
- const commits = [
128
- {
129
- sourceCommit: {
130
- committedDate: 'bbb',
131
- message: '[backport] Bump to 5.1.3 (#62286)',
132
- sha: 'my-sha',
133
- },
134
- sourcePullRequest: {
135
- url: 'foo',
136
- number: 62286,
137
- mergeCommit: {
138
- message: '[backport] Bump to 5.1.3 (#62286)',
139
- sha: 'my-sha',
140
- },
141
- },
142
- sourceBranch: 'master',
143
- expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
144
- },
145
- ];
146
- await (0, getTargetBranches_1.getTargetBranches)(options, commits);
147
- targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
148
- });
149
- it('should list the correct branches', async () => {
150
- expect(targetBranchChoices).toEqual([
151
- { checked: true, name: '7.x' },
152
- { checked: false, name: '7.7' },
153
- { checked: false, name: '7.6' },
154
- { checked: false, name: '7.5' },
155
- ]);
156
- });
157
- it('should not list the sourceBranch (master)', async () => {
158
- expect(targetBranchChoices).not.toContainEqual(expect.objectContaining({ name: 'master' }));
159
- });
160
- it('should select 7.x', async () => {
161
- expect(targetBranchChoices).toContainEqual({
162
- name: '7.x',
163
- checked: true,
164
- });
165
- });
166
- });
167
- });
168
- describe('getTargetBranchChoices', () => {
169
- const options = {
170
- ci: false,
171
- targetBranchChoices: [
172
- { name: 'master', checked: true },
173
- { name: '7.x', checked: true },
174
- { name: '7.8', checked: false },
175
- { name: '7.7', checked: false },
176
- ],
177
- branchLabelMapping: {},
178
- };
179
- const sourceBranch = 'master';
180
- it('should not check any branches if no labels match', () => {
181
- const targetBranchesFromLabels = [];
182
- const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
183
- expect(branches).toEqual([
184
- { checked: false, name: '7.x' },
185
- { checked: false, name: '7.8' },
186
- { checked: false, name: '7.7' },
187
- ]);
188
- });
189
- it('should pre-select branches based on labels', () => {
190
- const targetBranchesFromLabels = ['7.7'];
191
- const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
192
- expect(branches).toEqual([
193
- { checked: false, name: '7.x' },
194
- { checked: false, name: '7.8' },
195
- { checked: true, name: '7.7' },
196
- ]);
197
- });
198
- });
@@ -1 +0,0 @@
1
- export {};