backport 7.3.6 → 8.1.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 (245) hide show
  1. package/README.md +16 -21
  2. package/dist/backportRun.d.ts +18 -6
  3. package/dist/backportRun.js +70 -50
  4. package/dist/entrypoint.cli.js +4 -8
  5. package/dist/entrypoint.module.d.ts +13 -6
  6. package/dist/entrypoint.module.js +17 -19
  7. package/dist/entrypoint.module.private.test.js +129 -330
  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 +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -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 +58 -0
  18. package/dist/lib/env.d.ts +7 -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 +206 -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 +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -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/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +6 -4
  151. package/dist/options/cliArgs.d.ts +16 -9
  152. package/dist/options/cliArgs.js +54 -28
  153. package/dist/options/cliArgs.test.js +128 -4
  154. package/dist/options/config/config.d.ts +7 -6
  155. package/dist/options/config/config.js +5 -7
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +5 -3
  158. package/dist/options/config/globalConfig.js +17 -14
  159. package/dist/options/config/projectConfig.d.ts +2 -2
  160. package/dist/options/config/projectConfig.js +3 -3
  161. package/dist/options/config/projectConfig.test.js +19 -7
  162. package/dist/options/config/readConfigFile.d.ts +9 -7
  163. package/dist/options/config/readConfigFile.js +2 -2
  164. package/dist/options/options.d.ts +44 -9
  165. package/dist/options/options.js +22 -27
  166. package/dist/options/options.test.js +119 -58
  167. package/dist/runSequentially.d.ts +14 -7
  168. package/dist/runSequentially.js +26 -11
  169. package/dist/scripts/postinstall.js +4 -3
  170. package/dist/scripts/postinstall.test.js +6 -2
  171. package/dist/services/BackportError.d.ts +19 -0
  172. package/dist/services/BackportError.js +29 -0
  173. package/dist/services/HandledBackportError.d.ts +19 -0
  174. package/dist/services/HandledBackportError.js +29 -0
  175. package/dist/services/HandledError.d.ts +7 -3
  176. package/dist/services/HandledError.js +13 -13
  177. package/dist/services/child-process-promisified.d.ts +19 -3
  178. package/dist/services/child-process-promisified.js +46 -17
  179. package/dist/services/git.d.ts +6 -7
  180. package/dist/services/git.integration.test.js +381 -65
  181. package/dist/services/git.js +189 -127
  182. package/dist/services/git.private.test.d.ts +1 -0
  183. package/dist/services/git.private.test.js +618 -0
  184. package/dist/services/git.test.js +167 -158
  185. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  186. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  187. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  188. package/dist/services/github/v3/createPullRequest.js +4 -2
  189. package/dist/services/github/v3/createStatusComment.js +17 -17
  190. package/dist/services/github/v3/createStatusComment.test.js +22 -9
  191. package/dist/services/github/v4/apiRequestV4.js +8 -11
  192. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  193. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  194. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  195. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  196. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
  197. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  198. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
  199. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  200. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
  201. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  202. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  203. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
  204. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  205. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  206. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  207. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  208. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  209. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  210. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  211. package/dist/services/logger.d.ts +1 -4
  212. package/dist/services/logger.js +14 -19
  213. package/dist/services/test.d.ts +1 -0
  214. package/dist/services/test.js +23 -0
  215. package/dist/state.d.ts +0 -0
  216. package/dist/state.js +1 -0
  217. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  218. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  219. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  220. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +450 -0
  221. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +27 -28
  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.d.ts +1 -0
  226. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  227. package/dist/test/handleUnbackportedPullRequests.private.test.js +12 -10
  228. package/dist/test/sandbox.js +5 -1
  229. package/dist/test/setupFiles/automatic-mocks.js +17 -13
  230. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -7
  231. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  232. package/dist/ui/getCommits.js +2 -2
  233. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  234. package/dist/ui/getGitConfigAuthor.js +1 -1
  235. package/dist/ui/getTargetBranches.js +3 -3
  236. package/dist/ui/getTargetBranches.test.js +5 -1
  237. package/dist/ui/ora.d.ts +1 -8
  238. package/dist/ui/setupRepo.js +3 -3
  239. package/dist/ui/setupRepo.test.js +98 -61
  240. package/dist/utils/isErrnoError.d.ts +2 -0
  241. package/dist/utils/isErrnoError.js +7 -0
  242. package/dist/utils/packageVersion.d.ts +1 -1
  243. package/dist/utils/packageVersion.js +1 -1
  244. package/package.json +17 -17
  245. package/yarn.lock +461 -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];
@@ -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
  }));
@@ -400,51 +420,17 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
400
420
  commitAuthor,
401
421
  })).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
402
422
  });
