backport 5.6.6 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +13 -8
  10. package/dist/options/cliArgs.d.ts +11 -9
  11. package/dist/options/cliArgs.js +74 -36
  12. package/dist/options/cliArgs.test.js +33 -37
  13. package/dist/options/config/config.d.ts +17 -15
  14. package/dist/options/config/config.js +8 -8
  15. package/dist/options/config/config.test.js +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -1
  17. package/dist/options/config/globalConfig.d.ts +2 -51
  18. package/dist/options/config/globalConfig.js +8 -8
  19. package/dist/options/config/globalConfig.test.js +7 -3
  20. package/dist/options/config/projectConfig.d.ts +2 -51
  21. package/dist/options/config/projectConfig.js +2 -2
  22. package/dist/options/config/projectConfig.test.js +3 -3
  23. package/dist/options/config/readConfigFile.d.ts +2 -51
  24. package/dist/options/config/readConfigFile.js +2 -2
  25. package/dist/options/options.d.ts +19 -14
  26. package/dist/options/options.js +5 -6
  27. package/dist/options/options.test.js +48 -11
  28. package/dist/options/parseRequiredOptions.d.ts +18 -13
  29. package/dist/options/parseRequiredOptions.js +8 -12
  30. package/dist/options/parseRequiredOptions.test.js +25 -16
  31. package/dist/runSequentially.d.ts +20 -0
  32. package/dist/runSequentially.js +41 -0
  33. package/dist/runSequentially.test.d.ts +1 -0
  34. package/dist/runSequentially.test.js +235 -0
  35. package/dist/runWithOptions.js +7 -14
  36. package/dist/runWithOptions.test.js +138 -17
  37. package/dist/scripts/generate-gql.d.ts +1 -0
  38. package/dist/scripts/generate-gql.js +15 -0
  39. package/dist/scripts/postinstall.js +4 -4
  40. package/dist/scripts/postinstall.test.js +9 -2
  41. package/dist/scripts/runPostinstall.js +1 -1
  42. package/dist/services/HandledError.d.ts +11 -1
  43. package/dist/services/HandledError.js +2 -1
  44. package/dist/services/child-process-promisified.d.ts +1 -1
  45. package/dist/services/child-process-promisified.js +1 -1
  46. package/dist/services/env.js +5 -5
  47. package/dist/services/env.test.js +11 -4
  48. package/dist/services/fs-promisified.js +4 -4
  49. package/dist/services/getExpectedTarget.d.ts +9 -0
  50. package/dist/services/getExpectedTarget.js +77 -0
  51. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  52. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  53. package/dist/services/git.d.ts +15 -4
  54. package/dist/services/git.integration.test.d.ts +1 -0
  55. package/dist/services/git.integration.test.js +168 -0
  56. package/dist/services/git.js +86 -61
  57. package/dist/services/git.test.js +61 -64
  58. package/dist/services/github/commitFormatters.d.ts +3 -7
  59. package/dist/services/github/commitFormatters.js +10 -19
  60. package/dist/services/github/commitFormatters.test.js +2 -24
  61. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  62. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  63. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  64. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  66. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  67. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  68. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  69. package/dist/services/github/v3/createPullRequest.js +32 -23
  70. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  71. package/dist/services/github/v3/createStatusComment.js +97 -0
  72. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  73. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  74. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  75. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  76. package/dist/services/github/v4/apiRequestV4.js +5 -7
  77. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  78. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  79. package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
  80. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
  81. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  83. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  84. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  85. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  86. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  89. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  93. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  105. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  107. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  109. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  110. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  111. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  112. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  113. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  114. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  115. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  116. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  117. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  118. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  119. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  120. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  121. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  122. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  123. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  124. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  125. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
  126. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  127. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
  128. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
  129. package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
  130. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  131. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  132. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  134. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  135. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  136. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  137. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  138. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  139. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  140. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  141. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  142. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  143. package/dist/services/logger.d.ts +3 -3
  144. package/dist/services/logger.js +16 -15
  145. package/dist/services/prompt.test.d.ts +1 -0
  146. package/dist/services/prompt.test.js +87 -0
  147. package/dist/services/prompts.d.ts +10 -4
  148. package/dist/services/prompts.js +85 -22
  149. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  150. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  151. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  152. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  153. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  154. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  155. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  156. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  157. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  158. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  159. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  160. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  161. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  162. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  163. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  164. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  165. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  166. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  167. package/dist/services/sourceCommit.d.ts +78 -0
  168. package/dist/services/sourceCommit.js +86 -0
  169. package/dist/services/sourceCommit.test.d.ts +1 -0
  170. package/dist/services/sourceCommit.test.js +280 -0
  171. package/dist/test/inquirer.private.test.js +22 -15
  172. package/dist/test/integration/createSpies.js +6 -6
  173. package/dist/test/integration/envConstants.js +5 -6
  174. package/dist/test/integration/helpers.js +1 -1
  175. package/dist/test/integration/integration.private.test.d.ts +1 -0
  176. package/dist/test/integration/integration.private.test.js +308 -0
  177. package/dist/test/integration/integration.test.js +28 -29
  178. package/dist/test/nockHelpers.js +3 -7
  179. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  180. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  181. package/dist/types/Commit.d.ts +85 -0
  182. package/dist/types/Commit.js +139 -0
  183. package/dist/types/commitNode.d.ts +89 -0
  184. package/dist/types/commitNode.js +139 -0
  185. package/dist/types/commitNode.test.d.ts +1 -0
  186. package/dist/types/commitNode.test.js +255 -0
  187. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  188. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  189. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  190. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  191. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
  192. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  193. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  194. package/dist/ui/getCommits.d.ts +1 -1
  195. package/dist/ui/getCommits.js +55 -25
  196. package/dist/ui/getTargetBranches.d.ts +2 -2
  197. package/dist/ui/getTargetBranches.js +16 -17
  198. package/dist/ui/getTargetBranches.test.js +75 -99
  199. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  200. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  201. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  202. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  203. package/dist/ui/maybeSetupRepo.js +9 -9
  204. package/dist/ui/maybeSetupRepo.test.js +5 -1
  205. package/package.json +36 -51
  206. package/yarn.lock +2387 -2987
