backport 5.6.4 → 6.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 (253) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +33 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +56 -39
  12. package/dist/options/cliArgs.d.ts +38 -45
  13. package/dist/options/cliArgs.js +123 -104
  14. package/dist/options/cliArgs.test.js +106 -119
  15. package/dist/options/config/config.d.ts +56 -2
  16. package/dist/options/config/config.js +12 -6
  17. package/dist/options/config/config.test.js +11 -6
  18. package/dist/options/config/getOptionsFromGit.d.ts +4 -0
  19. package/dist/options/config/getOptionsFromGit.js +8 -0
  20. package/dist/options/config/globalConfig.d.ts +2 -1
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -1
  24. package/dist/options/config/projectConfig.js +3 -3
  25. package/dist/options/config/projectConfig.test.js +54 -17
  26. package/dist/options/config/readConfigFile.d.ts +53 -2
  27. package/dist/options/config/readConfigFile.js +31 -5
  28. package/dist/options/options.d.ts +67 -35
  29. package/dist/options/options.js +99 -16
  30. package/dist/options/options.test.js +214 -67
  31. package/dist/options/parseRequiredOptions.d.ts +71 -0
  32. package/dist/options/parseRequiredOptions.js +68 -0
  33. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  34. package/dist/options/parseRequiredOptions.test.js +122 -0
  35. package/dist/runSequentially.d.ts +20 -0
  36. package/dist/runSequentially.js +41 -0
  37. package/dist/runSequentially.test.d.ts +1 -0
  38. package/dist/runSequentially.test.js +192 -0
  39. package/dist/runWithOptions.js +7 -14
  40. package/dist/runWithOptions.test.js +142 -16
  41. package/dist/scripts/generate-gql.d.ts +1 -0
  42. package/dist/scripts/generate-gql.js +15 -0
  43. package/dist/scripts/postinstall.js +4 -4
  44. package/dist/scripts/postinstall.test.js +9 -2
  45. package/dist/scripts/runPostinstall.js +1 -1
  46. package/dist/services/HandledError.d.ts +11 -1
  47. package/dist/services/HandledError.js +2 -1
  48. package/dist/services/child-process-promisified.d.ts +1 -1
  49. package/dist/services/child-process-promisified.js +2 -2
  50. package/dist/services/env.js +5 -5
  51. package/dist/services/env.test.js +11 -4
  52. package/dist/services/fs-promisified.js +4 -4
  53. package/dist/services/getExpectedTarget.d.ts +9 -0
  54. package/dist/services/getExpectedTarget.js +77 -0
  55. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  56. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  57. package/dist/services/git.d.ts +23 -5
  58. package/dist/services/git.integration.test.d.ts +1 -0
  59. package/dist/services/git.integration.test.js +168 -0
  60. package/dist/services/git.js +133 -60
  61. package/dist/services/git.test.js +160 -53
  62. package/dist/services/github/commitFormatters.d.ts +3 -7
  63. package/dist/services/github/commitFormatters.js +10 -19
  64. package/dist/services/github/commitFormatters.test.js +2 -24
  65. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  66. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  67. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  68. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  69. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  70. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  71. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  72. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  73. package/dist/services/github/v3/createPullRequest.js +32 -26
  74. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  75. package/dist/services/github/v3/createPullRequest.test.js +78 -0
  76. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  77. package/dist/services/github/v3/createStatusComment.js +97 -0
  78. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  79. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  80. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  81. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  82. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  83. package/dist/services/github/v4/apiRequestV4.js +9 -11
  84. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  86. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  91. package/dist/services/github/v4/fetchAuthorId.d.ts +10 -2
  92. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  93. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  95. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  96. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  97. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  115. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  121. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  122. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  123. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  124. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  125. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  126. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  127. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  132. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  133. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  134. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  135. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  136. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  137. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  138. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  139. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  140. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  141. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  142. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  143. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  144. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  145. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  146. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  147. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  148. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  149. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  150. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  151. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  152. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  153. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  154. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  155. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  156. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  157. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  158. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  159. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  160. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  161. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +63 -0
  162. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  163. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  164. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
  165. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
  166. package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
  167. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  168. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  169. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  170. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  171. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  172. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  173. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  174. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  175. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  176. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  177. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  178. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  179. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  180. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  181. package/dist/services/logger.d.ts +3 -3
  182. package/dist/services/logger.js +24 -24
  183. package/dist/services/prompt.test.d.ts +1 -0
  184. package/dist/services/prompt.test.js +87 -0
  185. package/dist/services/prompts.d.ts +10 -4
  186. package/dist/services/prompts.js +85 -22
  187. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  188. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  189. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  191. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  192. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  193. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  194. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  195. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  196. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  197. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  198. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  199. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  200. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  201. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  202. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  203. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  204. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  205. package/dist/services/sourceCommit.d.ts +78 -0
  206. package/dist/services/sourceCommit.js +86 -0
  207. package/dist/services/sourceCommit.test.d.ts +1 -0
  208. package/dist/services/sourceCommit.test.js +280 -0
  209. package/dist/test/inquirer.private.test.js +105 -61
  210. package/dist/test/integration/createSpies.d.ts +1 -1
  211. package/dist/test/integration/createSpies.js +21 -9
  212. package/dist/test/integration/envConstants.js +5 -6
  213. package/dist/test/integration/helpers.js +1 -1
  214. package/dist/test/integration/integration.private.test.d.ts +1 -0
  215. package/dist/test/integration/integration.private.test.js +317 -0
  216. package/dist/test/integration/integration.test.js +30 -31
  217. package/dist/test/mockConfigFiles.d.ts +5 -0
  218. package/dist/test/mockConfigFiles.js +37 -0
  219. package/dist/test/nockHelpers.d.ts +3 -3
  220. package/dist/test/nockHelpers.js +7 -11
  221. package/dist/test/private/getDevAccessToken.js +1 -1
  222. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  223. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  224. package/dist/types/Commit.d.ts +85 -0
  225. package/dist/types/Commit.js +139 -0
  226. package/dist/types/commitNode.d.ts +89 -0
  227. package/dist/types/commitNode.js +139 -0
  228. package/dist/types/commitNode.test.d.ts +1 -0
  229. package/dist/types/commitNode.test.js +255 -0
  230. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  231. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  232. package/dist/ui/cherrypickAndCreatePullRequest.test.js +333 -76
  233. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  234. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  235. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  236. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  237. package/dist/ui/getCommits.d.ts +1 -1
  238. package/dist/ui/getCommits.js +55 -25
  239. package/dist/ui/getTargetBranches.d.ts +3 -2
  240. package/dist/ui/getTargetBranches.js +33 -18
  241. package/dist/ui/getTargetBranches.test.js +75 -99
  242. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  243. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  244. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  245. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  246. package/dist/ui/maybeSetupRepo.js +11 -10
  247. package/dist/ui/maybeSetupRepo.test.js +54 -4
  248. package/dist/utils/excludeUndefined.d.ts +6 -0
  249. package/dist/utils/excludeUndefined.js +7 -0
  250. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  251. package/dist/utils/excludeUndefined.test.js +24 -0
  252. package/package.json +37 -51
  253. package/yarn.lock +2416 -2987
