backport 6.3.0-beta → 6.3.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 (99) hide show
  1. package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
  2. package/dist/entrypoint.cli.e2e.private.test.js +277 -0
  3. package/dist/entrypoint.cli.js +0 -0
  4. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  5. package/dist/entrypoint.cli.private.test.js +46 -0
  6. package/dist/options/cliArgs.test.d.ts +1 -0
  7. package/dist/options/cliArgs.test.js +170 -0
  8. package/dist/options/config/config.test.d.ts +1 -0
  9. package/dist/options/config/config.test.js +32 -0
  10. package/dist/options/config/globalConfig.test.d.ts +1 -0
  11. package/dist/options/config/globalConfig.test.js +61 -0
  12. package/dist/options/config/projectConfig.test.d.ts +1 -0
  13. package/dist/options/config/projectConfig.test.js +109 -0
  14. package/dist/options/options.test.d.ts +1 -0
  15. package/dist/options/options.test.js +371 -0
  16. package/dist/runSequentially.test.d.ts +1 -0
  17. package/dist/runSequentially.test.js +218 -0
  18. package/dist/scripts/postinstall.test.d.ts +1 -0
  19. package/dist/scripts/postinstall.test.js +53 -0
  20. package/dist/services/env.test.d.ts +1 -0
  21. package/dist/services/env.test.js +21 -0
  22. package/dist/services/git.integration.test.d.ts +1 -0
  23. package/dist/services/git.integration.test.js +267 -0
  24. package/dist/services/git.test.d.ts +1 -0
  25. package/dist/services/git.test.js +518 -0
  26. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  27. package/dist/services/github/commitFormatters.test.js +11 -0
  28. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  29. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  30. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  31. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  32. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  33. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  34. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  35. package/dist/services/github/v4/apiRequestV4.test.js +82 -0
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  37. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  38. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  39. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  40. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  41. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  43. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
  44. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  45. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
  46. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  47. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  49. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
  50. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  51. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  52. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  53. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  54. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  55. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  56. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +4 -3
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  60. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  61. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  62. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
  63. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  64. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  65. package/dist/services/prompt.test.d.ts +1 -0
  66. package/dist/services/prompt.test.js +134 -0
  67. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  68. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
  69. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  70. package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
  71. package/dist/test/ExecError.d.ts +16 -0
  72. package/dist/test/ExecError.js +15 -0
  73. package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
  74. package/dist/test/backport-e2e.mutation.test.js +347 -0
  75. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -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 +32 -0
  83. package/dist/test/private/getDevAccessToken.d.ts +1 -0
  84. package/dist/test/private/getDevAccessToken.js +25 -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 +59 -0
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -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.test.d.ts +1 -0
  96. package/dist/ui/maybeSetupRepo.test.js +204 -0
  97. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  98. package/dist/utils/excludeUndefined.test.js +24 -0
  99. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /*
3
+ * This file is included in `setupFiles` in jest.config.js
4
+ * It will be run once per test file
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const packageVersionModule = __importStar(require("../../utils/packageVersion"));
27
+ const mocks_1 = require("../mocks");
28
+ /* eslint-disable @typescript-eslint/no-empty-function */
29
+ jest.mock('find-up', () => {
30
+ return jest.fn(async () => '/path/to/project/config');
31
+ });
32
+ // @ts-expect-error
33
+ // eslint-disable-next-line no-import-assign
34
+ packageVersionModule.PACKAGE_VERSION = '1.2.3';
35
+ jest.mock('make-dir', () => {
36
+ return jest.fn(() => Promise.resolve('/some/path'));
37
+ });
38
+ jest.mock('del', () => {
39
+ return jest.fn(async (path) => `Attempted to delete ${path}`);
40
+ });
41
+ (0, mocks_1.mockOra)();
42
+ // silence logger
43
+ jest.mock('../../services/logger', () => {
44
+ const spy = jest.fn();
45
+ return {
46
+ initLogger: jest.fn(),
47
+ redactAccessToken: jest.fn((str) => str),
48
+ consoleLog: jest.fn(),
49
+ updateLogger: jest.fn(),
50
+ logger: {
51
+ spy: spy,
52
+ info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
53
+ verbose: (msg, meta) => spy(`[VERBOSE] ${msg}`, meta),
54
+ warn: (msg, meta) => spy(`[WARN] ${msg}`, meta),
55
+ error: (msg, meta) => spy(`[ERROR] ${msg}`, meta),
56
+ debug: (msg, meta) => spy(`[DEBUG] ${msg}`, meta),
57
+ },
58
+ };
59
+ });
@@ -0,0 +1,455 @@
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 -->
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 -->
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 -->
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
+ throw new Error(`Missing exec mock for "${cmd}"`);
454
+ });
455
+ }
@@ -0,0 +1 @@
1
+ export {};