backport 7.3.5 → 8.0.0

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 (87) hide show
  1. package/README.md +13 -18
  2. package/dist/backportRun.d.ts +14 -3
  3. package/dist/backportRun.js +59 -37
  4. package/dist/entrypoint.cli.js +1 -1
  5. package/dist/entrypoint.module.d.ts +8 -3
  6. package/dist/entrypoint.module.js +6 -10
  7. package/dist/entrypoint.module.private.test.js +129 -330
  8. package/dist/options/ConfigOptions.d.ts +2 -2
  9. package/dist/options/cliArgs.d.ts +10 -6
  10. package/dist/options/cliArgs.js +32 -21
  11. package/dist/options/cliArgs.test.js +3 -3
  12. package/dist/options/config/config.d.ts +2 -2
  13. package/dist/options/config/config.js +2 -2
  14. package/dist/options/config/globalConfig.d.ts +2 -2
  15. package/dist/options/config/globalConfig.js +13 -10
  16. package/dist/options/config/projectConfig.d.ts +2 -2
  17. package/dist/options/config/projectConfig.js +3 -3
  18. package/dist/options/config/projectConfig.test.js +19 -7
  19. package/dist/options/config/readConfigFile.d.ts +4 -4
  20. package/dist/options/options.d.ts +4 -5
  21. package/dist/options/options.js +2 -3
  22. package/dist/options/options.test.js +7 -4
  23. package/dist/runSequentially.d.ts +5 -1
  24. package/dist/runSequentially.js +23 -8
  25. package/dist/scripts/postinstall.js +1 -0
  26. package/dist/scripts/postinstall.test.js +5 -1
  27. package/dist/services/HandledError.d.ts +6 -2
  28. package/dist/services/HandledError.js +8 -8
  29. package/dist/services/child-process-promisified.d.ts +19 -3
  30. package/dist/services/child-process-promisified.js +46 -17
  31. package/dist/services/git.d.ts +6 -7
  32. package/dist/services/git.integration.test.js +381 -65
  33. package/dist/services/git.js +188 -126
  34. package/dist/services/git.private.test.d.ts +1 -0
  35. package/dist/services/git.private.test.js +618 -0
  36. package/dist/services/git.test.js +167 -158
  37. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  38. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  39. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  40. package/dist/services/github/v3/createPullRequest.js +3 -1
  41. package/dist/services/github/v3/createStatusComment.js +16 -16
  42. package/dist/services/github/v3/createStatusComment.test.js +17 -5
  43. package/dist/services/github/v4/apiRequestV4.js +6 -9
  44. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  45. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  46. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  53. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  54. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
  55. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  56. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  60. package/dist/services/logger.d.ts +1 -4
  61. package/dist/services/logger.js +14 -19
  62. package/dist/services/test.d.ts +1 -0
  63. package/dist/services/test.js +23 -0
  64. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  65. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
  66. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
  67. package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
  68. package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
  69. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  70. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  71. package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
  72. package/dist/test/sandbox.js +5 -1
  73. package/dist/test/setupFiles/automatic-mocks.js +16 -12
  74. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
  75. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  76. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  77. package/dist/ui/getGitConfigAuthor.js +1 -1
  78. package/dist/ui/getTargetBranches.test.js +5 -1
  79. package/dist/ui/ora.d.ts +1 -8
  80. package/dist/ui/setupRepo.js +1 -1
  81. package/dist/ui/setupRepo.test.js +98 -61
  82. package/dist/utils/isErrnoError.d.ts +2 -0
  83. package/dist/utils/isErrnoError.js +7 -0
  84. package/dist/utils/packageVersion.d.ts +1 -1
  85. package/dist/utils/packageVersion.js +1 -1
  86. package/package.json +13 -13
  87. package/yarn.lock +414 -695
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -26,10 +30,7 @@ const os_1 = __importDefault(require("os"));
26
30
  const nock_1 = __importDefault(require("nock"));
27
31
  const ora_1 = __importDefault(require("ora"));
28
32
  const childProcess = __importStar(require("../services/child-process-promisified"));
29
- const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
30
33
  const logger = __importStar(require("../services/logger"));