403
- it('gracefully handles missing git info', async () => {
404
- jest
405
- .spyOn(childProcess, 'exec')
406
- // mock getIsMergeCommit(...)
407
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
408
- // mock cherry pick command
409
- .mockRejectedValueOnce(new ExecError_1.ExecError({
410
- killed: false,
411
- code: 128,
412
- signal: null,
413
- cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
414
- stdout: '',
415
- stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <foo@bar.net>) not allowed\n',
416
- }));
417
- await expect((0, git_1.cherrypick)({
418
- options,
419
- sha: 'abcd',
420
- commitAuthor,
421
- })).rejects.toThrowErrorMatchingInlineSnapshot(`
422
- "
423
- *** Please tell me who you are.
424
-
425
- Run
426
-
427
- git config --global user.email \\"you@example.com\\"
428
- git config --global user.name \\"Your Name\\"
429
-
430
- to set your account's default identity.
431
- Omit --global to set the identity only in this repository.
432
-
433
- fatal: empty ident name (for <foo@bar.net>) not allowed
434
- "
435
- `);
436
- });
437
423
  it('should re-throw non-cherrypick errors', async () => {
438
424
  jest
439
- .spyOn(childProcess, 'exec')
425
+ .spyOn(childProcess, 'spawnPromise')
440
426
  // mock getIsMergeCommit(...)
441
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
427
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
442
428
  // mock cherry pick command
443
429
  .mockRejectedValueOnce(new Error('non-cherrypick error'))
444
430
  // getConflictingFiles
445
- .mockResolvedValueOnce({ stdout: '', stderr: '' })
431
+ .mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] })
446
432
  // getUnstagedFiles
447
- .mockResolvedValueOnce({ stdout: '', stderr: '' });
433
+ .mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
448
434
  await expect((0, git_1.cherrypick)({
449
435
  options,
450
436
  sha: 'abcd',
@@ -469,44 +455,45 @@ describe('commitChanges', () => {
469
455
  };
470
456
  it('should return when changes committed successfully', async () => {
471
457
  jest
472
- .spyOn(childProcess, 'exec')
473
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
458
+ .spyOn(childProcess, 'spawnPromise')
459
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
474
460
  await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
475
461
  });
476
462
  it('should swallow error if changes have already been committed manaully', async () => {
477
- const err = {
478
- killed: false,
463
+ const err = new childProcess.SpawnError({
479
464
  code: 1,
480
- signal: null,
481
- cmd: 'git commit --no-edit',
465
+ cmdArgs: ['commit', '--no-edit'],
482
466
  stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
483
467
  stderr: '',
484
- };
485
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
468
+ });
469
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
486
470
  await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
487
471
  });
488
472
  describe('when commit fails due to empty message', () => {
489
473
  let spy;
490
474
  let res;
491
475
  beforeEach(async () => {
492
- const err = {
493
- killed: false,
476
+ const err = new childProcess.SpawnError({
494
477
  code: 1,
495
- signal: null,
496
- cmd: 'git commit --no-edit --no-verify',
478
+ cmdArgs: ['commit', '--no-edit', '--no-verify'],
497
479
  stdout: '',
498
480
  stderr: 'Aborting commit due to empty commit message.\n',
499
- };
481
+ });
500
482
  spy = jest
501
- .spyOn(childProcess, 'exec')
483
+ .spyOn(childProcess, 'spawnPromise')
502
484
  .mockRejectedValueOnce(err)
503
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
485
+ .mockResolvedValueOnce({
486
+ stderr: '',
487
+ stdout: '',
488
+ code: 0,
489
+ cmdArgs: [],
490
+ });
504
491
  res = await (0, git_1.commitChanges)(commit, options);
505
492
  });
506
493
  it('should manually set the commit message', () => {
507
494
  expect(spy).toHaveBeenCalledTimes(2);
508
- expect(spy).toHaveBeenCalledWith('git commit --no-edit', expect.any(Object));
509
- 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));
510
497
  });
511
498
  it('should handle the error and resolve successfully', async () => {
512
499
  await expect(res).toBe(undefined);
@@ -514,7 +501,7 @@ describe('commitChanges', () => {
514
501
  });
515
502
  it('should re-throw other errors', async () => {
516
503
  const err = new Error('another error');
517
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
504
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
518
505
  expect.assertions(1);
519
506
  await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
520
507
  });
@@ -528,24 +515,39 @@ describe('addRemote', () => {
528
515
  };
529
516
  it('add correct origin remote', async () => {
530
517
  const spy = jest
531
- .spyOn(childProcess, 'exec')
532
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
518
+ .spyOn(childProcess, 'spawnPromise')
519
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
533
520
  await (0, git_1.addRemote)(options, 'elastic');
534
- 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');
535
527
  });
536
528
  it('add correct user remote', async () => {
537
529
  const spy = jest
538
- .spyOn(childProcess, 'exec')
539
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
530
+ .spyOn(childProcess, 'spawnPromise')
531
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
540
532
  await (0, git_1.addRemote)(options, 'sqren');
541
- 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');
542
539
  });
543
540
  it('allows custom github url', async () => {
544
541
  const spy = jest
545
- .spyOn(childProcess, 'exec')
546
- .mockResolvedValueOnce({ stderr: '', stdout: '' });
542
+ .spyOn(childProcess, 'spawnPromise')
543
+ .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
547
544
  await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
548
- 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');
549
551
  });
550
552
  });
551
553
  describe('pushBackportBranch', () => {
@@ -558,14 +560,21 @@ describe('pushBackportBranch', () => {
558
560
  };
559
561
  const backportBranch = 'backport/7.x/pr-2';
560
562
  it('should handle missing fork error', async () => {
561
- jest.spyOn(childProcess, 'exec').mockRejectedValueOnce({
562
- killed: false,
563
+ jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(new childProcess.SpawnError({
563
564
  code: 128,
564
- signal: null,
565
- 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
+ ],
566
571
  stdout: '',
567
572
  stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
568
- });
569
- 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
+ `);
570
579
  });
571
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;