backport 8.3.1 → 8.4.2

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 (225) hide show
  1. package/README.md +11 -178
  2. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +42 -21
  3. package/dist/lib/child-process-promisified.js +2 -2
  4. package/dist/lib/git.d.ts +4 -3
  5. package/dist/lib/git.js +22 -29
  6. package/dist/lib/git.private.test.js +10 -7
  7. package/dist/lib/git.test.js +47 -15
  8. package/dist/lib/github/v4/apiRequestV4.js +14 -8
  9. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  10. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  11. package/dist/lib/ora.d.ts +1 -0
  12. package/dist/options/ConfigOptions.d.ts +1 -0
  13. package/dist/options/cliArgs.d.ts +1 -0
  14. package/dist/options/cliArgs.js +5 -0
  15. package/dist/options/config/config.d.ts +1 -0
  16. package/dist/options/config/readConfigFile.d.ts +1 -0
  17. package/dist/options/options.d.ts +2 -0
  18. package/dist/options/options.js +3 -2
  19. package/dist/options/options.test.js +5 -4
  20. package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
  21. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
  22. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  23. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
  24. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  25. package/dist/{entrypoint.cli.private.test.d.ts → test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts} +0 -0
  26. package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
  27. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  28. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts} +0 -0
  29. package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
  30. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  31. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  32. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
  33. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  34. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  35. package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
  36. package/dist/test/replaceStringAndLinebreaks.js +8 -0
  37. package/dist/test/sandbox.js +6 -2
  38. package/dist/utils/packageVersion.d.ts +1 -1
  39. package/dist/utils/packageVersion.js +1 -1
  40. package/package.json +23 -24
  41. package/yarn.lock +841 -950
  42. package/dist/entrypoint.cli.private.test.js +0 -47
  43. package/dist/errors/BackportError.d.ts +0 -19
  44. package/dist/errors/BackportError.js +0 -29
  45. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  46. package/dist/runSequentially.test.d.ts +0 -1
  47. package/dist/runSequentially.test.js +0 -243
  48. package/dist/services/BackportError.d.ts +0 -19
  49. package/dist/services/BackportError.js +0 -29
  50. package/dist/services/HandledBackportError.d.ts +0 -19
  51. package/dist/services/HandledBackportError.js +0 -29
  52. package/dist/services/HandledError.d.ts +0 -19
  53. package/dist/services/HandledError.js +0 -29
  54. package/dist/services/child-process-promisified.d.ts +0 -25
  55. package/dist/services/child-process-promisified.js +0 -58
  56. package/dist/services/env.d.ts +0 -7
  57. package/dist/services/env.js +0 -30
  58. package/dist/services/env.test.d.ts +0 -1
  59. package/dist/services/env.test.js +0 -21
  60. package/dist/services/git.d.ts +0 -77
  61. package/dist/services/git.integration.test.d.ts +0 -1
  62. package/dist/services/git.integration.test.js +0 -616
  63. package/dist/services/git.js +0 -439
  64. package/dist/services/git.private.test.d.ts +0 -1
  65. package/dist/services/git.private.test.js +0 -618
  66. package/dist/services/git.test.d.ts +0 -1
  67. package/dist/services/git.test.js +0 -580
  68. package/dist/services/github/commitFormatters.d.ts +0 -3
  69. package/dist/services/github/commitFormatters.js +0 -17
  70. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  71. package/dist/services/github/commitFormatters.test.js +0 -11
  72. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  73. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  74. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  75. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  76. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  77. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  78. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  79. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  80. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  81. package/dist/services/github/v3/createPullRequest.js +0 -91
  82. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  83. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  84. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  85. package/dist/services/github/v3/createStatusComment.js +0 -131
  86. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  87. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  88. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  89. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  90. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  91. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  92. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  93. package/dist/services/github/v4/apiRequestV4.js +0 -71
  94. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  95. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  96. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  97. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  98. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  99. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  100. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  101. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  102. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  103. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  113. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  114. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  117. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  124. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  126. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  127. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  128. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  129. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  130. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  131. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  132. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  134. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  135. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  136. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  137. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  138. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  142. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  143. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  144. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  145. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  146. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  148. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  149. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  150. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  151. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  152. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  153. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  154. package/dist/services/logger.d.ts +0 -9
  155. package/dist/services/logger.js +0 -74
  156. package/dist/services/prompt.test.d.ts +0 -1
  157. package/dist/services/prompt.test.js +0 -139
  158. package/dist/services/prompts.d.ts +0 -17
  159. package/dist/services/prompts.js +0 -132
  160. package/dist/services/remoteConfig.d.ts +0 -20
  161. package/dist/services/remoteConfig.js +0 -52
  162. package/dist/services/sequentially.d.ts +0 -1
  163. package/dist/services/sequentially.js +0 -10
  164. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  165. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  166. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  168. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  169. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  170. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  171. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  172. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  173. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  174. package/dist/services/test.d.ts +0 -1
  175. package/dist/services/test.js +0 -23
  176. package/dist/state.d.ts +0 -0
  177. package/dist/state.js +0 -1
  178. package/dist/test/ExecError.d.ts +0 -16
  179. package/dist/test/ExecError.js +0 -15
  180. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  181. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  182. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  183. package/dist/test/e2e/cli/date-filters.js +0 -43
  184. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  185. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  186. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  187. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  188. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  189. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  190. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  191. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  192. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  193. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  194. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  195. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  196. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  197. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  199. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  200. package/dist/ui/getCommits.d.ts +0 -2
  201. package/dist/ui/getCommits.js +0 -75
  202. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  203. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  204. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  205. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  206. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  207. package/dist/ui/getGitConfigAuthor.js +0 -15
  208. package/dist/ui/getTargetBranches.d.ts +0 -5
  209. package/dist/ui/getTargetBranches.js +0 -67
  210. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  211. package/dist/ui/getTargetBranches.test.js +0 -204
  212. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  213. package/dist/ui/maybeSetupRepo.js +0 -53
  214. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  215. package/dist/ui/maybeSetupRepo.test.js +0 -238
  216. package/dist/ui/ora.d.ts +0 -2
  217. package/dist/ui/ora.js +0 -21
  218. package/dist/ui/setupRepo.d.ts +0 -2
  219. package/dist/ui/setupRepo.js +0 -56
  220. package/dist/ui/setupRepo.test.d.ts +0 -1
  221. package/dist/ui/setupRepo.test.js +0 -273
  222. package/dist/utils/filterMissingCommits.d.ts +0 -2
  223. package/dist/utils/filterMissingCommits.js +0 -7
  224. package/dist/utils/redact.d.ts +0 -1
  225. package/dist/utils/redact.js +0 -7
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const nock_1 = __importDefault(require("nock"));
7
- const addAssigneesToPullRequest_1 = require("./addAssigneesToPullRequest");
8
- describe('addAssigneesToPullRequest', () => {
9
- it('should add assignees to PR', async () => {
10
- const pullNumber = 216;
11
- const assignees = ['sqren'];
12
- const scope = (0, nock_1.default)('https://api.github.com')
13
- .post('/repos/elastic/kibana/issues/216/assignees', {
14
- assignees: ['sqren'],
15
- })
16
- .reply(200, 'some response');
17
- const res = await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)({
18
- author: 'sqren',
19
- repoName: 'kibana',
20
- repoOwner: 'elastic',
21
- accessToken: 'my-token',
22
- }, pullNumber, assignees);
23
- expect(res).toBe(undefined);
24
- scope.done();
25
- nock_1.default.cleanAll();
26
- });
27
- });
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addLabelsToPullRequest = void 0;
4
- const rest_1 = require("@octokit/rest");
5
- const ora_1 = require("../../../ui/ora");
6
- const logger_1 = require("../../logger");
7
- async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, labels) {
8
- const text = `Adding labels: ${labels.join(', ')}`;
9
- logger_1.logger.info(text);
10
- const spinner = (0, ora_1.ora)(ci, text).start();
11
- try {
12
- const octokit = new rest_1.Octokit({
13
- auth: accessToken,
14
- baseUrl: githubApiBaseUrlV3,
15
- log: logger_1.logger,
16
- });
17
- await octokit.issues.addLabels({
18
- owner: repoOwner,
19
- repo: repoName,
20
- issue_number: pullNumber,
21
- labels,
22
- });
23
- spinner.succeed();
24
- }
25
- catch (e) {
26
- spinner.fail();
27
- logger_1.logger.info(`Could not add labels to PR ${pullNumber}`, e);
28
- }
29
- }
30
- exports.addLabelsToPullRequest = addLabelsToPullRequest;
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addReviewersToPullRequest = void 0;
4
- const rest_1 = require("@octokit/rest");
5
- const ora_1 = require("../../../ui/ora");
6
- const logger_1 = require("../../logger");
7
- async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, reviewers) {
8
- const text = `Adding reviewers: ${reviewers}`;
9
- logger_1.logger.info(text);
10
- const spinner = (0, ora_1.ora)(ci, text).start();
11
- try {
12
- const octokit = new rest_1.Octokit({
13
- auth: accessToken,
14
- baseUrl: githubApiBaseUrlV3,
15
- log: logger_1.logger,
16
- });
17
- await octokit.pulls.requestReviewers({
18
- owner: repoOwner,
19
- repo: repoName,
20
- pull_number: pullNumber,
21
- reviewers,
22
- });
23
- spinner.succeed();
24
- }
25
- catch (e) {
26
- //@ts-expect-error
27
- const message = e.response?.data?.message;
28
- spinner.fail(`Adding reviewers. ${message ? message : ''}`);
29
- logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e);
30
- }
31
- }
32
- exports.addReviewersToPullRequest = addReviewersToPullRequest;
@@ -1,29 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- import { Commit } from '../../sourceCommit/parseSourceCommit';
3
- export interface PullRequestPayload {
4
- owner: string;
5
- repo: string;
6
- title: string;
7
- body: string;
8
- head: string;
9
- base: string;
10
- [key: string]: unknown;
11
- }
12
- export declare function createPullRequest({ options, prPayload, }: {
13
- options: ValidConfigOptions;
14
- prPayload: PullRequestPayload;
15
- }): Promise<{
16
- url: string;
17
- number: number;
18
- didUpdate: boolean;
19
- }>;
20
- export declare function getPullRequestBody({ options, commits, targetBranch, }: {
21
- options: ValidConfigOptions;
22
- commits: Commit[];
23
- targetBranch: string;
24
- }): string;
25
- export declare function getTitle({ options, commits, targetBranch, }: {
26
- options: ValidConfigOptions;
27
- commits: Commit[];
28
- targetBranch: string;
29
- }): string;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void 0;
4
- const rest_1 = require("@octokit/rest");
5
- const ora_1 = require("../../../ui/ora");
6
- const packageVersion_1 = require("../../../utils/packageVersion");
7
- const BackportError_1 = require("../../BackportError");
8
- const logger_1 = require("../../logger");
9
- const commitFormatters_1 = require("../commitFormatters");
10
- const fetchExistingPullRequest_1 = require("../v4/fetchExistingPullRequest");
11
- const getGithubV3ErrorMessage_1 = require("./getGithubV3ErrorMessage");
12
- async function createPullRequest({ options, prPayload, }) {
13
- logger_1.logger.info(`Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`);
14
- const { accessToken, githubApiBaseUrlV3 } = options;
15
- const spinner = (0, ora_1.ora)(options.ci, `Creating pull request`).start();
16
- try {
17
- const octokit = new rest_1.Octokit({
18
- auth: accessToken,
19
- baseUrl: githubApiBaseUrlV3,
20
- log: logger_1.logger,
21
- });
22
- const res = await octokit.pulls.create(prPayload);
23
- spinner.succeed();
24
- return {
25
- url: res.data.html_url,
26
- number: res.data.number,
27
- didUpdate: false,
28
- };
29
- }
30
- catch (e) {
31
- // retrieve url for existing
32
- try {
33
- const existingPR = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({
34
- options,
35
- prPayload,
36
- });
37
- if (existingPR) {
38
- spinner.succeed('Updating existing pull request');
39
- return {
40
- url: existingPR.url,
41
- number: existingPR.number,
42
- didUpdate: true,
43
- };
44
- }
45
- }
46
- catch (e) {
47
- logger_1.logger.info('Could not retrieve existing pull request', e);
48
- // swallow error
49
- }
50
- spinner.fail();
51
- throw new BackportError_1.BackportError(
52
- //@ts-expect-error
53
- `Could not create pull request: ${(0, getGithubV3ErrorMessage_1.getGithubV3ErrorMessage)(e)}`);
54
- }
55
- }
56
- exports.createPullRequest = createPullRequest;
57
- function getPullRequestBody({ options, commits, targetBranch, }) {
58
- const commitMessages = commits
59
- .map((c) => {
60
- const message = c.sourcePullRequest
61
- ? `[${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)}](${c.sourcePullRequest.url})`
62
- : `${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} (${(0, commitFormatters_1.getShortSha)(c.sourceCommit.sha)})`;
63
- return ` - ${message}`;
64
- })
65
- .join('\n');
66
- const defaultPrDescription = `# Backport
67
-
68
- This will backport the following commits from \`${commits[0].sourceBranch}\` to \`${targetBranch}\`:
69
- ${commitMessages}
70
-
71
- <!--- Backport version: ${packageVersion_1.PACKAGE_VERSION} -->
72
-
73
- ### Questions ?
74
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)`;
75
- return (options.prDescription ?? defaultPrDescription)
76
- .replace('{targetBranch}', targetBranch)
77
- .replace('{commitMessages}', commitMessages)
78
- .replace('{defaultPrDescription}', defaultPrDescription);
79
- }
80
- exports.getPullRequestBody = getPullRequestBody;
81
- function getTitle({ options, commits, targetBranch, }) {
82
- const commitMessages = commits
83
- .map((c) => (0, commitFormatters_1.getFirstLine)(c.sourceCommit.message))
84
- .join(' | ');
85
- const defaultPrTitle = '[{targetBranch}] {commitMessages}';
86
- return (options.prTitle ?? defaultPrTitle)
87
- .replace('{targetBranch}', targetBranch)
88
- .replace('{commitMessages}', commitMessages)
89
- .slice(0, 240);
90
- }
91
- exports.getTitle = getTitle;
@@ -1 +0,0 @@
1
- export {};
@@ -1,377 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const createPullRequest_1 = require("./createPullRequest");
4
- describe('getPullRequestBody', () => {
5
- it('when single pull request is backported', () => {
6
- expect((0, createPullRequest_1.getPullRequestBody)({
7
- options: {},
8
- commits: [
9
- {
10
- author: {
11
- email: 'soren.louv@elastic.co',
12
- name: 'Søren Louv-Jansen',
13
- },
14
- sourcePullRequest: {
15
- number: 55,
16
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
17
- mergeCommit: {
18
- sha: 'abcdefghi',
19
- message: 'My commit message (#55)',
20
- },
21
- },
22
- sourceCommit: {
23
- committedDate: '2020',
24
- sha: 'abcdefghi',
25
- message: 'My commit message (#55)',
26
- },
27
- expectedTargetPullRequests: [],
28
- sourceBranch: 'master',
29
- },
30
- ],
31
- targetBranch: '7.x',
32
- })).toMatchInlineSnapshot(`
33
- "# Backport
34
-
35
- This will backport the following commits from \`master\` to \`7.x\`:
36
- - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
37
-
38
- <!--- Backport version: 1.2.3-mocked -->
39
-
40
- ### Questions ?
41
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
42
- `);
43
- });
44
- it('when a single commit (non pull request) is backported', () => {
45
- expect((0, createPullRequest_1.getPullRequestBody)({
46
- options: {},
47
- commits: [
48
- {
49
- author: {
50
- email: 'soren.louv@elastic.co',
51
- name: 'Søren Louv-Jansen',
52
- },
53
- sourceCommit: {
54
- committedDate: '',
55
- sha: 'abcdefghijklmw',
56
- message: 'My commit message',
57
- },
58
- sourceBranch: 'main',
59
- expectedTargetPullRequests: [],
60
- },
61
- ],
62
- targetBranch: '7.x',
63
- })).toMatchInlineSnapshot(`
64
- "# Backport
65
-
66
- This will backport the following commits from \`main\` to \`7.x\`:
67
- - My commit message (abcdefgh)
68
-
69
- <!--- Backport version: 1.2.3-mocked -->
70
-
71
- ### Questions ?
72
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
73
- `);
74
- });
75
- it('when multiple commits are backported', () => {
76
- expect((0, createPullRequest_1.getPullRequestBody)({
77
- options: {},
78
- commits: [
79
- {
80
- author: {
81
- email: 'soren.louv@elastic.co',
82
- name: 'Søren Louv-Jansen',
83
- },
84
- sourcePullRequest: {
85
- number: 55,
86
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
87
- mergeCommit: {
88
- sha: 'abcdefghijklm',
89
- message: 'My commit message (#55)',
90
- },
91
- },
92
- sourceCommit: {
93
- committedDate: '',
94
- sha: 'abcdefghijklm',
95
- message: 'My commit message (#55)',
96
- },
97
- sourceBranch: 'main',
98
- expectedTargetPullRequests: [],
99
- },
100
- {
101
- author: {
102
- email: 'soren.louv@elastic.co',
103
- name: 'Søren Louv-Jansen',
104
- },
105
- sourceCommit: {
106
- committedDate: '',
107
- sha: 'qwertyuiop',
108
- message: 'Another commit message',
109
- },
110
- sourceBranch: 'main',
111
- expectedTargetPullRequests: [],
112
- },
113
- ],
114
- targetBranch: '7.x',
115
- })).toMatchInlineSnapshot(`
116
- "# Backport
117
-
118
- This will backport the following commits from \`main\` to \`7.x\`:
119
- - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
120
- - Another commit message (qwertyui)
121
-
122
- <!--- Backport version: 1.2.3-mocked -->
123
-
124
- ### Questions ?
125
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
126
- `);
127
- });
128
- it('when a PR is merged (instead of squashed) and the individual commits are selected', () => {
129
- expect((0, createPullRequest_1.getPullRequestBody)({
130
- options: {},
131
- commits: [
132
- {
133
- sourceCommit: {
134
- committedDate: '2022-02-07T23:53:14Z',
135
- message: 'Merge strategy: Second commit',
136
- sha: 'e8df5eaa4db7b94474b48e2320b02d33a830d9fb',
137
- },
138
- author: {
139
- email: 'soren.louv@elastic.co',
140
- name: 'Søren Louv-Jansen',
141
- },
142
- sourcePullRequest: {
143
- number: 1,
144
- url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
145
- mergeCommit: {
146
- message: 'Merge pull request #1 from backport-org/merge-strategy\n\nMerge commits to `main`',
147
- sha: '0db7f1ac1233461563d8708511d1c14adbab46da',
148
- },
149
- },
150
- sourceBranch: 'main',
151
- expectedTargetPullRequests: [],
152
- },
153
- {
154
- sourceCommit: {
155
- committedDate: '2022-02-07T23:51:59Z',
156
- message: 'Merge strategy: First commit',
157
- sha: '5411b1c1144093e422220008f23f2c2b909ed113',
158
- },
159
- author: {
160
- email: 'soren.louv@elastic.co',
161
- name: 'Søren Louv-Jansen',
162
- },
163
- sourcePullRequest: {
164
- number: 1,
165
- url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
166
- mergeCommit: {
167
- message: 'Merge pull request #1 from backport-org/merge-strategy\n\nMerge commits to `main`',
168
- sha: '0db7f1ac1233461563d8708511d1c14adbab46da',
169
- },
170
- },
171
- sourceBranch: 'main',
172
- expectedTargetPullRequests: [],
173
- },
174
- ],
175
- targetBranch: '7.x',
176
- })).toMatchInlineSnapshot(`
177
- "# Backport
178
-
179
- This will backport the following commits from \`main\` to \`7.x\`:
180
- - [Merge strategy: Second commit](https://github.com/backport-org/different-merge-strategies/pull/1)
181
- - [Merge strategy: First commit](https://github.com/backport-org/different-merge-strategies/pull/1)
182
-
183
- <!--- Backport version: 1.2.3-mocked -->
184
-
185
- ### Questions ?
186
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
187
- `);
188
- });
189
- it('replaces template variables in PR description', () => {
190
- expect((0, createPullRequest_1.getPullRequestBody)({
191
- options: {
192
- prDescription: 'Backporting the following to {targetBranch}:\n{commitMessages}',
193
- },
194
- commits: [
195
- {
196
- author: {
197
- email: 'soren.louv@elastic.co',
198
- name: 'Søren Louv-Jansen',
199
- },
200
- sourcePullRequest: {
201
- number: 55,
202
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
203
- mergeCommit: {
204
- sha: 'abcdefghijklm',
205
- message: 'My commit message (#55)',
206
- },
207
- },
208
- sourceCommit: {
209
- committedDate: '',
210
- sha: 'abcdefghijklm',
211
- message: 'My commit message (#55)',
212
- },
213
- sourceBranch: 'main',
214
- expectedTargetPullRequests: [],
215
- },
216
- {
217
- author: {
218
- email: 'soren.louv@elastic.co',
219
- name: 'Søren Louv-Jansen',
220
- },
221
- sourceCommit: {
222
- committedDate: '',
223
- sha: 'qwertyuiop',
224
- message: 'Another commit message',
225
- },
226
- sourceBranch: 'main',
227
- expectedTargetPullRequests: [],
228
- },
229
- ],
230
- targetBranch: '7.x',
231
- })).toMatchInlineSnapshot(`
232
- "Backporting the following to 7.x:
233
- - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
234
- - Another commit message (qwertyui)"
235
- `);
236
- });
237
- it('appends text to the default descriptions', () => {
238
- expect((0, createPullRequest_1.getPullRequestBody)({
239
- options: {
240
- prDescription: '{defaultPrDescription}\n\ntext to append',
241
- },
242
- commits: [
243
- {
244
- author: {
245
- email: 'soren.louv@elastic.co',
246
- name: 'Søren Louv-Jansen',
247
- },
248
- sourcePullRequest: {
249
- number: 55,
250
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
251
- mergeCommit: {
252
- sha: 'abcdefghijklm',
253
- message: 'My commit message (#55)',
254
- },
255
- },
256
- sourceCommit: {
257
- committedDate: '',
258
- sha: 'abcdefghijklm',
259
- message: 'My commit message (#55)',
260
- },
261
- sourceBranch: 'main',
262
- expectedTargetPullRequests: [],
263
- },
264
- {
265
- author: {
266
- email: 'soren.louv@elastic.co',
267
- name: 'Søren Louv-Jansen',
268
- },
269
- sourceCommit: {
270
- committedDate: '',
271
- sha: 'qwertyuiop',
272
- message: 'Another commit message',
273
- },
274
- sourceBranch: 'main',
275
- expectedTargetPullRequests: [],
276
- },
277
- ],
278
- targetBranch: '7.x',
279
- })).toMatchInlineSnapshot(`
280
- "# Backport
281
-
282
- This will backport the following commits from \`main\` to \`7.x\`:
283
- - [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
284
- - Another commit message (qwertyui)
285
-
286
- <!--- Backport version: 1.2.3-mocked -->
287
-
288
- ### Questions ?
289
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
290
-
291
- text to append"
292
- `);
293
- });
294
- });
295
- describe('getTitle', () => {
296
- it('has the default title', () => {
297
- expect((0, createPullRequest_1.getTitle)({
298
- options: {},
299
- commits: [
300
- {
301
- author: {
302
- email: 'soren.louv@elastic.co',
303
- name: 'Søren Louv-Jansen',
304
- },
305
- sourceBranch: 'main',
306
- sourcePullRequest: {
307
- number: 55,
308
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
309
- mergeCommit: {
310
- sha: 'abcdefghi',
311
- message: 'My commit message (#55)',
312
- },
313
- },
314
- sourceCommit: {
315
- committedDate: '2020',
316
- sha: 'abcdefghi',
317
- message: 'My commit message (#55)',
318
- },
319
- expectedTargetPullRequests: [],
320
- },
321
- {
322
- author: {
323
- email: 'soren.louv@elastic.co',
324
- name: 'Søren Louv-Jansen',
325
- },
326
- sourcePullRequest: {
327
- number: 56,
328
- url: 'https://github.com/backport-org/different-merge-strategies/pull/56',
329
- mergeCommit: {
330
- sha: 'jklmnopqr',
331
- message: 'Another commit message (#56)',
332
- },
333
- },
334
- sourceCommit: {
335
- committedDate: '2020',
336
- sha: 'jklmnopqr',
337
- message: 'Another commit message (#56)',
338
- },
339
- sourceBranch: 'main',
340
- expectedTargetPullRequests: [],
341
- },
342
- ],
343
- targetBranch: '7.x',
344
- })).toEqual('[7.x] My commit message (#55) | Another commit message (#56)');
345
- });
346
- it('replaces template variables in PR title', () => {
347
- expect((0, createPullRequest_1.getTitle)({
348
- options: {
349
- prTitle: 'Branch: "{targetBranch}". Messages: {commitMessages}',
350
- },
351
- commits: [
352
- {
353
- author: {
354
- email: 'soren.louv@elastic.co',
355
- name: 'Søren Louv-Jansen',
356
- },
357
- sourcePullRequest: {
358
- number: 55,
359
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
360
- mergeCommit: {
361
- sha: 'abcdefghi',
362
- message: 'My commit message (#55)',
363
- },
364
- },
365
- sourceCommit: {
366
- committedDate: '',
367
- sha: 'abcdefghi',
368
- message: 'My commit message (#55)',
369
- },
370
- sourceBranch: 'main',
371
- expectedTargetPullRequests: [],
372
- },
373
- ],
374
- targetBranch: '7.x',
375
- })).toEqual('Branch: "7.x". Messages: My commit message (#55)');
376
- });
377
- });
@@ -1,11 +0,0 @@
1
- import { BackportResponse } from '../../../backportRun';
2
- import { ValidConfigOptions } from '../../../options/options';
3
- export declare function createStatusComment({ options, backportResponse, }: {
4
- options: ValidConfigOptions;
5
- backportResponse: BackportResponse;
6
- }): Promise<void>;
7
- export declare function getCommentBody({ options, pullNumber, backportResponse, }: {
8
- options: ValidConfigOptions;
9
- pullNumber: number;
10
- backportResponse: BackportResponse;
11
- }): string | undefined;