backport 7.4.0 → 8.2.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 (244) hide show
  1. package/README.md +15 -16
  2. package/dist/backportRun.d.ts +12 -6
  3. package/dist/backportRun.js +64 -62
  4. package/dist/entrypoint.cli.js +4 -8
  5. package/dist/entrypoint.module.d.ts +13 -6
  6. package/dist/entrypoint.module.js +14 -20
  7. package/dist/entrypoint.module.private.test.js +47 -346
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +60 -0
  18. package/dist/lib/env.d.ts +9 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +210 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +138 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +566 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/github/v4/validateTargetBranches.d.ts +14 -0
  125. package/dist/lib/github/v4/validateTargetBranches.js +46 -0
  126. package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
  127. package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
  128. package/dist/lib/logger.d.ts +11 -0
  129. package/dist/lib/logger.js +80 -0
  130. package/dist/lib/ora.d.ts +2 -0
  131. package/dist/lib/ora.js +21 -0
  132. package/dist/lib/prompt.test.d.ts +1 -0
  133. package/dist/lib/prompt.test.js +139 -0
  134. package/dist/lib/prompts.d.ts +17 -0
  135. package/dist/lib/prompts.js +132 -0
  136. package/dist/lib/remoteConfig.d.ts +20 -0
  137. package/dist/lib/remoteConfig.js +52 -0
  138. package/dist/lib/sequentially.d.ts +1 -0
  139. package/dist/lib/sequentially.js +10 -0
  140. package/dist/lib/setupRepo.d.ts +2 -0
  141. package/dist/lib/setupRepo.js +56 -0
  142. package/dist/lib/setupRepo.test.d.ts +1 -0
  143. package/dist/lib/setupRepo.test.js +278 -0
  144. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  145. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  146. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  147. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  148. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  149. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  150. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  151. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  152. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  153. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  154. package/dist/options/ConfigOptions.d.ts +4 -2
  155. package/dist/options/cliArgs.d.ts +14 -6
  156. package/dist/options/cliArgs.js +50 -22
  157. package/dist/options/cliArgs.test.js +128 -4
  158. package/dist/options/config/config.d.ts +5 -4
  159. package/dist/options/config/config.js +3 -5
  160. package/dist/options/config/config.test.js +0 -1
  161. package/dist/options/config/globalConfig.d.ts +5 -3
  162. package/dist/options/config/globalConfig.js +17 -14
  163. package/dist/options/config/readConfigFile.d.ts +5 -3
  164. package/dist/options/config/readConfigFile.js +2 -2
  165. package/dist/options/options.d.ts +41 -5
  166. package/dist/options/options.js +24 -24
  167. package/dist/options/options.test.js +117 -55
  168. package/dist/runSequentially.d.ts +14 -9
  169. package/dist/runSequentially.js +27 -12
  170. package/dist/scripts/postinstall.js +4 -3
  171. package/dist/scripts/postinstall.test.js +6 -2
  172. package/dist/services/BackportError.d.ts +19 -0
  173. package/dist/services/BackportError.js +29 -0
  174. package/dist/services/HandledBackportError.d.ts +19 -0
  175. package/dist/services/HandledBackportError.js +29 -0
  176. package/dist/services/HandledError.d.ts +2 -2
  177. package/dist/services/HandledError.js +7 -7
  178. package/dist/services/child-process-promisified.d.ts +19 -3
  179. package/dist/services/child-process-promisified.js +46 -17
  180. package/dist/services/git.d.ts +6 -7
  181. package/dist/services/git.integration.test.js +381 -65
  182. package/dist/services/git.js +189 -123
  183. package/dist/services/git.private.test.d.ts +1 -0
  184. package/dist/services/git.private.test.js +618 -0
  185. package/dist/services/git.test.js +167 -124
  186. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  187. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  188. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  189. package/dist/services/github/v3/createPullRequest.js +4 -2
  190. package/dist/services/github/v3/createStatusComment.js +16 -17
  191. package/dist/services/github/v3/createStatusComment.test.js +20 -9
  192. package/dist/services/github/v4/apiRequestV4.js +2 -2
  193. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  194. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  195. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
  196. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
  197. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
  198. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
  199. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
  200. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
  201. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
  202. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  203. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
  204. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  205. package/dist/services/logger.js +5 -1
  206. package/dist/services/test.d.ts +1 -0
  207. package/dist/services/test.js +23 -0
  208. package/dist/state.d.ts +0 -0
  209. package/dist/state.js +1 -0
  210. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  211. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
  212. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +53 -75
  213. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
  214. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
  215. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
  216. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
  217. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
  218. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
  219. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
  220. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
  221. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +28 -29
  222. package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
  223. package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
  224. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  225. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +28 -21
  226. package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -8
  227. package/dist/test/sandbox.js +5 -1
  228. package/dist/test/setupFiles/automatic-mocks.js +6 -2
  229. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
  230. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  231. package/dist/ui/getCommits.js +2 -2
  232. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  233. package/dist/ui/getGitConfigAuthor.js +1 -1
  234. package/dist/ui/getTargetBranches.js +3 -3
  235. package/dist/ui/getTargetBranches.test.js +5 -1
  236. package/dist/ui/ora.d.ts +1 -8
  237. package/dist/ui/setupRepo.js +3 -3
  238. package/dist/ui/setupRepo.test.js +98 -61
  239. package/dist/utils/isErrnoError.d.ts +2 -0
  240. package/dist/utils/isErrnoError.js +7 -0
  241. package/dist/utils/packageVersion.d.ts +1 -1
  242. package/dist/utils/packageVersion.js +1 -1
  243. package/package.json +19 -19
  244. package/yarn.lock +472 -701