@@ -3,10 +3,9 @@ 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.getBackportBranchName = exports.cherrypickAndCreateTargetPullRequest = void 0;
6
+ exports.getBackportBranchName = exports.getCommitsWithoutBackports = exports.cherrypickAndCreateTargetPullRequest = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const lodash_difference_1 = __importDefault(require("lodash.difference"));
9
- const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
8
+ const lodash_1 = require("lodash");
10
9
  const ora = require("ora");
11
10
  const HandledError_1 = require("../services/HandledError");
12
11
  const child_process_promisified_1 = require("../services/child-process-promisified");
@@ -15,21 +14,24 @@ const git_1 = require("../services/git");
15
14
  const commitFormatters_1 = require("../services/github/commitFormatters");
16
15
  const addAssigneesToPullRequest_1 = require("../services/github/v3/addAssigneesToPullRequest");
17
16
  const addLabelsToPullRequest_1 = require("../services/github/v3/addLabelsToPullRequest");
17
+ const addReviewersToPullRequest_1 = require("../services/github/v3/addReviewersToPullRequest");
18
18
  const createPullRequest_1 = require("../services/github/v3/createPullRequest");
19
+ const enablePullRequestAutoMerge_1 = require("../services/github/v4/enablePullRequestAutoMerge");
20
+ const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
19
21
  const logger_1 = require("../services/logger");
20
22
  const prompts_1 = require("../services/prompts");
21
23
  const sequentially_1 = require("../services/sequentially");
22
24
  async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
23
25
  const backportBranch = getBackportBranchName(targetBranch, commits);
