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,459 +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 os_1 = __importDefault(require("os"));
26
- const nock_1 = __importDefault(require("nock"));
27
- const ora_1 = __importDefault(require("ora"));
28
- const childProcess = __importStar(require("../services/child-process-promisified"));
29
- const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
30
- const logger = __importStar(require("../services/logger"));
31
- const prompts = __importStar(require("../services/prompts"));
32
- const ExecError_1 = require("../test/ExecError");
33
- const nockHelpers_1 = require("../test/nockHelpers");
34
- const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
35
- describe('cherrypickAndCreateTargetPullRequest', () => {
36
- let execSpy;
37
- let addLabelsScope;
38
- let consoleLogSpy;
39
- beforeEach(() => {
40
- jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
41
- execSpy = jest
42
- .spyOn(childProcess, 'exec')
43
- // mock all exec commands to respond without errors
44
- .mockResolvedValue({ stdout: '', stderr: '' });
45
- consoleLogSpy = jest.spyOn(logger, 'consoleLog');
46
- // ensure labels are added
47
- addLabelsScope = (0, nock_1.default)('https://api.github.com')
48
- .post('/repos/elastic/kibana/issues/1337/labels', {
49
- labels: ['backport'],
50
- })
51
- .reply(200);
52
- });
53
- afterEach(() => {
54
- jest.clearAllMocks();
55
- addLabelsScope.done();
56
- nock_1.default.cleanAll();
57
- });
58
- describe('when commit has a pull request reference', () => {
59
- let res;
60
- let createPullRequestCalls;
61
- beforeEach(async () => {
62
- const options = {
63
- assignees: [],
64
- authenticatedUsername: 'sqren_authenticated',
65
- fork: true,
66
- prTitle: '[{targetBranch}] {commitMessages}',
67
- repoName: 'kibana',
68
- repoOwner: 'elastic',
69
- reviewers: [],
70
- sourceBranch: 'myDefaultSourceBranch',
71
- sourcePRLabels: [],
72
- targetPRLabels: ['backport'],
73
- author: 'sqren',
74
- };
75
- const commits = [
76
- {
77
- sourceBranch: '7.x',
78
- sourceCommit: {
79
- committedDate: 'fff',
80
- sha: 'mySha',
81
- message: 'My original commit message (#1000)',
82
- },
83
- sourcePullRequest: {
84
- url: 'foo',
85
- number: 1000,
86
- mergeCommit: {
87
- sha: 'mySha',
88
- message: 'My original commit message (#1000)',
89
- },
90
- },
91
- expectedTargetPullRequests: [],
92
- },
93
- {
94
- sourceBranch: '7.x',
95
- sourceCommit: {
96
- committedDate: 'ggg',
97
- sha: 'mySha2',
98
- message: 'My other commit message (#2000)',
99
- },
100
- sourcePullRequest: {
101
- url: 'foo',
102
- number: 2000,
103
- mergeCommit: {
104
- sha: 'mySha2',
105
- message: 'My other commit message (#2000)',
106
- },
107
- },
108
- expectedTargetPullRequests: [],
109
- },
110
- ];
111
- const scope = (0, nock_1.default)('https://api.github.com')
112
- .post('/repos/elastic/kibana/pulls')
113
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
114
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
115
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
116
- options,
117
- commits,
118
- targetBranch: '6.x',
119
- });
120
- scope.done();
121
- nock_1.default.cleanAll();
122
- });
123
- it('creates the pull request with multiple PR references', () => {
124
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
125
- Array [
126
- Object {
127
- "base": "6.x",
128
- "body": "# Backport
129
-
130
- This will backport the following commits from \`7.x\` to \`6.x\`:
131
- - [My original commit message (#1000)](foo)
132
- - [My other commit message (#2000)](foo)
133
-
134
- <!--- Backport version: 1.2.3-mocked -->
135
-
136
- ### Questions ?
137
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
138
- "head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
139
- "title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
140
- },
141
- ]
142
- `);
143
- });
144
- it('returns the expected response', () => {
145
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
146
- });
147
- it('should make correct git commands', () => {
148
- expect(execSpy.mock.calls).toMatchSnapshot();
149
- });
150
- it('logs correctly', () => {
151
- expect(consoleLogSpy.mock.calls.length).toBe(2);
152
- expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
153
- "
154
- Backporting to 6.x:"
155
- `);
156
- expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
157
- });
158
- it('should start the spinner with the correct text', () => {
159
- expect(ora_1.default.mock.calls.map((call) => call[0]))
160
- .toMatchInlineSnapshot(`
161
- Array [
162
- "Pulling latest changes",
163
- "Cherry-picking: My original commit message (#1000)",
164
- "Cherry-picking: My other commit message (#2000)",
165
- "Pushing branch \\"sqren_authenticated:backport/6.x/pr-1000_pr-2000\\"",
166
- undefined,
167
- "Creating pull request",
168
- "Adding labels: backport",
169
- ]
170
- `);
171
- });
172
- });
173
- describe('when commit does not have a pull request reference', () => {
174
- let res;
175
- let createPullRequestCalls;
176
- beforeEach(async () => {
177
- const options = {
178
- assignees: [],
179
- authenticatedUsername: 'sqren_authenticated',
180
- fork: true,
181
- prTitle: '[{targetBranch}] {commitMessages}',
182
- repoName: 'kibana',
183
- repoOwner: 'elastic',
184
- reviewers: [],
185
- sourcePRLabels: [],
186
- targetPRLabels: ['backport'],
187
- author: 'sqren',
188
- };
189
- const commits = [
190
- {
191
- sourceCommit: {
192
- committedDate: 'hhh',
193
- sha: 'mySha',
194
- message: 'My original commit message',
195
- },
196
- sourceBranch: '7.x',
197
- expectedTargetPullRequests: [],
198
- },
199
- ];
200
- const scope = (0, nock_1.default)('https://api.github.com')
201
- .post('/repos/elastic/kibana/pulls')
202
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
203
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
204
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
205
- options,
206
- commits,
207
- targetBranch: '6.x',
208
- });
209
- scope.done();
210
- nock_1.default.cleanAll();
211
- });
212
- it('creates the pull request with commit reference', () => {
213
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
214
- Array [
215
- Object {
216
- "base": "6.x",
217
- "body": "# Backport
218
-
219
- This will backport the following commits from \`7.x\` to \`6.x\`:
220
- - My original commit message (mySha)
221
-
222
- <!--- Backport version: 1.2.3-mocked -->
223
-
224
- ### Questions ?
225
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
226
- "head": "sqren_authenticated:backport/6.x/commit-mySha",
227
- "title": "[6.x] My original commit message",
228
- },
229
- ]
230
- `);
231
- });
232
- it('returns the expected response', () => {
233
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
234
- });
235
- });
236
- describe('when cherry-picking fails', () => {
237
- let res;
238
- let promptSpy;
239
- let execSpy;
240
- let commitsByAuthorCalls;
241
- let createPullRequestCalls;
242
- beforeEach(async () => {
243
- // spies
244
- promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
245
- execSpy = setupExecSpyForCherryPick();
246
- const options = {
247
- assignees: [],
248
- authenticatedUsername: 'sqren_authenticated',
249
- fork: true,
250
- githubApiBaseUrlV4: 'http://localhost/graphql',
251
- prTitle: '[{targetBranch}] {commitMessages}',
252
- repoName: 'kibana',
253
- repoOwner: 'elastic',
254
- reviewers: [],
255
- sourceBranch: 'myDefaultSourceBranch',
256
- sourcePRLabels: [],
257
- targetPRLabels: ['backport'],
258
- author: 'sqren',
259
- };
260
- const scope = (0, nock_1.default)('https://api.github.com')
261
- .post('/repos/elastic/kibana/pulls')
262
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
263
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
264
- commitsByAuthorCalls =
265
- (0, nockHelpers_1.mockGqlRequest)({
266
- name: 'CommitsByAuthor',
267
- statusCode: 200,
268
- body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
269
- });
270
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
271
- options,
272
- commits: [
273
- {
274
- sourceCommit: {
275
- committedDate: '2021-08-18T16:11:38Z',
276
- sha: 'mySha',
277
- message: 'My original commit message',
278
- },
279
- sourceBranch: '7.x',
280
- expectedTargetPullRequests: [],
281
- },
282
- ],
283
- targetBranch: '6.x',
284
- });
285
- scope.done();
286
- nock_1.default.cleanAll();
287
- });
288
- it('creates the pull request with commit reference', () => {
289
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
290
- Array [
291
- Object {
292
- "base": "6.x",
293
- "body": "# Backport
294
-
295
- This will backport the following commits from \`7.x\` to \`6.x\`:
296
- - My original commit message (mySha)
297
-
298
- <!--- Backport version: 1.2.3-mocked -->
299
-
300
- ### Questions ?
301
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
302
- "head": "sqren_authenticated:backport/6.x/commit-mySha",
303
- "title": "[6.x] My original commit message",
304
- },
305
- ]
306
- `);
307
- });
308
- it('returns the expected response', () => {
309
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
310
- });
311
- it('shows the right prompts', () => {
312
- expect(promptSpy.mock.calls.length).toBe(4);
313
- expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
314
- "Fix the following conflicts manually:
315
-
316
- Conflicting files:
317
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
318
-
319
-
320
- Press ENTER when the conflicts are resolved and files are staged"
321
- `);
322
- expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
323
- "Fix the following conflicts manually:
324
-
325
- Conflicting files:
326
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
327
-
328
-
329
- Press ENTER when the conflicts are resolved and files are staged"
330
- `);
331
- expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
332
- "Fix the following conflicts manually:
333
-
334
- Conflicting files:
335
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
336
-
337
-
338
- Press ENTER when the conflicts are resolved and files are staged"
339
- `);
340
- });
341
- it('commitsByAuthor is called with correct arguments', () => {
342
- expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
343
- Object {
344
- "authorId": null,
345
- "commitPath": "conflicting-file.txt",
346
- "dateSince": null,
347
- "dateUntil": "2021-08-18T16:11:38Z",
348
- "maxNumber": 10,
349
- "repoName": "kibana",
350
- "repoOwner": "elastic",
351
- "sourceBranch": "myDefaultSourceBranch",
352
- }
353
- `);
354
- });
355
- it('calls exec correctly', () => {
356
- expect(execSpy.mock.calls).toMatchSnapshot();
357
- });
358
- it('calls ora correctly', () => {
359
- expect(ora_1.default.mock.calls.map((call) => call[0]))
360
- .toMatchInlineSnapshot(`
361
- Array [
362
- "Pulling latest changes",
363
- "Cherry-picking: My original commit message",
364
- "Finalizing cherrypick",
365
- "Pushing branch \\"sqren_authenticated:backport/6.x/commit-mySha\\"",
366
- undefined,
367
- "Creating pull request",
368
- "Adding labels: backport",
369
- ]
370
- `);
371
- });
372
- it('logs correctly', async () => {
373
- expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
374
- "
375
- Backporting to 6.x:"
376
- `);
377
- expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
378
- "
379
- The commit could not be backported due to conflicts
380
- "
381
- `);
382
- expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
383
- "
384
- ----------------------------------------
385
- "
386
- `);
387
- expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
388
- "
389
- ----------------------------------------
390
- "
391
- `);
392
- });
393
- });
394
- });
395
- function setupExecSpyForCherryPick() {
396
- let conflictingFilesCheck = 0;
397
- let unstagedFilesCheck = 0;
398
- return jest
399
- .spyOn(childProcess, 'exec')
400
- .mockImplementation(async (cmd) => {
401
- // createFeatureBranch
402
- if (cmd.includes('git checkout -B')) {
403
- return { stdout: 'create feature branch succeeded', stderr: '' };
404
- }
405
- // git fetch
406
- if (cmd.startsWith('git fetch')) {
407
- return { stderr: '', stdout: '' };
408
- }
409
- // cherrypick
410
- if (cmd === 'git cherry-pick -x mySha') {
411
- throw new ExecError_1.ExecError({ cmd });
412
- }
413
- // getIsCommitInBranch
414
- if (cmd.startsWith('git merge-base --is-ancestor')) {
415
- return { stderr: '', stdout: '' };
416
- }
417
- // getConflictingFiles
418
- if (cmd === 'git --no-pager diff --check') {
419
- conflictingFilesCheck++;
420
- if (conflictingFilesCheck >= 4) {
421
- return { stderr: '', stdout: '' };
422
- }
423
- throw new ExecError_1.ExecError({
424
- code: 2,
425
- cmd,
426
- stdout: `conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n`,
427
- });
428
- }
429
- // getUnstagedFiles
430
- if (cmd === 'git --no-pager diff --name-only') {
431
- unstagedFilesCheck++;
432
- if (unstagedFilesCheck >= 5) {
433
- return { stderr: '', stdout: '' };
434
- }
435
- return { stdout: `conflicting-file.txt\n`, stderr: '' };
436
- }
437
- // addUnstagedFiles
438
- if (cmd === 'git add --update') {
439
- return { stdout: ``, stderr: '' };
440
- }
441
- // finalizeCherrypick
442
- if (cmd.includes('git commit --no-edit')) {
443
- return { stdout: ``, stderr: '' };
444
- }
445
- // pushFeatureBranch
446
- if (cmd.startsWith('git push ')) {
447
- return { stdout: ``, stderr: '' };
448
- }
449
- // deleteFeatureBranch
450
- if (cmd.includes('git branch -D ')) {
451
- return { stdout: ``, stderr: '' };
452
- }
453
- // getIsMergeCommit
454
- if (cmd.startsWith('git rev-list -1 --merges')) {
455
- return { stdout: ``, stderr: '' };
456
- }
457
- throw new Error(`Missing exec mock for "${cmd}"`);
458
- });
459
- }
@@ -1 +0,0 @@
1
- export {};