backport 7.2.0-beta.2 → 7.2.0-beta.3

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 (104) hide show
  1. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  2. package/dist/entrypoint.cli.private.test.js +46 -0
  3. package/dist/options/cliArgs.test.d.ts +1 -0
  4. package/dist/options/cliArgs.test.js +182 -0
  5. package/dist/options/config/config.test.d.ts +1 -0
  6. package/dist/options/config/config.test.js +32 -0
  7. package/dist/options/config/globalConfig.test.d.ts +1 -0
  8. package/dist/options/config/globalConfig.test.js +61 -0
  9. package/dist/options/config/projectConfig.test.d.ts +1 -0
  10. package/dist/options/config/projectConfig.test.js +109 -0
  11. package/dist/options/options.test.d.ts +1 -0
  12. package/dist/options/options.test.js +384 -0
  13. package/dist/runSequentially.test.d.ts +1 -0
  14. package/dist/runSequentially.test.js +243 -0
  15. package/dist/scripts/postinstall.test.d.ts +1 -0
  16. package/dist/scripts/postinstall.test.js +53 -0
  17. package/dist/services/env.test.d.ts +1 -0
  18. package/dist/services/env.test.js +21 -0
  19. package/dist/services/git.d.ts +1 -3
  20. package/dist/services/git.integration.test.d.ts +1 -0
  21. package/dist/services/git.integration.test.js +320 -0
  22. package/dist/services/git.js +5 -3
  23. package/dist/services/git.test.d.ts +1 -0
  24. package/dist/services/git.test.js +532 -0
  25. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  26. package/dist/services/github/commitFormatters.test.js +11 -0
  27. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  28. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  29. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  30. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  31. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  32. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  33. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  34. package/dist/services/github/v4/apiRequestV4.test.js +109 -0
  35. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  37. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  38. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  39. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  40. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  41. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
  43. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  44. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
  45. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  46. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
  47. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -0
  49. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  51. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  53. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  55. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  56. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
  57. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  59. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  60. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +156 -0
  61. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  62. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  63. package/dist/services/prompt.test.d.ts +1 -0
  64. package/dist/services/prompt.test.js +134 -0
  65. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  66. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  67. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  68. package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
  69. package/dist/test/ExecError.d.ts +16 -0
  70. package/dist/test/ExecError.js +15 -0
  71. package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
  72. package/dist/test/e2e/cli.e2e.private.test.js +433 -0
  73. package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
  74. package/dist/test/e2e/module.e2e.private.test.js +363 -0
  75. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -0
  77. package/dist/test/mockConfigFiles.d.ts +5 -0
  78. package/dist/test/mockConfigFiles.js +21 -0
  79. package/dist/test/mocks.d.ts +10 -0
  80. package/dist/test/mocks.js +23 -0
  81. package/dist/test/nockHelpers.d.ts +16 -0
  82. package/dist/test/nockHelpers.js +36 -0
  83. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  84. package/dist/test/private/getDevAccessToken.js +12 -0
  85. package/dist/test/sandbox.d.ts +5 -0
  86. package/dist/test/sandbox.js +43 -0
  87. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  88. package/dist/test/setupFiles/automatic-mocks.js +63 -0
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -0
  91. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  92. package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
  93. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  94. package/dist/ui/getTargetBranches.test.js +198 -0
  95. package/dist/ui/maybeSetupRepo.js +7 -3
  96. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  97. package/dist/ui/maybeSetupRepo.test.js +238 -0
  98. package/dist/ui/ora.d.ts +1 -1
  99. package/dist/ui/ora.js +2 -2
  100. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  101. package/dist/utils/excludeUndefined.test.js +24 -0
  102. package/dist/utils/packageVersion.d.ts +1 -1
  103. package/dist/utils/packageVersion.js +1 -1
  104. package/package.json +1 -1
@@ -0,0 +1,311 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,198 @@
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
+ });
@@ -2,15 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.maybeSetupRepo = void 0;
4
4
  const del = require("del");
5
- const ora = require("ora");
5
+ const HandledError_1 = require("../services/HandledError");
6
6
  const env_1 = require("../services/env");
7
7
  const git_1 = require("../services/git");
8
+ const ora_1 = require("./ora");
8
9
  async function maybeSetupRepo(options) {
9
10
  const repoPath = (0, env_1.getRepoPath)(options);
10
11
  const isAlreadyCloned = await getIsRepoCloned(options);
12
+ if (options.cwd.includes(repoPath)) {
13
+ throw new HandledError_1.HandledError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
14
+ }
11
15
  // clone repo if folder does not already exists
12
16
  if (!isAlreadyCloned) {
13
- const spinner = ora().start();
17
+ const spinner = (0, ora_1.ora)(options.ci).start();
14
18
  try {
15
19
  const sourcePath = await (0, git_1.getSourceRepoPath)(options);
16
20
  const sourcePathHumanReadable = sourcePath.includes(options.gitHostname)
@@ -44,6 +48,6 @@ async function maybeSetupRepo(options) {
44
48
  exports.maybeSetupRepo = maybeSetupRepo;
45
49
  async function getIsRepoCloned(options) {
46
50
  const repoPath = (0, env_1.getRepoPath)(options);
47
- const projectRoot = await (0, git_1.getGitProjectRoot)(options);
51
+ const projectRoot = await (0, git_1.getGitProjectRoot)(repoPath);
48
52
  return repoPath === projectRoot;
49
53
  }
@@ -0,0 +1 @@
1
+ export {};