backport 6.1.1 → 6.1.5

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 (81) hide show
  1. package/README.md +83 -70
  2. package/dist/entrypoint.module.d.ts +4 -1
  3. package/dist/entrypoint.module.js +10 -4
  4. package/dist/entrypoint.module.private.test.js +4 -1
  5. package/dist/main.js +5 -1
  6. package/dist/options/ConfigOptions.d.ts +3 -0
  7. package/dist/options/cliArgs.d.ts +5 -1
  8. package/dist/options/cliArgs.js +24 -2
  9. package/dist/options/cliArgs.test.js +0 -7
  10. package/dist/options/config/config.d.ts +7 -1
  11. package/dist/options/config/config.js +2 -2
  12. package/dist/options/config/config.test.js +1 -1
  13. package/dist/options/config/globalConfig.d.ts +1 -1
  14. package/dist/options/config/globalConfig.js +4 -8
  15. package/dist/options/config/readConfigFile.d.ts +4 -1
  16. package/dist/options/options.d.ts +10 -1
  17. package/dist/options/options.js +10 -2
  18. package/dist/options/options.test.js +113 -123
  19. package/dist/runSequentially.test.js +8 -5
  20. package/dist/services/HandledError.d.ts +1 -1
  21. package/dist/services/env.d.ts +2 -3
  22. package/dist/services/env.js +9 -10
  23. package/dist/services/env.test.js +0 -6
  24. package/dist/services/git.d.ts +2 -1
  25. package/dist/services/git.js +5 -3
  26. package/dist/services/github/v3/createPullRequest.js +1 -1
  27. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  28. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  29. package/dist/services/github/v3/createStatusComment.js +50 -27
  30. package/dist/services/github/v3/createStatusComment.test.js +155 -73
  31. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  32. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  33. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  34. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  35. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  36. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  37. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  38. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  39. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  40. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  41. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  42. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  43. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  44. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  45. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  46. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  47. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  48. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  49. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  50. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -0
  51. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  52. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  53. package/dist/services/logger.d.ts +0 -1
  54. package/dist/services/logger.js +3 -3
  55. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  56. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  57. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  58. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  59. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  60. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  61. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  62. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  63. package/dist/test/inquirer.private.test.js +4 -15
  64. package/dist/test/integration/integration.private.test.js +2 -2
  65. package/dist/test/nockHelpers.js +1 -3
  66. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  67. package/dist/todo-delete.d.ts +1 -0
  68. package/dist/todo-delete.js +17 -0
  69. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  70. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
  71. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  72. package/dist/ui/getCommits.js +1 -1
  73. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  74. package/dist/ui/getCommitsWithoutBackports.js +68 -0
  75. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  76. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  77. package/dist/ui/maybeSetupRepo.js +0 -6
  78. package/dist/utils/redact.d.ts +1 -0
  79. package/dist/utils/redact.js +7 -0
  80. package/package.json +3 -3
  81. package/yarn.lock +462 -284
@@ -3,7 +3,7 @@ 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.getCommitsWithoutBackports = exports.cherrypickAndCreateTargetPullRequest = void 0;
6
+ exports.getBackportBranchName = exports.cherrypickAndCreateTargetPullRequest = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const lodash_1 = require("lodash");
9
9
  const ora = require("ora");
@@ -17,10 +17,10 @@ const addLabelsToPullRequest_1 = require("../services/github/v3/addLabelsToPullR
17
17
  const addReviewersToPullRequest_1 = require("../services/github/v3/addReviewersToPullRequest");
18
18
  const createPullRequest_1 = require("../services/github/v3/createPullRequest");
19
19
  const enablePullRequestAutoMerge_1 = require("../services/github/v4/enablePullRequestAutoMerge");
20
- const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
21
20
  const logger_1 = require("../services/logger");
22
21
  const prompts_1 = require("../services/prompts");
23
22
  const sequentially_1 = require("../services/sequentially");
23
+ const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
24
24
  async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
25
25
  const backportBranch = getBackportBranchName(targetBranch, commits);
26
26
  const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
@@ -83,44 +83,6 @@ async function backportViaFilesystem({ options, prPayload, commits, targetBranch
83
83
  await (0, git_1.deleteBackportBranch)({ options, backportBranch });
84
84
  return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
85
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
- });
122
- }
123
- exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
124
86
  /*
125
87
  * Returns the name of the backport branch without remote name
126
88
  *
@@ -141,13 +103,14 @@ function getBackportBranchName(targetBranch, commits) {
141
103
  exports.getBackportBranchName = getBackportBranchName;
142
104
  async function waitForCherrypick(options, commit, targetBranch) {
143
105
  const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.originalMessage))}`;
106
+ const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
144
107
  const cherrypickSpinner = ora(spinnerText).start();
145
108
  let conflictingFiles;
146
109
  let unstagedFiles;
147
110
  let needsResolving;
148
111
  try {
149
112
  await (0, git_1.fetchBranch)(options, commit.sourceBranch);
150
- ({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
113
+ ({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha, mergedTargetPullRequest));
151
114
  // no conflicts encountered
152
115
  if (!needsResolving) {
153
116
  cherrypickSpinner.succeed();
@@ -177,23 +140,23 @@ async function waitForCherrypick(options, commit, targetBranch) {
177
140
  }
178
141
  autoResolveSpinner.fail();
179
142
  }
180
- const commitsWithoutBackports = await getCommitsWithoutBackports({
143
+ const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
181
144
  options,
182
145
  commit,
183
146
  targetBranch,
184
147
  conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
185
148
  });
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
- }
191
149
  if (options.ci) {
192
150
  throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
193
- type: 'commitsWithoutBackports',
151
+ type: 'merge-conflict-due-to-missing-backports',
194
152
  commitsWithoutBackports,
195
153
  });
196
154
  }
155
+ (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
156
+ if (commitsWithoutBackports.length > 0) {
157
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to "${targetBranch}":`));
158
+ (0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
159
+ }
197
160
  /*
198
161
  * Commit could not be cleanly cherrypicked: Initiating conflict resolution
199
162
  */