@@ -3,11 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.addRemote = exports.deleteRemote = exports.getUpstreamFromGitRemote = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
6
+ exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getUpstreamFromGitRemote = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
7
7
  const path_1 = require("path");
8
8
  const del_1 = __importDefault(require("del"));
9
- const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
10
- const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
9
+ const lodash_1 = require("lodash");
11
10
  const ora_1 = __importDefault(require("ora"));
12
11
  const HandledError_1 = require("./HandledError");
13
12
  const child_process_promisified_1 = require("./child-process-promisified");
@@ -17,7 +16,7 @@ const commitFormatters_1 = require("./github/commitFormatters");
17
16
  const logger_1 = require("./logger");
18
17
  async function folderExists(path) {
19
18
  try {
20
- const stats = await fs_promisified_1.stat(path);
19
+ const stats = await (0, fs_promisified_1.stat)(path);
21
20
  return stats.isDirectory();
22
21
  }
23
22
  catch (e) {
@@ -28,12 +27,12 @@ async function folderExists(path) {
28
27
  }
29
28
  }
30
29
  function repoExists(options) {
31
- return folderExists(env_1.getRepoPath(options));
30
+ return folderExists((0, env_1.getRepoPath)(options));
32
31
  }
33
32
  exports.repoExists = repoExists;
34
33
  function deleteRepo(options) {
35
- const repoPath = env_1.getRepoPath(options);
36
- return del_1.default(repoPath);
34
+ const repoPath = (0, env_1.getRepoPath)(options);
35
+ return (0, del_1.default)(repoPath);
37
36
  }
38
37
  exports.deleteRepo = deleteRepo;
39
38
  function getRemoteUrl({ repoName, accessToken, gitHostname }, repoOwner) {
@@ -50,7 +49,7 @@ function cloneRepo(options, callback) {
50
49
  resolve();
51
50
  }
52
51
  };
53
- const execProcess = child_process_promisified_1.execAsCallback(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: env_1.getRepoOwnerPath(options), maxBuffer: 100 * 1024 * 1024 }, cb);
52
+ const execProcess = (0, child_process_promisified_1.execAsCallback)(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: (0, env_1.getRepoOwnerPath)(options), maxBuffer: 100 * 1024 * 1024 }, cb);
54
53
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55
54
  if (execProcess.stderr) {
56
55
  execProcess.stderr.on('data', (data) => {
@@ -66,7 +65,7 @@ function cloneRepo(options, callback) {
66
65
  exports.cloneRepo = cloneRepo;
67
66
  async function getLocalConfigFileCommitDate() {
68
67
  try {
69
- const { stdout } = await child_process_promisified_1.exec('git --no-pager log -1 --format=%cd .backportrc.js*', {});
68
+ const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=%cd .backportrc.js*', {});
70
69
  const timestamp = Date.parse(stdout);
71
70
  if (timestamp > 0) {
72
71
  return timestamp;
@@ -80,7 +79,7 @@ exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
80
79
  async function isLocalConfigFileUntracked() {
81
80
  try {
82
81
  // list untracked files
83
- const { stdout } = await child_process_promisified_1.exec('git ls-files .backportrc.js* --exclude-standard --others', {});
82
+ const { stdout } = await (0, child_process_promisified_1.exec)('git ls-files .backportrc.js* --exclude-standard --others', {});
84
83
  return !!stdout;
85
84
  }
86
85
  catch (e) {
@@ -90,7 +89,7 @@ async function isLocalConfigFileUntracked() {
90
89
  exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
91
90
  async function isLocalConfigFileModified() {
92
91
  try {
93
- const { stdout } = await child_process_promisified_1.exec('git --no-pager diff HEAD --name-only .backportrc.js*', {});
92
+ const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager diff HEAD --name-only .backportrc.js*', {});
94
93
  return !!stdout;
95
94
  }
96
95
  catch (e) {
@@ -100,7 +99,7 @@ async function isLocalConfigFileModified() {
100
99
  exports.isLocalConfigFileModified = isLocalConfigFileModified;
101
100
  async function getUpstreamFromGitRemote() {
102
101
  try {
103
- const { stdout } = await child_process_promisified_1.exec('git remote --verbose', {});
102
+ const { stdout } = await (0, child_process_promisified_1.exec)('git remote --verbose', {});
104
103
  const matches = stdout.match(/github.com[:/]{1}(.*).git/);
105
104
  if (matches !== null) {
106
105
  return matches[1];
@@ -111,9 +110,27 @@ async function getUpstreamFromGitRemote() {
111
110
  }
112
111
  }
113
112
  exports.getUpstreamFromGitRemote = getUpstreamFromGitRemote;
113
+ async function getIsCommitInBranch(options, commitSha) {
114
+ try {
115
+ const cwd = (0, env_1.getRepoPath)(options);
116
+ await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
117
+ cwd,
118
+ });
119
+ return true;
120
+ }
121
+ catch (e) {
122
+ const isExecError = e.cmd && e.code > 0;
123
+ // re-throw if error is not an exec related error
124
+ if (!isExecError) {
125
+ throw e;
126
+ }
127
+ return false;
128
+ }
129
+ }
130
+ exports.getIsCommitInBranch = getIsCommitInBranch;
114
131
  async function deleteRemote(options, remoteName) {
115
132
  try {
116
- await child_process_promisified_1.exec(`git remote rm ${remoteName}`, { cwd: env_1.getRepoPath(options) });
133
+ await (0, child_process_promisified_1.exec)(`git remote rm ${remoteName}`, { cwd: (0, env_1.getRepoPath)(options) });
117
134
  }
118
135
  catch (e) {
119
136
  const isExecError = e.cmd && e.code > 0;
@@ -126,7 +143,7 @@ async function deleteRemote(options, remoteName) {
126
143
  exports.deleteRemote = deleteRemote;
127
144
  async function addRemote(options, remoteName) {
128
145
  try {
129
- await child_process_promisified_1.exec(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: env_1.getRepoPath(options) });
146
+ await (0, child_process_promisified_1.exec)(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: (0, env_1.getRepoPath)(options) });
130
147
  }
131
148
  catch (e) {
132
149
  // note: swallowing error
@@ -134,13 +151,19 @@ async function addRemote(options, remoteName) {
134
151
  }
135
152
  }
136
153
  exports.addRemote = addRemote;
137
- async function cherrypick(options, commit) {
138
- await child_process_promisified_1.exec(`git fetch ${options.repoOwner} ${commit.sourceBranch}:${commit.sourceBranch} --force`, { cwd: env_1.getRepoPath(options) });
139
- const mainline = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
140
- const cmd = `git cherry-pick${mainline} ${commit.sha}`;
154
+ async function fetchBranch(options, branch) {
155
+ await (0, child_process_promisified_1.exec)(`git fetch ${options.repoOwner} ${branch}:${branch} --force`, {
156
+ cwd: (0, env_1.getRepoPath)(options),
157
+ });
158
+ }
159
+ exports.fetchBranch = fetchBranch;
160
+ async function cherrypick(options, sha) {
161
+ const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
162
+ const cherrypickRefArg = options.cherrypickRef ? ' -x' : '';
163
+ const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
141
164
  try {
142
- await child_process_promisified_1.exec(cmd, { cwd: env_1.getRepoPath(options) });
143
- return { needsResolving: false };
165
+ await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
166
+ return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
144
167
  }
145
168
  catch (e) {
146
169
  // missing `mainline` option
@@ -149,21 +172,24 @@ async function cherrypick(options, commit) {
149
172
  }
150
173
  // commit was already backported
151
174
  if (e.message.includes('The previous cherry-pick is now empty')) {
152
- const shortSha = commitFormatters_1.getShortSha(commit.sha);
175
+ const shortSha = (0, commitFormatters_1.getShortSha)(sha);
153
176
  throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
154
177
  }
155
178
  // git info missing
156
179
  if (e.message.includes('Please tell me who you are')) {
157
180
  throw new HandledError_1.HandledError(`Cherrypick failed:\n${e.message}`);
158
181
  }
159
- if (e.message.includes(`bad object ${commit.sha}`)) {
160
- throw new HandledError_1.HandledError(`Cherrypick failed because commit "${commit.sha}" was not found`);
182
+ if (e.message.includes(`bad object ${sha}`)) {
183
+ throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
161
184
  }
162
185
  const isCherryPickError = e.cmd === cmd;
163
- const hasConflicts = !lodash_isempty_1.default(await getConflictingFiles(options));
164
- const hasUnstagedFiles = !lodash_isempty_1.default(await getUnstagedFiles(options));
165
- if (isCherryPickError && (hasConflicts || hasUnstagedFiles)) {
166
- return { needsResolving: true };
186
+ if (isCherryPickError) {
187
+ const [conflictingFiles, unstagedFiles] = await Promise.all([
188
+ getConflictingFiles(options),
189
+ getUnstagedFiles(options),
190
+ ]);
191
+ if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
192
+ return { conflictingFiles, unstagedFiles, needsResolving: true };
167
193
  }
168
194
  // re-throw error if there are no conflicts to solve
169
195
  throw e;
@@ -171,23 +197,22 @@ async function cherrypick(options, commit) {
171
197
  }
172
198
  exports.cherrypick = cherrypick;
173
199
  async function commitChanges(commit, options) {
174
- var _a, _b;
175
- const noVerify = options.noVerify ? ` --no-verify` : '';
200
+ const noVerifyFlag = options.noVerify ? ` --no-verify` : '';
176
201
  try {
177
- await child_process_promisified_1.exec(`git commit --no-edit${noVerify}`, {
178
- cwd: env_1.getRepoPath(options),
202
+ await (0, child_process_promisified_1.exec)(`git commit --no-edit${noVerifyFlag}`, {
203
+ cwd: (0, env_1.getRepoPath)(options),
179
204
  });
180
205
  }
181
206
  catch (e) {
182
- if ((_a = e.stdout) === null || _a === void 0 ? void 0 : _a.includes('nothing to commit')) {
207
+ if (e.stdout?.includes('nothing to commit')) {
183
208
  logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
184
209
  return;
185
210
  }
186
211
  // manually set the commit message if the inferred commit message is empty
187
212
  // this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
188
- if ((_b = e.stderr) === null || _b === void 0 ? void 0 : _b.includes('Aborting commit due to empty commit message')) {
189
- await child_process_promisified_1.exec(`git commit -m "${commit.originalMessage}" ${noVerify}`, {
190
- cwd: env_1.getRepoPath(options),
213
+ if (e.stderr?.includes('Aborting commit due to empty commit message')) {
214
+ await (0, child_process_promisified_1.exec)(`git commit -m "${commit.originalMessage}" ${noVerifyFlag}`, {
215
+ cwd: (0, env_1.getRepoPath)(options),
191
216
  });
192
217
  return;
193
218
  }
@@ -197,9 +222,9 @@ async function commitChanges(commit, options) {
197
222
  }
198
223
  exports.commitChanges = commitChanges;
199
224
  async function getConflictingFiles(options) {
200
- const repoPath = env_1.getRepoPath(options);
225
+ const repoPath = (0, env_1.getRepoPath)(options);
201
226
  try {
202
- await child_process_promisified_1.exec(`git --no-pager diff --check`, { cwd: repoPath });
227
+ await (0, child_process_promisified_1.exec)(`git --no-pager diff --check`, { cwd: repoPath });
203
228
  return [];
204
229
  }
205
230
  catch (e) {
@@ -211,9 +236,15 @@ async function getConflictingFiles(options) {
211
236
  .map((line) => {
212
237
  const posSeparator = line.indexOf(':');
213
238
  const filename = line.slice(0, posSeparator).trim();
214
- return path_1.resolve(repoPath, filename);
239
+ return filename;
240
+ });
241
+ const uniqueFiles = (0, lodash_1.uniq)(files);
242
+ return uniqueFiles.map((file) => {
243
+ return {
244
+ absolute: (0, path_1.resolve)(repoPath, file),
245
+ relative: file,
246
+ };
215
247
  });
216
- return lodash_uniq_1.default(files);
217
248
  }
218
249
  // rethrow error since it's unrelated
219
250
  throw e;
@@ -222,21 +253,21 @@ async function getConflictingFiles(options) {
222
253
  exports.getConflictingFiles = getConflictingFiles;
223
254
  // retrieve the list of files that could not be cleanly merged
224
255
  async function getUnstagedFiles(options) {
225
- const repoPath = env_1.getRepoPath(options);
226
- const res = await child_process_promisified_1.exec(`git --no-pager diff --name-only`, {
256
+ const repoPath = (0, env_1.getRepoPath)(options);
257
+ const res = await (0, child_process_promisified_1.exec)(`git --no-pager diff --name-only`, {
227
258
  cwd: repoPath,
228
259
  });
229
260
  const files = res.stdout
230
261
  .split('\n')
231
262
  .filter((file) => !!file)
232
- .map((file) => path_1.resolve(repoPath, file));
233
- return lodash_uniq_1.default(files);
263
+ .map((file) => (0, path_1.resolve)(repoPath, file));
264
+ return (0, lodash_1.uniq)(files);
234
265
  }
235
266
  exports.getUnstagedFiles = getUnstagedFiles;
236
267
  async function setCommitAuthor(options, username) {
237
- const spinner = ora_1.default(`Changing author to "${options.username}"`).start();
268
+ const spinner = (0, ora_1.default)(`Changing author to "${username}"`).start();
238
269
  try {
239
- const res = await child_process_promisified_1.exec(`git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`, { cwd: env_1.getRepoPath(options) });
270
+ const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
240
271
  spinner.succeed();
241
272
  return res;
242
273
  }
@@ -250,16 +281,16 @@ exports.setCommitAuthor = setCommitAuthor;
250
281
  // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
251
282
  // master -> backport/7.x/pr-1234 -> 7.x
252
283
  async function createBackportBranch({ options, targetBranch, backportBranch, }) {
253
- var _a, _b;
254
- const spinner = ora_1.default('Pulling latest changes').start();
284
+ const spinner = (0, ora_1.default)('Pulling latest changes').start();
255
285
  try {
256
- const res = await child_process_promisified_1.exec(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: env_1.getRepoPath(options) });
286
+ const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
257
287
  spinner.succeed();
258
288
  return res;
259
289
  }
260
290
  catch (e) {
261
291
  spinner.fail();
262
- const isBranchInvalid = ((_a = e.stderr) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(`couldn't find remote ref`)) || ((_b = e.stderr) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(`invalid refspec`));
292
+ const isBranchInvalid = e.stderr?.toLowerCase().includes(`couldn't find remote ref`) ||
293
+ e.stderr?.toLowerCase().includes(`invalid refspec`);
263
294
  if (isBranchInvalid) {
264
295
  throw new HandledError_1.HandledError(`The branch "${targetBranch}" is invalid or doesn't exist`);
265
296
  }
@@ -268,8 +299,8 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
268
299
  }
269
300
  exports.createBackportBranch = createBackportBranch;
270
301
  async function deleteBackportBranch({ options, backportBranch, }) {
271
- const spinner = ora_1.default().start();
272
- await child_process_promisified_1.exec(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: env_1.getRepoPath(options) });
302
+ const spinner = (0, ora_1.default)().start();
303
+ await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
273
304
  spinner.stop();
274
305
  }
275
306
  exports.deleteBackportBranch = deleteBackportBranch;
@@ -281,23 +312,17 @@ function getRepoForkOwner(options) {
281
312
  }
282
313
  exports.getRepoForkOwner = getRepoForkOwner;
283
314
  async function pushBackportBranch({ options, backportBranch, }) {
284
- var _a;
285
315
  const repoForkOwner = getRepoForkOwner(options);
286
- const spinnerText = `Pushing branch "${repoForkOwner}:${backportBranch}"`;
287
- const spinner = ora_1.default(spinnerText).start();
288
- if (options.dryRun) {
289
- spinner.succeed(`Dry run: ${spinnerText}`);
290
- return;
291
- }
316
+ const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
292
317
  try {
293
- const res = await child_process_promisified_1.exec(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: env_1.getRepoPath(options) });
318
+ const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
294
319
  spinner.succeed();
295
320
  return res;
296
321
  }
297
322
  catch (e) {
298
323
  spinner.fail();
299
- if ((_a = e.stderr) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(`repository not found`)) {
300
- throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode "--fork false". Read more about "fork mode" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork`);
324
+ if (e.stderr?.toLowerCase().includes(`repository not found`)) {
325
+ throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) 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`);
301
326
  }
302
327
  throw e;
303
328
  }