@@ -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];
@@ -24,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
29
  const os_1 = __importDefault(require("os"));
26
30
  const childProcess = __importStar(require("../services/child-process-promisified"));
27
- const ExecError_1 = require("../test/ExecError");
28
31
  const git_1 = require("./git");
29
32
  beforeEach(() => {
30
33
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
@@ -35,9 +38,11 @@ afterEach(() => {
35
38
  const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
36
39
  describe('getUnstagedFiles', () => {
37
40
  it('should split lines and remove empty', async () => {
38
- jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
41
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
39
42
  stdout: 'conflicting-file.txt\nconflicting-file2.txt\n',
40
43
  stderr: '',
44
+ code: 0,
45
+ cmdArgs: [],
41
46
  });
42
47
  const options = {
43
48
  repoOwner: 'elastic',
@@ -49,9 +54,11 @@ describe('getUnstagedFiles', () => {
49
54
  ]);
50
55
  });
51
56
  it('should not error on empty', async () => {
52
- jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
57
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
53
58
  stdout: '',
54
59
  stderr: '',
60
+ code: 0,
61
+ cmdArgs: [],
55
62
  });
56
63
  const options = {
57
64
  repoOwner: 'elastic',
@@ -65,13 +72,15 @@ describe('getLocalConfigFileCommitDate', () => {
65
72
  const res = {
66
73
  stdout: 'Wed Dec 16 10:10:39 2020 -0800\n',
67
74
  stderr: '',
75
+ code: 0,
76
+ cmdArgs: [],
68
77
  };
69
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
78
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
70
79
  expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(1608142239000);
71
80
  });
72
81
  it('returns empty when file does not exists', async () => {
73
- const res = { stdout: '', stderr: '' };
74
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
82
+ const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
83
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
75
84
  expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
76
85
  });
77
86
  it('handles errors', async () => {
@@ -83,19 +92,24 @@ describe('getLocalConfigFileCommitDate', () => {
83
92
  stdout: '',
84
93
  stderr: 'any error',
85
94
  };
86
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
95
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
87
96
  expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
88
97
  });
89
98
  });
90
99
  describe('isLocalConfigFileUntracked', () => {
91
100
  it('returns "false" if file does not exist', async () => {
92
- const res = { stdout: '', stderr: '' };
93
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
101
+ const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
102
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
94
103
  expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(false);
95
104
  });
96
105
  it('returns "true" if file is untracked', async () => {
97
- const res = { stdout: '.backportrc.json\n', stderr: '' };
98
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
106
+ const res = {
107
+ stdout: '.backportrc.json\n',
108
+ stderr: '',
109
+ code: 0,
110
+ cmdArgs: [],
111
+ };
112
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
99
113
  expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(true);
100
114
  });
101
115
  it('handles errors', async () => {
@@ -107,24 +121,29 @@ describe('isLocalConfigFileUntracked', () => {
107
121
  stdout: '',
108
122
  stderr: 'any error',
109
123
  };
110
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
124
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
111
125
  expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(undefined);
112
126
  });
113
127
  });
114
128
  describe('isLocalConfigFileModified', () => {
115
129
  it('returns "false" if file does not exist', async () => {
116
- const res = { stdout: '', stderr: '' };
117
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
130
+ const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
131
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
118
132
  expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
119
133
  });
120
134
  it('returns "false" if file is untracked', async () => {
121
- const res = { stdout: '', stderr: '' };
122
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
135
+ const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
136
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
123
137
  expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
124
138
  });
125
139
  it('returns "true" if file is staged', async () => {
126
- const res = { stdout: '.backportrc.json\n', stderr: '' };
127
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
140
+ const res = {
141
+ stdout: '.backportrc.json\n',
142
+ stderr: '',
143
+ code: 0,
144
+ cmdArgs: [],
145
+ };
146
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
128
147
  expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(true);
129
148
  });
130
149
  it('handles errors', async () => {
@@ -136,8 +155,8 @@ describe('isLocalConfigFileModified', () => {
136
155
  stdout: '',
137
156
  stderr: 'any error',
138
157
  };
139
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
140
- expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(undefined);
158
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
159
+ expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toBe(false);
141
160
  });
142
161
  });
143
162
  describe('getRepoInfoFromGitRemotes', () => {
@@ -152,8 +171,10 @@ describe('getRepoInfoFromGitRemotes', () => {
152
171
  'sqren\tgit@github.com:sqren/kibana.git (fetch)\n' +
153
172
  'sqren\tgit@github.com:sqren/kibana.git (push)\n',
154
173
  stderr: '',
174
+ code: 0,
175
+ cmdArgs: [],
155
176
  };
156
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
177
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
157
178
  expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
158
179
  { repoName: 'kibana', repoOwner: 'john.doe' },
159
180
  { repoName: 'kibana', repoOwner: 'elastic' },
@@ -162,18 +183,20 @@ describe('getRepoInfoFromGitRemotes', () => {
162
183
  ]);
163
184
  });
164
185
  it('returns repoName and repoOwner https remotes', async () => {
165
- jest.spyOn(childProcess, 'exec').mockResolvedValue({
186
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue({
166
187
  stdout: 'origin\thttps://github.com/shay/elasticsearch.git (fetch)\n' +
167
188
  'origin\thttps://github.com/shay/elasticsearch.git (push)\n',
168
189
  stderr: '',
190
+ code: 0,
191
+ cmdArgs: [],
169
192
  });
170
193
  expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
171
194
  { repoName: 'elasticsearch', repoOwner: 'shay' },
172
195
  ]);
173
196
  });
174
197
  it('returns undefined when no remotes exist', async () => {
175
- const res = { stdout: '', stderr: '' };
176
- jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
198
+ const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
199
+ jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
177
200
  expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
178
201
  });
179
202
  it('handles errors', async () => {
@@ -185,21 +208,19 @@ describe('getRepoInfoFromGitRemotes', () => {
185
208
  stdout: '',
186
209
  stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
187
210
  };
188
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
211
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
189
212
  expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
190
213
  });
191
214
  });
192
215
  describe('getConflictingFiles', () => {
193
216
  it('should split by linebreak and remove empty and duplicate items', async () => {
194
- const err = {
195
- killed: false,
217
+ const err = new childProcess.SpawnError({
196
218
  code: 2,
197
- signal: null,
198
- cmd: 'git --no-pager diff --check',
219
+ cmdArgs: ['--no-pager', 'diff', '--check'],
199
220
  stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
200
221
  stderr: '',
201
- };
202
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
222
+ });
223
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
203
224
  const options = {
204
225
  repoOwner: 'elastic',
205
226
  repoName: 'kibana',
@@ -212,7 +233,7 @@ describe('getConflictingFiles', () => {
212
233
  ]);
213
234
  });
214
235
  });
215
- describe('createFeatureBranch', () => {
236
+ describe('createBackportBranch', () => {
216
237
  const options = {
217
238
  repoOwner: 'elastic',
218
239
  repoName: 'kibana',
@@ -221,34 +242,30 @@ describe('createFeatureBranch', () => {
221
242
  const backportBranch = 'backport/4.x/commit-72f94e76';
222
243
  it(`should handle "couldn't find remote ref" error`, async () => {
223
244
  expect.assertions(1);
224
- const err = {
225
- killed: false,
245
+ const err = new childProcess.SpawnError({
226
246
  code: 128,
227
- signal: null,
228
- cmd: '',
247
+ cmdArgs: [],
229
248
  stdout: 'HEAD is now at 72f94e7 Create "conflicting-file.txt" in master\n',
230
249
  stderr: "fatal: couldn't find remote ref 4.x\n",
231
- };
232
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
250
+ });
251
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
233
252
  await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
234
253
  });
235
254
  it('should throw "Invalid refspec" error', async () => {
236
255
  expect.assertions(1);
237
- const err = {
238
- killed: false,
256
+ const err = new childProcess.SpawnError({
239
257
  code: 128,
240
- signal: null,
241
- cmd: '',
258
+ cmdArgs: [],
242
259
  stdout: '',
243
260
  stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
244
- };
245
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
261
+ });
262
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
246
263
  await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
247
264
  });
248
265
  it('should rethrow normal error', async () => {
249
266
  expect.assertions(1);
250
267
  const err = new Error('just a normal error');
251
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
268
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
252
269
  expect.assertions(1);
253
270
  await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
254
271
  });
@@ -259,21 +276,19 @@ describe('deleteRemote', () => {
259
276
  repoOwner: 'elastic',
260
277
  repoName: 'kibana',
261
278
  };
262
- it('should swallow exec error', async () => {
263
- const err = {
264
- killed: false,
279
+ it('should swallow SpawnError error', async () => {
280
+ const err = new childProcess.SpawnError({
265
281
  code: 128,
266
- signal: null,
267
- cmd: 'git remote rm origin',
282
+ cmdArgs: [],
268
283
  stdout: '',
269
284
  stderr: "fatal: No such remote: 'origin'\n",
270
- };
271
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
285
+ });
286
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
272
287
  await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
273
288
  });
274
289
  it('should rethrow normal error', async () => {
275
290
  const err = new Error('just a normal error');
276
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
291
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
277
292
  expect.assertions(1);
278
293
  await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
279
294
  });
@@ -285,11 +300,9 @@ describe('cherrypick', () => {
285
300
  };
286
301
  it('should return `needsResolving: false` when no errors are encountered', async () => {
287
302
  jest
288
- .spyOn(childProcess, 'exec')
289
- // mock getIsMergeCommit(...)
290
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
291
- // mock cherrypick(...)
292
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
303
+ .spyOn(childProcess, 'spawnPromise')
304
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
305
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
293
306
  expect(await (0, git_1.cherrypick)({
294
307
  options,
295
308
  sha: 'abcd',
@@ -301,41 +314,52 @@ describe('cherrypick', () => {
301
314
  });
302
315
  });
303
316
  it('should use mainline option when specified', async () => {
304
- const execSpy = jest
305
- .spyOn(childProcess, 'exec')
306
- // mock getIsMergeCommit(...)
307
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
308
- // mock cherry pick command
309
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
317
+ const spawnSpy = jest
318
+ .spyOn(childProcess, 'spawnPromise')
319
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
320
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
310
321
  await (0, git_1.cherrypick)({
311
322
  options: { ...options, mainline: 1 },
312
323
  sha: 'abcd',
313
324
  commitAuthor,
314
325
  });
315
- expect(execSpy.mock.calls[0][0]).toBe('git -c user.name="Soren L" -c user.email="soren@mail.dk" cherry-pick -x --mainline 1 abcd');
326
+ const args = spawnSpy.mock.calls[0];
327
+ expect(args).toEqual([
328
+ 'git',
329
+ [
330
+ '-c',
331
+ 'user.name="Soren L"',
332
+ '-c',
333
+ 'user.email="soren@mail.dk"',
334
+ 'cherry-pick',
335
+ '--mainline',
336
+ '1',
337
+ '-x',
338
+ 'abcd',
339
+ ],
340
+ '/myHomeDir/.backport/repositories/elastic/kibana',
341
+ ]);
316
342
  });
317
343
  it('should return `needsResolving: true` upon cherrypick error', async () => {
318
344
  jest
319
- .spyOn(childProcess, 'exec')
320
- // mock getIsMergeCommit(...)
321
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
345
+ .spyOn(childProcess, 'spawnPromise')
346
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
322
347
  // mock `git cherrypick`
323
- .mockRejectedValueOnce(new ExecError_1.ExecError({
324
- killed: false,
348
+ .mockRejectedValueOnce(new childProcess.SpawnError({
325
349
  code: 128,
326
- cmd: 'git cherry-pick -x abcd',
350
+ cmdArgs: ['cherry-pick', '-x', 'abcd'],
327
351
  stdout: '',
328
352
  stderr: '',
329
353
  }))
330
354
  // mock getConflictingFiles
331
- .mockRejectedValueOnce(new ExecError_1.ExecError({
355
+ .mockRejectedValueOnce(new childProcess.SpawnError({
332
356
  code: 2,
333
- cmd: 'git --no-pager diff --check',
357
+ cmdArgs: ['--no-pager', 'diff', '--check'],
334
358
  stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
335
359
  stderr: '',
336
360
  }))
337
361
  // mock getUnstagedFiles
338
- .mockResolvedValueOnce({ stdout: '', stderr: '' });
362
+ .mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
339
363
  expect(await (0, git_1.cherrypick)({
340
364
  options,
341
365
  sha: 'abcd',
@@ -353,15 +377,13 @@ describe('cherrypick', () => {
353
377
  });
354
378
  it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
355
379
  jest
356
- .spyOn(childProcess, 'exec')
380
+ .spyOn(childProcess, 'spawnPromise')
357
381
  // mock getIsMergeCommit(...)
358
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
382
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
359
383
  // mock cherry pick command
360
- .mockRejectedValueOnce(new ExecError_1.ExecError({
361
- killed: false,
384
+ .mockRejectedValueOnce(new childProcess.SpawnError({
362
385
  code: 128,
363
- signal: null,
364
- cmd: 'git cherry-pick 381c7b604110257437a289b1f1742685eb8d79c5',
386
+ cmdArgs: ['cherry-pick', '381c7b604110257437a289b1f1742685eb8d79c5'],
365
387
  stdout: '',
366
388
  stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
367
389
  }));
@@ -382,15 +404,13 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
382
404
  });
383
405
  it('should gracefully handle empty commits', async () => {
384
406
  jest
385
- .spyOn(childProcess, 'exec')
407
+ .spyOn(childProcess, 'spawnPromise')
386
408
  // mock getIsMergeCommit(...)
387
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
409
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
388
410
  // mock cherry pick command
389
- .mockRejectedValueOnce(new ExecError_1.ExecError({
390
- killed: false,
411
+ .mockRejectedValueOnce(new childProcess.SpawnError({
391
412
  code: 1,
392
- signal: null,
393
- cmd: 'git cherry-pick fe6b13b83cc010f722548cd5a0a8c2d5341a20dd',
413
+ cmdArgs: ['cherry-pick', 'fe6b13b83cc010f722548cd5a0a8c2d5341a20dd'],
394
414
  stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
395
415
  stderr: "The previous cherry-pick is now empty, possibly due to conflict resolution.\nIf you wish to commit it anyway, use:\n\n git commit --allow-empty\n\nOtherwise, please use 'git cherry-pick --skip'\n",
396
416
  }));
@@ -402,15 +422,15 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
402
422
  });
403
423
  it('should re-throw non-cherrypick errors', async () => {
404
424
  jest
405
- .spyOn(childProcess, 'exec')
425
+ .spyOn(childProcess, 'spawnPromise')
406
426
  // mock getIsMergeCommit(...)
407
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
427
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
408
428
  // mock cherry pick command
409
429
  .mockRejectedValueOnce(new Error('non-cherrypick error'))
410
430
  // getConflictingFiles
411
- .mockResolvedValueOnce({ stdout: '', stderr: '' })
431
+ .mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] })
412
432
  // getUnstagedFiles
413
- .mockResolvedValueOnce({ stdout: '', stderr: '' });
433
+ .mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
414
434
  await expect((0, git_1.cherrypick)({
415
435
  options,
416
436
  sha: 'abcd',
@@ -435,44 +455,45 @@ describe('commitChanges', () => {
435
455
  };
436
456
  it('should return when changes committed successfully', async () => {
437
457
  jest
438
- .spyOn(childProcess, 'exec')
439
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
458
+ .spyOn(childProcess, 'spawnPromise')
459
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
440
460
  await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
441
461
  });
442
462
  it('should swallow error if changes have already been committed manaully', async () => {
443
- const err = {
444
- killed: false,
463
+ const err = new childProcess.SpawnError({
445
464
  code: 1,
446
- signal: null,
447
- cmd: 'git commit --no-edit',
465
+ cmdArgs: ['commit', '--no-edit'],
448
466
  stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
449
467
  stderr: '',
450
- };
451
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
468
+ });
469
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
452
470
  await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
453
471
  });
454
472
  describe('when commit fails due to empty message', () => {
455
473
  let spy;
456
474
  let res;
457
475
  beforeEach(async () => {
458
- const err = {
459
- killed: false,
476
+ const err = new childProcess.SpawnError({
460
477
  code: 1,
461
- signal: null,
462
- cmd: 'git commit --no-edit --no-verify',
478
+ cmdArgs: ['commit', '--no-edit', '--no-verify'],
463
479
  stdout: '',
464
480
  stderr: 'Aborting commit due to empty commit message.\n',
465
- };
481
+ });
466
482
  spy = jest
467
- .spyOn(childProcess, 'exec')
483
+ .spyOn(childProcess, 'spawnPromise')
468
484
  .mockRejectedValueOnce(err)
469
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
485
+ .mockResolvedValueOnce({
486
+ stderr: '',
487
+ stdout: '',
488
+ code: 0,
489
+ cmdArgs: [],
490
+ });
470
491
  res = await (0, git_1.commitChanges)(commit, options);
471
492
  });
472
493
  it('should manually set the commit message', () => {
473
494
  expect(spy).toHaveBeenCalledTimes(2);
474
- expect(spy).toHaveBeenCalledWith('git commit --no-edit', expect.any(Object));
475
- expect(spy).toHaveBeenCalledWith('git commit -m "The original commit message" ', expect.any(Object));
495
+ expect(spy).toHaveBeenCalledWith('git', ['commit', '--no-edit'], expect.any(String));
496
+ expect(spy).toHaveBeenCalledWith('git', ['commit', '--message=The original commit message'], expect.any(String));
476
497
  });
477
498
  it('should handle the error and resolve successfully', async () => {
478
499
  await expect(res).toBe(undefined);
@@ -480,7 +501,7 @@ describe('commitChanges', () => {
480
501
  });
481
502
  it('should re-throw other errors', async () => {
482
503
  const err = new Error('another error');
483
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
504
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
484
505
  expect.assertions(1);
485
506
  await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
486
507
  });
@@ -494,24 +515,39 @@ describe('addRemote', () => {
494
515
  };
495
516
  it('add correct origin remote', async () => {
496
517
  const spy = jest
497
- .spyOn(childProcess, 'exec')
498
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
518
+ .spyOn(childProcess, 'spawnPromise')
519
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
499
520
  await (0, git_1.addRemote)(options, 'elastic');
500
- return expect(spy).toHaveBeenCalledWith('git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
521
+ return expect(spy).toHaveBeenCalledWith('git', [
522
+ 'remote',
523
+ 'add',
524
+ 'elastic',
525
+ 'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
526
+ ], '/myHomeDir/.backport/repositories/elastic/kibana');
501
527
  });
502
528
  it('add correct user remote', async () => {
503
529
  const spy = jest
504
- .spyOn(childProcess, 'exec')
505
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
530
+ .spyOn(childProcess, 'spawnPromise')
531
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
506
532
  await (0, git_1.addRemote)(options, 'sqren');
507
- return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
533
+ return expect(spy).toHaveBeenCalledWith('git', [
534
+ 'remote',
535
+ 'add',
536
+ 'sqren',
537
+ 'https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
538
+ ], '/myHomeDir/.backport/repositories/elastic/kibana');
508
539
  });
509
540
  it('allows custom github url', async () => {
510
541
  const spy = jest
511
- .spyOn(childProcess, 'exec')
512
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
542
+ .spyOn(childProcess, 'spawnPromise')
543
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
513
544
  await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
514
- return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
545
+ return expect(spy).toHaveBeenCalledWith('git', [
546
+ 'remote',
547
+ 'add',
548
+ 'sqren',
549
+ 'https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git',
550
+ ], '/myHomeDir/.backport/repositories/elastic/kibana');
515
551
  });
516
552
  });
517
553
  describe('pushBackportBranch', () => {
@@ -524,14 +560,21 @@ describe('pushBackportBranch', () => {
524
560
  };
525
561
  const backportBranch = 'backport/7.x/pr-2';
526
562
  it('should handle missing fork error', async () => {
527
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce({
528
- killed: false,
563
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(new childProcess.SpawnError({
529
564
  code: 128,
530
- signal: null,
531
- cmd: 'git push sqren backport/7.x/pr-2:backport/7.x/pr-2 --force',
565
+ cmdArgs: [
566
+ 'push',
567
+ 'sqren',
568
+ 'backport/7.x/pr-2:backport/7.x/pr-2',
569
+ '--force',
570
+ ],
532
571
  stdout: '',
533
572
  stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
534
- });
535
- await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
573
+ }));
574
+ await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects
575
+ .toThrowErrorMatchingInlineSnapshot(`
576
+ "Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the repository (https://github.com/elastic/kibana) or disable fork mode via \\"--no-fork\\".
577
+ Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/configuration.md#fork"
578
+ `);
536
579
  });
537
580
  });
@@ -26,7 +26,7 @@ async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwn
26
26
  }
27
27
  catch (e) {
28
28
  spinner.fail();
29
- logger_1.logger.info(`Could not add assignees to PR ${pullNumber}`, e.stack);
29
+ logger_1.logger.info(`Could not add assignees to PR ${pullNumber}`, e);
30
30
  }
31
31
  }
32
32
  exports.addAssigneesToPullRequest = addAssigneesToPullRequest;
@@ -24,7 +24,7 @@ async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner,
24
24
  }
25
25
  catch (e) {
26
26
  spinner.fail();
27
- logger_1.logger.info(`Could not add labels to PR ${pullNumber}`, e.stack);
27
+ logger_1.logger.info(`Could not add labels to PR ${pullNumber}`, e);
28
28
  }
29
29
  }
30
30
  exports.addLabelsToPullRequest = addLabelsToPullRequest;
@@ -23,9 +23,10 @@ async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwn
23
23
  spinner.succeed();
24
24
  }
25
25
  catch (e) {
26
+ //@ts-expect-error
26
27
  const message = e.response?.data?.message;
27
28
  spinner.fail(`Adding reviewers. ${message ? message : ''}`);
28
- logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e.stack);
29
+ logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e);
29
30
  }
30
31
  }
31
32
  exports.addReviewersToPullRequest = addReviewersToPullRequest;
@@ -4,7 +4,7 @@ exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void
4
4
  const rest_1 = require("@octokit/rest");
5
5
  const ora_1 = require("../../../ui/ora");
6
6
  const packageVersion_1 = require("../../../utils/packageVersion");
7
- const HandledError_1 = require("../../HandledError");
7
+ const BackportError_1 = require("../../BackportError");
8
8
  const logger_1 = require("../../logger");
9
9
  const commitFormatters_1 = require("../commitFormatters");
10
10
  const fetchExistingPullRequest_1 = require("../v4/fetchExistingPullRequest");
@@ -48,7 +48,9 @@ async function createPullRequest({ options, prPayload, }) {
48
48
  // swallow error
49
49
  }
50
50
  spinner.fail();
51
- throw new HandledError_1.HandledError(`Could not create pull request: ${(0, getGithubV3ErrorMessage_1.getGithubV3ErrorMessage)(e)}`);
51
+ throw new BackportError_1.BackportError(
52
+ //@ts-expect-error
53
+ `Could not create pull request: ${(0, getGithubV3ErrorMessage_1.getGithubV3ErrorMessage)(e)}`);
52
54
  }
53
55
  }
54
56
  exports.createPullRequest = createPullRequest;