24
- const repoForkOwner = git_1.getRepoForkOwner(options);
25
- logger_1.consoleLog(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
26
+ const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
27
+ (0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
26
28
  const prPayload = {
27
29
  owner: options.repoOwner,
28
30
  repo: options.repoName,
29
- title: createPullRequest_1.getTitle({ options, commits, targetBranch }),
30
- body: createPullRequest_1.getBody({ options, commits, targetBranch }),
31
+ title: (0, createPullRequest_1.getTitle)({ options, commits, targetBranch }),
32
+ body: (0, createPullRequest_1.getPullRequestBody)({ options, commits, targetBranch }),
31
33
  head: `${repoForkOwner}:${backportBranch}`,
32
- base: targetBranch,
34
+ base: targetBranch, // eg. 7.x
33
35
  };
34
36
  const targetPullRequest = await backportViaFilesystem({
35
37
  options,
@@ -39,37 +41,86 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
39
41
  commits,
40
42
  });
41
43
  // add assignees to target pull request
44
+ const assignees = options.autoAssign
45
+ ? [options.authenticatedUsername]
46
+ : options.assignees;
42
47
  if (options.assignees.length > 0) {
43
- await addAssigneesToPullRequest_1.addAssigneesToPullRequest(options, targetPullRequest.number, options.assignees);
48
+ await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)(options, targetPullRequest.number, assignees);
49
+ }
50
+ // add reviewers to target pull request
51
+ if (options.reviewers.length > 0) {
52
+ await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, targetPullRequest.number, options.reviewers);
44
53
  }
45
54
  // add labels to target pull request
46
55
  if (options.targetPRLabels.length > 0) {
47
- await addLabelsToPullRequest_1.addLabelsToPullRequest(options, targetPullRequest.number, options.targetPRLabels);
56
+ await (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, targetPullRequest.number, options.targetPRLabels);
57
+ }
58
+ // make PR auto mergable
59
+ if (options.autoMerge) {
60
+ await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)(options, targetPullRequest.number);
48
61
  }
49
62
  // add labels to source pull requests
50
63
  if (options.sourcePRLabels.length > 0) {
51
64
  const promises = commits.map((commit) => {
52
65
  if (commit.pullNumber) {
53
- return addLabelsToPullRequest_1.addLabelsToPullRequest(options, commit.pullNumber, options.sourcePRLabels);
66
+ return (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, commit.pullNumber, options.sourcePRLabels);
54
67
  }
55
68
  });
56
69
  await Promise.all(promises);
57
70
  }
58
- logger_1.consoleLog(`View pull request: ${targetPullRequest.url}`);
71
+ (0, logger_1.consoleLog)(`View pull request: ${targetPullRequest.url}`);
59
72
  return targetPullRequest;
60
73
  }
61
74
  exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
62
75
  async function backportViaFilesystem({ options, prPayload, commits, targetBranch, backportBranch, }) {
63
76
  logger_1.logger.info('Backporting via filesystem');
64
- await git_1.createBackportBranch({ options, targetBranch, backportBranch });
65
- await sequentially_1.sequentially(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
77
+ await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
78
+ await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
66
79
  if (options.resetAuthor) {
67
- await git_1.setCommitAuthor(options, options.username);
80
+ await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
68
81
  }
69
- await git_1.pushBackportBranch({ options, backportBranch });
70
- await git_1.deleteBackportBranch({ options, backportBranch });
71
- return createPullRequest_1.createPullRequest({ options, prPayload });
82
+ await (0, git_1.pushBackportBranch)({ options, backportBranch });
83
+ await (0, git_1.deleteBackportBranch)({ options, backportBranch });
84
+ return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
85
+ }
86
+ // when the user is facing a git conflict we should help them understand
87
+ // why the conflict occurs. In many cases it's because one or more commits haven't been backported yet
88
+ async function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }) {
89
+ const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
90
+ ...options,
91
+ author: null,
92
+ commitPaths: conflictingFiles,
93
+ });
94
+ return (await Promise.all(commitsInConflictingPaths
95
+ .filter((c) => {
96
+ // exclude the commit we are currently trying to backport
97
+ if (c.sha === commit.sha) {
98
+ return false;
99
+ }
100
+ // exclude commits that are newer than the commit we are trying to backport
101
+ if (c.committedDate > commit.committedDate) {
102
+ return false;
103
+ }
104
+ const alreadyBackported = c.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state === 'MERGED');
105
+ if (alreadyBackported) {
106
+ return false;
107
+ }
108
+ return true;
109
+ })
110
+ .slice(0, 10) // limit to max 10 commits
111
+ .map(async (c) => {
112
+ const isCommitInBranch = await (0, git_1.getIsCommitInBranch)(options, c.sha);
113
+ return { c, isCommitInBranch };
114
+ })))
115
+ .filter(({ isCommitInBranch }) => !isCommitInBranch)
116
+ .map(({ c }) => {
117
+ // get pull request for the target branch (if it exists)
118
+ const unmergedPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch);
119
+ const formatted = ` - ${(0, commitFormatters_1.getFirstLine)(c.originalMessage)}${unmergedPr?.state === 'OPEN' ? chalk_1.default.gray(' (backport pending)') : ''}${c.pullUrl ? `\n ${c.pullUrl}` : ''}`;
120
+ return { formatted, commit: c };
121
+ });
72
122
  }
