backport 7.0.1-beta.2 → 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 (163) hide show
  1. package/dist/backportRun.d.ts +1 -0
  2. package/dist/backportRun.js +3 -2
  3. package/dist/entrypoint.cli.js +12 -1
  4. package/dist/entrypoint.module.d.ts +4 -3
  5. package/dist/entrypoint.module.js +2 -7
  6. package/dist/options/ConfigOptions.d.ts +1 -1
  7. package/dist/options/cliArgs.d.ts +2 -1
  8. package/dist/options/cliArgs.js +4 -0
  9. package/dist/options/config/config.d.ts +1 -1
  10. package/dist/options/config/readConfigFile.d.ts +2 -2
  11. package/dist/options/options.d.ts +3 -6
  12. package/dist/runSequentially.js +1 -0
  13. package/dist/services/HandledError.js +3 -1
  14. package/dist/services/git.d.ts +2 -0
  15. package/dist/services/git.js +47 -10
  16. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  17. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  18. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  19. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  20. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  21. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  22. package/dist/services/github/v3/createPullRequest.js +2 -5
  23. package/dist/services/github/v3/createStatusComment.js +1 -1
  24. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  25. package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
  26. package/dist/services/github/v4/apiRequestV4.js +22 -21
  27. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  28. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  29. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  30. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  31. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
  32. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  33. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
  34. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  35. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
  36. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
  37. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  38. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  39. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  40. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  41. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
  42. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
  43. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  44. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  45. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  46. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  47. package/dist/services/logger.d.ts +5 -5
  48. package/dist/services/logger.js +24 -23
  49. package/dist/services/remoteConfig.d.ts +20 -0
  50. package/dist/services/remoteConfig.js +52 -0
  51. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  52. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  53. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  54. package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
  55. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  56. package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
  57. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
  58. package/dist/ui/getCommits.js +8 -6
  59. package/dist/ui/maybeSetupRepo.js +7 -14
  60. package/dist/ui/ora.d.ts +9 -0
  61. package/dist/ui/ora.js +21 -0
  62. package/dist/utils/packageVersion.d.ts +1 -1
  63. package/dist/utils/packageVersion.js +1 -1
  64. package/package.json +10 -10
  65. package/yarn.lock +121 -114
  66. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  67. package/dist/entrypoint.cli.e2e.private.test.js +0 -319
  68. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  69. package/dist/entrypoint.cli.private.test.js +0 -46
  70. package/dist/options/cliArgs.test.d.ts +0 -1
  71. package/dist/options/cliArgs.test.js +0 -182
  72. package/dist/options/config/config.test.d.ts +0 -1
  73. package/dist/options/config/config.test.js +0 -32
  74. package/dist/options/config/globalConfig.test.d.ts +0 -1
  75. package/dist/options/config/globalConfig.test.js +0 -61
  76. package/dist/options/config/projectConfig.test.d.ts +0 -1
  77. package/dist/options/config/projectConfig.test.js +0 -109
  78. package/dist/options/options.test.d.ts +0 -1
  79. package/dist/options/options.test.js +0 -386
  80. package/dist/runSequentially.test.d.ts +0 -1
  81. package/dist/runSequentially.test.js +0 -218
  82. package/dist/scripts/postinstall.test.d.ts +0 -1
  83. package/dist/scripts/postinstall.test.js +0 -53
  84. package/dist/services/env.test.d.ts +0 -1
  85. package/dist/services/env.test.js +0 -21
  86. package/dist/services/git.integration.test.d.ts +0 -1
  87. package/dist/services/git.integration.test.js +0 -267
  88. package/dist/services/git.test.d.ts +0 -1
  89. package/dist/services/git.test.js +0 -518
  90. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  91. package/dist/services/github/commitFormatters.test.js +0 -11
  92. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  93. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  94. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  95. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  96. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  97. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  98. package/dist/services/github/v3/index.d.ts +0 -1
  99. package/dist/services/github/v3/index.js +0 -61
  100. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  101. package/dist/services/github/v4/apiRequestV4.test.js +0 -82
  102. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  103. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -96
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -143
  110. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -124
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -200
  114. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -153
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  118. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  120. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  122. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  123. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -136
  124. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  126. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  127. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -154
  128. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  129. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  130. package/dist/services/prompt.test.d.ts +0 -1
  131. package/dist/services/prompt.test.js +0 -134
  132. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  133. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  134. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  135. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -235
  136. package/dist/test/ExecError.d.ts +0 -16
  137. package/dist/test/ExecError.js +0 -15
  138. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  139. package/dist/test/backport-e2e.mutation.test.js +0 -347
  140. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  141. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  142. package/dist/test/mockConfigFiles.d.ts +0 -5
  143. package/dist/test/mockConfigFiles.js +0 -21
  144. package/dist/test/mocks.d.ts +0 -10
  145. package/dist/test/mocks.js +0 -23
  146. package/dist/test/nockHelpers.d.ts +0 -16
  147. package/dist/test/nockHelpers.js +0 -32
  148. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  149. package/dist/test/private/getDevAccessToken.js +0 -12
  150. package/dist/test/sandbox.d.ts +0 -5
  151. package/dist/test/sandbox.js +0 -43
  152. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  153. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  154. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  155. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -455
  156. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  157. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  158. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  159. package/dist/ui/getTargetBranches.test.js +0 -198
  160. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  161. package/dist/ui/maybeSetupRepo.test.js +0 -204
  162. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  163. 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 {};