31
- const prompts = __importStar(require("../services/prompts"));
32
- const ExecError_1 = require("../test/ExecError");
33
34
  const nockHelpers_1 = require("../test/nockHelpers");
34
35
  const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
35
36
  describe('cherrypickAndCreateTargetPullRequest', () => {
@@ -39,9 +40,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
39
40
  beforeEach(() => {
40
41
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
41
42
  execSpy = jest
42
- .spyOn(childProcess, 'exec')
43
+ .spyOn(childProcess, 'spawnPromise')
43
44
  // mock all exec commands to respond without errors
44
- .mockResolvedValue({ stdout: '', stderr: '' });
45
+ .mockResolvedValue({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
45
46
  consoleLogSpy = jest.spyOn(logger, 'consoleLog');
46
47
  // ensure labels are added
47
48
  addLabelsScope = (0, nock_1.default)('https://api.github.com')
@@ -249,14 +250,8 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
249
250
  });
250
251
  describe('when cherry-picking fails', () => {
251
252
  let res;
252
- let promptSpy;
253
- let execSpy;
254
- let commitsByAuthorCalls;
255
253
  let createPullRequestCalls;
256
254
  beforeEach(async () => {
257
- // spies
258
- promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
259
- execSpy = setupExecSpyForCherryPick();
260
255
  const options = {
261
256
  assignees: [],
262
257
  authenticatedUsername: 'sqren_authenticated',
@@ -276,12 +271,6 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
276
271
  .post('/repos/elastic/kibana/pulls')
277
272
  .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
278
273
  createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
279
- commitsByAuthorCalls =
280
- (0, nockHelpers_1.mockGqlRequest)({
281
- name: 'CommitsByAuthor',
282
- statusCode: 200,
283
- body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
284
- });
285
274
  res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
286
275
  options,
287
276
  commits: [
@@ -327,146 +316,5 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
327
316
  it('returns the expected response', () => {
328
317
  expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
329
318
  });
330
- it('shows the right prompts', () => {
331
- expect(promptSpy.mock.calls.length).toBe(4);
332
- expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
333
- "Fix the following conflicts manually:
334
-
335
- Conflicting files:
336
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
337
-
338
-
339
- Press ENTER when the conflicts are resolved and files are staged"
340
- `);
341
- expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
342
- "Fix the following conflicts manually:
343
-
344
- Conflicting files:
345
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
346
-
347
-
348
- Press ENTER when the conflicts are resolved and files are staged"
349
- `);
350
- expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
351
- "Fix the following conflicts manually:
352
-
353
- Conflicting files:
354
- - /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
355
-
356
-
357
- Press ENTER when the conflicts are resolved and files are staged"
358
- `);
359
- });
360
- it('commitsByAuthor is called with correct arguments', () => {
361
- expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
362
- Object {
363
- "authorId": null,
364
- "commitPath": "conflicting-file.txt",
365
- "dateSince": null,
366
- "dateUntil": "2021-08-18T16:11:38Z",
367
- "maxNumber": 10,
368
- "repoName": "kibana",
369
- "repoOwner": "elastic",
370
- "sourceBranch": "myDefaultSourceBranch",
371
- }
372
- `);
373
- });
374
- it('calls exec correctly', () => {
375
- expect(execSpy.mock.calls).toMatchSnapshot();
376
- });
377
- it('calls ora correctly', () => {
378
- expect(ora_1.default.mock.calls.map((call) => call[0].text))
379
- .toMatchInlineSnapshot(`
380
- Array [
381
- "Pulling latest changes",
382
- "Cherry-picking: My original commit message",
383
- "Finalizing cherrypick",
384
- "Pushing branch \\"sqren:backport/6.x/commit-mySha\\"",
385
- undefined,
386
- "Creating pull request",
387
- "Adding labels: backport",
388
- ]
389
- `);
390
- });
391
- it('logs correctly', async () => {
392
- expect(consoleLogSpy.mock.calls.map((call) => call[0]).join(''))
393
- .toMatchInlineSnapshot(`
394
- "
395
- Backporting to 6.x:
396
- The commit could not be backported due to conflicts
397
- Please fix the conflicts in /myHomeDir/.backport/repositories/elastic/kibana
398
- ----------------------------------------
399
-
400
- ----------------------------------------
401
-
402
- ----------------------------------------
403
- View pull request: myHtmlUrl"
404
- `);
405
- });
406
319
  });
407
320
  });
408
- function setupExecSpyForCherryPick() {
409
- let conflictingFilesCheck = 0;
410
- let unstagedFilesCheck = 0;
411
- return jest
412
- .spyOn(childProcess, 'exec')
413
- .mockImplementation(async (cmd) => {
414
- // createFeatureBranch
415
- if (cmd.includes('git checkout -B')) {
416
- return { stdout: 'create feature branch succeeded', stderr: '' };
417
- }
418
- // git fetch
419
- if (cmd.startsWith('git fetch')) {
420
- return { stderr: '', stdout: '' };
421
- }
422
- // emulate cherrypick exception
423
- if (cmd.includes('cherry-pick -x mySha')) {
424
- throw new ExecError_1.ExecError({ cmd, code: 128 });
425
- }
426
- // getIsCommitInBranch
427
- if (cmd.startsWith('git merge-base --is-ancestor')) {
428
- return { stderr: '', stdout: '' };
429
- }
430
- // getConflictingFiles
431
- if (cmd === 'git --no-pager diff --check') {
432
- conflictingFilesCheck++;
433
- if (conflictingFilesCheck >= 4) {
434
- return { stderr: '', stdout: '' };
435
- }
436
- throw new ExecError_1.ExecError({
437
- code: 2,
438
- cmd,
439
- stdout: `conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n`,
440
- });
441
- }
442
- // getUnstagedFiles
443
- if (cmd === 'git --no-pager diff --name-only') {
444
- unstagedFilesCheck++;
445
- if (unstagedFilesCheck >= 5) {
446
- return { stderr: '', stdout: '' };
447
- }
448
- return { stdout: `conflicting-file.txt\n`, stderr: '' };
449
- }
450
- // addUnstagedFiles
451
- if (cmd === 'git add --update') {
452
- return { stdout: ``, stderr: '' };
453
- }
454
- // finalizeCherrypick
455
- if (cmd.includes('git commit --no-edit')) {
456
- return { stdout: ``, stderr: '' };
457
- }
458
- // pushFeatureBranch
459
- if (cmd.startsWith('git push ')) {
460
- return { stdout: ``, stderr: '' };
461
- }
462
- // deleteFeatureBranch
463
- if (cmd.includes('git branch -D ')) {
464
- return { stdout: ``, stderr: '' };
465
- }
466
- // getIsMergeCommit
467
- if (cmd.startsWith('git rev-list -1 --merges')) {
468
- return { stdout: ``, stderr: '' };
469
- }
470
- throw new Error(`Missing exec mock for "${cmd}"`);
471
- });
472
- }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGitConfigAuthor = void 0;
4
4
  const git_1 = require("../services/git");
5
5
  async function getGitConfigAuthor(options) {
6
- const localRepoPath = await (0, git_1.getLocalRepoPath)(options);
6
+ const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
7
7
  if (!localRepoPath) {
8
8
  return;
9
9
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/ui/ora.d.ts CHANGED
@@ -1,9 +1,2 @@
1
1
  import oraOriginal from 'ora';
2
- export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora | {
3
- start: (text?: string | undefined) => any;
4
- succeed: () => void;
5
- stop: () => void;
6
- fail: () => void;
7
- stopAndPersist: () => void;
8
- text: string;
9
- };
2
+ export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora;
@@ -16,7 +16,7 @@ async function setupRepo(options) {
16
16
  if (!isAlreadyCloned) {
17
17
  const spinner = (0, ora_1.ora)(options.ci).start();
18
18
  try {
19
- const localRepoPath = await (0, git_1.getLocalRepoPath)(options);
19
+ const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
20
20
  const remoteRepoPath = (0, git_1.getRemoteUrl)(options, options.repoOwner);
21
21
  const sourcePath = localRepoPath ? localRepoPath : remoteRepoPath;
22
22
  // show the full path for local repos, but only the host name for remote repos (to avoid showing the access token)
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -29,12 +33,12 @@ const gitModule = __importStar(require("../services/git"));
29
33
  const mocks_1 = require("../test/mocks");
30
34
  const setupRepo_1 = require("./setupRepo");
31
35
  describe('setupRepo', () => {
32
- let execSpy;
36
+ let spawnSpy;
33
37
  beforeEach(() => {
34
38
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
35
- execSpy = jest
36
- .spyOn(childProcess, 'exec')
37
- .mockResolvedValue({ stderr: '', stdout: '' });
39
+ spawnSpy = jest
40
+ .spyOn(childProcess, 'spawnPromise')
41
+ .mockResolvedValue({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
38
42
  });
39
43
  afterEach(() => {
40
44
  jest.restoreAllMocks();
@@ -42,10 +46,10 @@ describe('setupRepo', () => {
42
46
  describe('if an error occurs while cloning', () => {
43
47
  it('should delete repo', async () => {
44
48
  expect.assertions(2);
45
- execSpy = jest
46
- .spyOn(childProcess, 'execAsCallback')
47
- .mockImplementation((cmd) => {
48
- if (cmd.startsWith('git clone')) {
49
+ jest
50
+ .spyOn(childProcess, 'spawnOriginal')
51
+ .mockImplementation((cmd, cmdArgs) => {
52
+ if (cmdArgs.includes('clone')) {
49
53
  throw new Error('Simulated git clone failure');
50
54
  }
51
55
  throw new Error('unknown error');
@@ -60,39 +64,43 @@ describe('setupRepo', () => {
60
64
  });
61
65
  describe('while cloning the repo', () => {
62
66
  it('updates the progress', async () => {
63
- let onCloneComplete;
64
- let dataHandler;
67
+ let onClose;
68
+ let onData;
65
69
  const oraMock = (0, mocks_1.getOraMock)();
66
70
  const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
67
71
  const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
68
- jest.spyOn(gitModule, 'getLocalRepoPath').mockResolvedValue(undefined);
69
72
  jest
70
- .spyOn(childProcess, 'execAsCallback')
73
+ .spyOn(gitModule, 'getLocalSourceRepoPath')
74
+ .mockResolvedValue(undefined);
75
+ jest
76
+ .spyOn(childProcess, 'spawnOriginal')
71
77
  //@ts-expect-error
72
- .mockImplementation((cmdString, cmdOptions, onComplete) => {
73
- // callback should be called to finalize the operation
74
- if (onComplete) {
75
- //@ts-expect-error
76
- onCloneComplete = onComplete;
77
- }
78
+ .mockImplementation(() => {
78
79
  return {
80
+ on: (name, cb) => {
81
+ if (name === 'close') {
82
+ onClose = cb;
83
+ }
84
+ },
79
85
  stderr: {
80
86
  on: (name, handler) => {
81
- dataHandler = handler;
87
+ if (name === 'data') {
88
+ onData = handler;
89
+ }
82
90
  },
83
91
  },
84
92
  };
85
93
  });
86
94
  setTimeout(() => {
87
- dataHandler('Receiving objects: 1%');
88
- dataHandler('Receiving objects: 10%');
89
- dataHandler('Receiving objects: 20%');
90
- dataHandler('Receiving objects: 100%');
91
- dataHandler('Updating files: 1%');
92
- dataHandler('Updating files: 10%');
93
- dataHandler('Updating files: 20%');
94
- dataHandler('Updating files: 100%');
95
- onCloneComplete();
95
+ onData('Receiving objects: 1%');
96
+ onData('Receiving objects: 10%');
97
+ onData('Receiving objects: 20%');
98
+ onData('Receiving objects: 100%');
99
+ onData('Updating files: 1%');
100
+ onData('Updating files: 10%');
101
+ onData('Updating files: 20%');
102
+ onData('Updating files: 100%');
103
+ onClose(0);
96
104
  }, 50);
97
105
  await (0, setupRepo_1.setupRepo)({
98
106
  repoName: 'kibana',
@@ -117,18 +125,23 @@ describe('setupRepo', () => {
117
125
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
118
126
  });
119
127
  });
120
- describe('if repo already exists', () => {
121
- beforeEach(() => {
122
- jest
123
- .spyOn(childProcess, 'execAsCallback')
124
- //@ts-expect-error
125
- .mockImplementation((cmdString, cmdOptions, callback) => {
128
+ describe('if repo is already cloned', () => {
129
+ function mockGitProjectRootPath(value) {
130
+ return (jest
131
+ .spyOn(childProcess, 'spawnPromise')
126
132
  //@ts-expect-error
127
- callback();
128
- return { stderr: { on: () => null } };
129
- });
130
- });
131
- it('should re-create remotes for both source repo and fork', async () => {
133
+ .mockImplementationOnce(async (cmd, cmdArgs) => {
134
+ if (cmdArgs.includes('rev-parse')) {
135
+ return {
136
+ stdout: value,
137
+ };
138
+ }
139
+ }));
140
+ }
141
+ beforeEach(async () => {
142
+ jest.clearAllMocks();
143
+ mockGitProjectRootPath('/myHomeDir/.backport/repositories/elastic/kibana');
144
+ jest.spyOn(gitModule, 'cloneRepo');
132
145
  await (0, setupRepo_1.setupRepo)({
133
146
  accessToken: 'myAccessToken',
134
147
  authenticatedUsername: 'sqren_authenticated',
@@ -138,12 +151,22 @@ describe('setupRepo', () => {
138
151
  repoName: 'kibana',
139
152
  repoOwner: 'elastic',
140
153
  });
141
- expect(execSpy.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
154
+ });
155
+ it('should not delete the existing repo', () => {
156
+ expect(del_1.default).not.toHaveBeenCalled();
157
+ });
158
+ it('should not clone repo', () => {
159
+ expect(gitModule.cloneRepo).not.toHaveBeenCalled();
160
+ });
161
+ it('should re-create remotes for both source repo and fork', () => {
162
+ expect(spawnSpy.mock.calls.map(([cmd, cmdArgs, cwd]) => ({
163
+ cmd: `${cmd} ${cmdArgs.join(' ')}`,
164
+ cwd,
165
+ }))).toEqual([
142
166
  {
143
167
  cmd: 'git rev-parse --show-toplevel',
144
168
  cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
145
169
  },
146
- { cmd: 'git remote --verbose', cwd: '/path/to/source/repo' },
147
170
  {
148
171
  cmd: 'git remote rm origin',
149
172
  cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
@@ -167,19 +190,30 @@ describe('setupRepo', () => {
167
190
  ]);
168
191
  });
169
192
  });
193
+ function mockGitClone() {
194
+ jest
195
+ .spyOn(childProcess, 'spawnOriginal')
196
+ //@ts-expect-error
197
+ .mockImplementation((cmd, cmdArgs) => {
198
+ if (cmdArgs.includes('clone')) {
199
+ return {
200
+ on: (name, cb) => {
201
+ if (name === 'close') {
202
+ //@ts-expect-error
203
+ cb(0);
204
+ }
205
+ },
206
+ stderr: { on: () => null },
207
+ };
208
+ }
209
+ });
210
+ }
170
211
  describe('if repo does not exists locally', () => {
171
212
  let spinnerSuccessSpy;
172
213
  beforeEach(async () => {
173
214
  const oraMock = (0, mocks_1.getOraMock)();
174
215
  spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
175
- jest
176
- .spyOn(childProcess, 'execAsCallback')
177
- //@ts-expect-error
178
- .mockImplementation((cmdString, cmdOptions, callback) => {
179
- //@ts-expect-error
180
- callback();
181
- return { stderr: { on: () => null } };
182
- });
216
+ mockGitClone();
183
217
  await (0, setupRepo_1.setupRepo)({
184
218
  accessToken: 'myAccessToken',
185
219
  gitHostname: 'github.com',
@@ -190,7 +224,12 @@ describe('setupRepo', () => {
190
224
  });
191
225
  it('should clone it from github.com', async () => {
192
226
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
193
- expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
227
+ expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
228
+ 'clone',
229
+ 'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
230
+ '/myHomeDir/.backport/repositories/elastic/kibana',
231
+ '--progress',
232
+ ]);
194
233
  });
195
234
  });
196
235
  describe('if repo exists locally', () => {
@@ -199,19 +238,12 @@ describe('setupRepo', () => {
199
238
  const oraMock = (0, mocks_1.getOraMock)();
200
239
  spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
201
240
  jest
202
- .spyOn(gitModule, 'getLocalRepoPath')
241
+ .spyOn(gitModule, 'getLocalSourceRepoPath')
203
242
  .mockResolvedValue('/path/to/source/repo');
204
243
  jest
205
244
  .spyOn(gitModule, 'getGitConfig')
206
245
  .mockResolvedValue('email-or-username');
207
- jest
208
- .spyOn(childProcess, 'execAsCallback')
209
- //@ts-expect-error
210
- .mockImplementation((cmdString, cmdOptions, callback) => {
211
- //@ts-expect-error
212
- callback();
213
- return { stderr: { on: () => null } };
214
- });
246
+ mockGitClone();
215
247
  await (0, setupRepo_1.setupRepo)({
216
248
  repoName: 'kibana',
217
249
  repoOwner: 'elastic',
@@ -220,7 +252,12 @@ describe('setupRepo', () => {
220
252
  });
221
253
  it('should clone it from local folder', async () => {
222
254
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
223
- expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
255
+ expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
256
+ 'clone',
257
+ '/path/to/source/repo',
258
+ '/myHomeDir/.backport/repositories/elastic/kibana',
259
+ '--progress',
260
+ ]);
224
261
  });
225
262
  });
226
263
  describe('if `repoPath` is a parent of current working directory (cwd)', () => {
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function isErrnoError(error: unknown): error is NodeJS.ErrnoException;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isErrnoError = void 0;
4
+ function isErrnoError(error) {
5
+ return error instanceof Error && 'code' in error;
6
+ }
7
+ exports.isErrnoError = isErrnoError;
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "7.3.5";
1
+ export declare const PACKAGE_VERSION = "8.0.0";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '7.3.5';
4
+ exports.PACKAGE_VERSION = '8.0.0';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "7.3.5",
17
+ "version": "8.0.0",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@octokit/rest": "^18.12.0",
68
- "axios": "^0.25.0",
68
+ "axios": "^0.26.0",
69
69
  "dedent": "^0.7.0",
70
70
  "del": "^6.0.0",
71
71
  "dotenv": "^16.0.0",
@@ -82,22 +82,22 @@
82
82
  "utility-types": "^3.10.0",
83
83
  "winston": "^3.6.0",
84
84
  "yargs": "^17.3.1",
85
- "yargs-parser": "^21.0.0"
85
+ "yargs-parser": "^21.0.1"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/core-js": "^2.5.5",
89
89
  "@types/dedent": "^0.7.0",
90
90
  "@types/inquirer": "^8.2.0",
91
91
  "@types/jest": "^27.4.1",
92
- "@types/lodash": "^4.14.178",
92
+ "@types/lodash": "^4.14.179",
93
93
  "@types/node": "^17.0.21",
94
94
  "@types/safe-json-stringify": "^1.1.2",
95
- "@types/yargs": "^17.0.8",
96
- "@types/yargs-parser": "^20.2.1",
97
- "@typescript-eslint/eslint-plugin": "^5.12.1",
98
- "@typescript-eslint/parser": "^5.12.1",
99
- "eslint": "^8.9.0",
100
- "eslint-config-prettier": "^8.4.0",
95
+ "@types/yargs": "^17.0.9",
96
+ "@types/yargs-parser": "^21.0.0",
97
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
98
+ "@typescript-eslint/parser": "^5.14.0",
99
+ "eslint": "^8.10.0",
100
+ "eslint-config-prettier": "^8.5.0",
101
101
  "eslint-plugin-import": "^2.25.4",
102
102
  "eslint-plugin-jest": "^26.1.1",
103
103
  "eslint-plugin-prettier": "^4.0.0",
@@ -105,12 +105,12 @@
105
105
  "husky": "^7.0.4",
106
106
  "jest": "^27.5.1",
107
107
  "jest-snapshot-serializer-ansi": "^1.0.0",
108
- "lint-staged": "^12.3.4",
108
+ "lint-staged": "^12.3.5",
109
109
  "nock": "^13.2.4",
110
110
  "prettier": "^2.5.1",
111
111
  "strip-ansi": "^6.0.1",
112
112
  "ts-jest": "^27.1.3",
113
- "ts-node": "^10.5.0",
114
- "typescript": "^4.5.5"
113
+ "ts-node": "^10.7.0",
114
+ "typescript": "^4.6.2"
115
115
  }
116
116
  }