123
+ exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
73
124
  /*
74
125
  * Returns the name of the backport branch without remote name
75
126
  *
@@ -82,21 +133,21 @@ function getBackportBranchName(targetBranch, commits) {
82
133
  const refValues = commits
83
134
  .map((commit) => commit.pullNumber
84
135
  ? `pr-${commit.pullNumber}`
85
- : `commit-${commitFormatters_1.getShortSha(commit.sha)}`)
136
+ : `commit-${(0, commitFormatters_1.getShortSha)(commit.sha)}`)
86
137
  .join('_')
87
138
  .slice(0, 200);
88
139
  return `backport/${targetBranch}/${refValues}`;
89
140
  }
90
141
  exports.getBackportBranchName = getBackportBranchName;
91
142
  async function waitForCherrypick(options, commit, targetBranch) {
92
- const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright(commit.formattedMessage)}`;
143
+ const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.originalMessage))}`;
93
144
  const cherrypickSpinner = ora(spinnerText).start();
94
- if (options.dryRun) {
95
- cherrypickSpinner.succeed(`Dry run: ${spinnerText}`);
96
- return;
97
- }
145
+ let conflictingFiles;
146
+ let unstagedFiles;
147
+ let needsResolving;
98
148
  try {
99
- const { needsResolving } = await git_1.cherrypick(options, commit);
149
+ await (0, git_1.fetchBranch)(options, commit.sourceBranch);
150
+ ({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
100
151
  // no conflicts encountered
101
152
  if (!needsResolving) {
102
153
  cherrypickSpinner.succeed();
@@ -112,10 +163,9 @@ async function waitForCherrypick(options, commit, targetBranch) {
112
163
  // resolve conflicts automatically
113
164
  if (options.autoFixConflicts) {
114
165
  const autoResolveSpinner = ora('Attempting to resolve conflicts automatically').start();
115
- const filesWithConflicts = await git_1.getConflictingFiles(options);
116
- const repoPath = env_1.getRepoPath(options);
166
+ const repoPath = (0, env_1.getRepoPath)(options);
117
167
  const didAutoFix = await options.autoFixConflicts({
118
- files: filesWithConflicts,
168
+ files: conflictingFiles.map((f) => f.absolute),
119
169
  directory: repoPath,
120
170
  logger: logger_1.logger,
121
171
  targetBranch,
@@ -127,23 +177,42 @@ async function waitForCherrypick(options, commit, targetBranch) {
127
177
  }
128
178
  autoResolveSpinner.fail();
129
179
  }
180
+ const commitsWithoutBackports = await getCommitsWithoutBackports({
181
+ options,
182
+ commit,
183
+ targetBranch,
184
+ conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
185
+ });
186
+ (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
187
+ if (commitsWithoutBackports.length > 0) {
188
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following commits to "${targetBranch}":`));
189
+ (0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
190
+ }
130
191
  if (options.ci) {
131
- throw new HandledError_1.HandledError('Commit could not be cherrypicked due to conflicts');
192
+ throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
193
+ type: 'commitsWithoutBackports',
194
+ commitsWithoutBackports,
195
+ });
132
196
  }
133
197
  /*
134
198
  * Commit could not be cleanly cherrypicked: Initiating conflict resolution
135
199
  */
136
200
  if (options.editor) {
137
- const repoPath = env_1.getRepoPath(options);
138
- await child_process_promisified_1.exec(`${options.editor} ${repoPath}`, {});
201
+ const repoPath = (0, env_1.getRepoPath)(options);
202
+ await (0, child_process_promisified_1.exec)(`${options.editor} ${repoPath}`, {});
139
203
  }
140
204
  // list files with conflict markers + unstaged files and require user to resolve them
141
- await listConflictingAndUnstagedFiles(options);
205
+ await listConflictingAndUnstagedFiles({
206
+ retries: 0,
207
+ options,
208
+ conflictingFiles: conflictingFiles.map((f) => f.absolute),
209
+ unstagedFiles,
210
+ });
142
211
  // Conflicts should be resolved and files staged at this point
143
212
  const stagingSpinner = ora(`Finalizing cherrypick`).start();
144
213
  try {
145
214
  // Run `git commit`
146
- await git_1.commitChanges(commit, options);
215
+ await (0, git_1.commitChanges)(commit, options);
147
216
  stagingSpinner.succeed();
148
217
  }
149
218
  catch (e) {
@@ -151,43 +220,45 @@ async function waitForCherrypick(options, commit, targetBranch) {
151
220
  throw e;
152
221
  }
153
222
  }
154
- async function listConflictingAndUnstagedFiles(options) {
155
- const checkForProblems = async (retries = 0) => {
156
- const [conflictingFiles, _unstagedFiles] = await Promise.all([
157
- git_1.getConflictingFiles(options),
158
- git_1.getUnstagedFiles(options),
159
- ]);
160
- const unstagedFiles = lodash_difference_1.default(_unstagedFiles, conflictingFiles);
161
- const hasConflictingFiles = !lodash_isempty_1.default(conflictingFiles);
162
- const hasUnstagedFiles = !lodash_isempty_1.default(unstagedFiles);
163
- if (!hasConflictingFiles && !hasUnstagedFiles) {
164
- return;
165
- }
166
- // add divider between prompts
167
- if (retries > 0) {
168
- logger_1.consoleLog('\n----------------------------------------\n');
169
- }
170
- // show conflict section if there are conflicting files
171
- const conflictSection = hasConflictingFiles
172
- ? `Conflicting files:\n${chalk_1.default.reset(conflictingFiles.map((file) => ` - ${file}`).join('\n'))}`
173
- : '';
174
- const unstagedSection = hasUnstagedFiles
175
- ? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
176
- : '';
177
- const res = await prompts_1.confirmPrompt(`${chalk_1.default.reset(`Please fix the issues in: ${env_1.getRepoPath(options)}`)}
223
+ async function listConflictingAndUnstagedFiles({ retries, options, conflictingFiles, unstagedFiles, }) {
224
+ const hasUnstagedFiles = !(0, lodash_1.isEmpty)((0, lodash_1.difference)(unstagedFiles, conflictingFiles));
225
+ const hasConflictingFiles = !(0, lodash_1.isEmpty)(conflictingFiles);
226
+ if (!hasConflictingFiles && !hasUnstagedFiles) {
227
+ return;
228
+ }
229
+ // add divider between prompts
230
+ if (retries > 0) {
231
+ (0, logger_1.consoleLog)('\n----------------------------------------\n');
232
+ }
233
+ const header = chalk_1.default.reset(`Fix the following conflicts manually:`);
234
+ // show conflict section if there are conflicting files
235
+ const conflictSection = hasConflictingFiles
236
+ ? `Conflicting files:\n${chalk_1.default.reset(conflictingFiles.map((file) => ` - ${file}`).join('\n'))}`
237
+ : '';
238
+ const unstagedSection = hasUnstagedFiles
239
+ ? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
240
+ : '';
241
+ const res = await (0, prompts_1.confirmPrompt)(`${header}
178
242
 
179
243
  ${conflictSection}
180
244
  ${unstagedSection}
181
245
 
182
246
  Press ENTER when the conflicts are resolved and files are staged`);
183
- if (!res) {
184
- throw new HandledError_1.HandledError('Aborted');
185
- }
186
- const MAX_RETRIES = 100;
187
- if (retries++ > MAX_RETRIES) {
188
- throw new Error(`Maximum number of retries (${MAX_RETRIES}) exceeded`);
189
- }
190
- await checkForProblems(retries);
191
- };
192
- await checkForProblems();
247
+ if (!res) {
248
+ throw new HandledError_1.HandledError('Aborted');
249
+ }
250
+ const MAX_RETRIES = 100;
251
+ if (retries++ > MAX_RETRIES) {
252
+ throw new Error(`Maximum number of retries (${MAX_RETRIES}) exceeded`);
253
+ }
254
+ const [_conflictingFiles, _unstagedFiles] = await Promise.all([
255
+ (0, git_1.getConflictingFiles)(options),
256
+ (0, git_1.getUnstagedFiles)(options),
257
+ ]);
258
+ await listConflictingAndUnstagedFiles({
259
+ retries,
260
+ options,
261
+ conflictingFiles: _conflictingFiles.map((file) => file.absolute),
262
+ unstagedFiles: _unstagedFiles,
263
+ });
193
264
  }