backport 8.3.0 → 8.4.1

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 (238) hide show
  1. package/README.md +11 -178
  2. package/dist/backportRun.js +1 -1
  3. package/dist/entrypoint.module.d.ts +2 -2
  4. package/dist/entrypoint.module.js +2 -0
  5. package/dist/entrypoint.module.private.test.js +11 -10
  6. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +30 -20
  7. package/dist/lib/child-process-promisified.js +2 -2
  8. package/dist/lib/getCommits.js +1 -1
  9. package/dist/lib/git.d.ts +1 -1
  10. package/dist/lib/git.js +8 -28
  11. package/dist/lib/git.private.test.js +7 -7
  12. package/dist/lib/git.test.js +28 -12
  13. package/dist/lib/github/v3/createStatusComment.js +3 -2
  14. package/dist/lib/github/v3/createStatusComment.test.js +61 -0
  15. package/dist/lib/github/v4/apiRequestV4.js +1 -1
  16. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
  17. package/dist/{entrypoint.cli.private.test.d.ts → lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts} +0 -0
  18. package/dist/lib/github/v4/{enablePullRequestAutoMerge.private.test.js → enablePullRequestAutoMerge.mutation.test.js} +34 -8
  19. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +6 -3
  20. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
  21. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
  22. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
  23. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
  24. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
  25. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
  26. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  27. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
  28. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
  29. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
  30. package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
  31. package/dist/lib/ora.d.ts +1 -0
  32. package/dist/lib/remoteConfig.d.ts +1 -1
  33. package/dist/lib/remoteConfig.js +4 -0
  34. package/dist/options/ConfigOptions.d.ts +1 -0
  35. package/dist/options/cliArgs.d.ts +3 -2
  36. package/dist/options/cliArgs.js +21 -6
  37. package/dist/options/config/config.d.ts +1 -0
  38. package/dist/options/config/readConfigFile.d.ts +1 -0
  39. package/dist/options/options.d.ts +5 -2
  40. package/dist/options/options.js +3 -3
  41. package/dist/options/options.test.js +7 -4
  42. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/date-filters.private.test.d.ts} +0 -0
  43. package/dist/test/e2e/cli/date-filters.private.test.js +48 -0
  44. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +120 -4
  45. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +4 -18
  46. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -1
  47. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  48. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  49. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  50. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  51. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +1 -0
  52. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  54. package/dist/utils/packageVersion.d.ts +1 -1
  55. package/dist/utils/packageVersion.js +1 -1
  56. package/package.json +20 -21
  57. package/yarn.lock +210 -220
  58. package/dist/entrypoint.cli.private.test.js +0 -47
  59. package/dist/errors/BackportError.d.ts +0 -19
  60. package/dist/errors/BackportError.js +0 -29
  61. package/dist/runSequentially.test.d.ts +0 -1
  62. package/dist/runSequentially.test.js +0 -243
  63. package/dist/services/BackportError.d.ts +0 -19
  64. package/dist/services/BackportError.js +0 -29
  65. package/dist/services/HandledBackportError.d.ts +0 -19
  66. package/dist/services/HandledBackportError.js +0 -29
  67. package/dist/services/HandledError.d.ts +0 -19
  68. package/dist/services/HandledError.js +0 -29
  69. package/dist/services/child-process-promisified.d.ts +0 -25
  70. package/dist/services/child-process-promisified.js +0 -58
  71. package/dist/services/env.d.ts +0 -7
  72. package/dist/services/env.js +0 -30
  73. package/dist/services/env.test.d.ts +0 -1
  74. package/dist/services/env.test.js +0 -21
  75. package/dist/services/git.d.ts +0 -77
  76. package/dist/services/git.integration.test.d.ts +0 -1
  77. package/dist/services/git.integration.test.js +0 -616
  78. package/dist/services/git.js +0 -439
  79. package/dist/services/git.private.test.d.ts +0 -1
  80. package/dist/services/git.private.test.js +0 -618
  81. package/dist/services/git.test.d.ts +0 -1
  82. package/dist/services/git.test.js +0 -580
  83. package/dist/services/github/commitFormatters.d.ts +0 -3
  84. package/dist/services/github/commitFormatters.js +0 -17
  85. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  86. package/dist/services/github/commitFormatters.test.js +0 -11
  87. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  88. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  89. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  90. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  91. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  92. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  93. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  94. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  95. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  96. package/dist/services/github/v3/createPullRequest.js +0 -91
  97. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  98. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  99. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  100. package/dist/services/github/v3/createStatusComment.js +0 -131
  101. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  102. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  103. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  104. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  105. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  106. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  107. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  108. package/dist/services/github/v4/apiRequestV4.js +0 -71
  109. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  110. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  111. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  112. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  113. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  114. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  115. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  116. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  117. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  118. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  119. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  120. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  121. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  122. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  123. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  124. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  125. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  126. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  127. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  128. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  129. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  130. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  131. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  132. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  133. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  134. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  135. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  136. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  137. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  138. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  139. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  140. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  141. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  142. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  143. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  144. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  145. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  146. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  147. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  148. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  149. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  150. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  151. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  152. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  153. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  154. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  155. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  156. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  157. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  158. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  159. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  160. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  161. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  162. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  163. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  164. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  165. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  166. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  167. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  168. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  169. package/dist/services/logger.d.ts +0 -9
  170. package/dist/services/logger.js +0 -74
  171. package/dist/services/prompt.test.d.ts +0 -1
  172. package/dist/services/prompt.test.js +0 -139
  173. package/dist/services/prompts.d.ts +0 -17
  174. package/dist/services/prompts.js +0 -132
  175. package/dist/services/remoteConfig.d.ts +0 -20
  176. package/dist/services/remoteConfig.js +0 -52
  177. package/dist/services/sequentially.d.ts +0 -1
  178. package/dist/services/sequentially.js +0 -10
  179. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  180. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  181. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  182. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  183. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  184. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  185. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  186. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  187. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  188. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  189. package/dist/services/test.d.ts +0 -1
  190. package/dist/services/test.js +0 -23
  191. package/dist/state.d.ts +0 -0
  192. package/dist/state.js +0 -1
  193. package/dist/test/ExecError.d.ts +0 -16
  194. package/dist/test/ExecError.js +0 -15
  195. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  196. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  197. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  198. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  199. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  200. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  201. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  202. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  203. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  204. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  205. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  206. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  207. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  208. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  209. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  210. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  211. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  212. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  213. package/dist/ui/getCommits.d.ts +0 -2
  214. package/dist/ui/getCommits.js +0 -75
  215. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  216. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  217. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  218. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  219. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  220. package/dist/ui/getGitConfigAuthor.js +0 -15
  221. package/dist/ui/getTargetBranches.d.ts +0 -5
  222. package/dist/ui/getTargetBranches.js +0 -67
  223. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  224. package/dist/ui/getTargetBranches.test.js +0 -204
  225. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  226. package/dist/ui/maybeSetupRepo.js +0 -53
  227. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  228. package/dist/ui/maybeSetupRepo.test.js +0 -238
  229. package/dist/ui/ora.d.ts +0 -2
  230. package/dist/ui/ora.js +0 -21
  231. package/dist/ui/setupRepo.d.ts +0 -2
  232. package/dist/ui/setupRepo.js +0 -56
  233. package/dist/ui/setupRepo.test.d.ts +0 -1
  234. package/dist/ui/setupRepo.test.js +0 -273
  235. package/dist/utils/filterMissingCommits.d.ts +0 -2
  236. package/dist/utils/filterMissingCommits.js +0 -7
  237. package/dist/utils/redact.d.ts +0 -1
  238. package/dist/utils/redact.js +0 -7
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommentBody = exports.createStatusComment = void 0;
4
- const rest_1 = require("@octokit/rest");
5
- const packageVersion_1 = require("../../../utils/packageVersion");
6
- const redact_1 = require("../../../utils/redact");
7
- const BackportError_1 = require("../../BackportError");
8
- const logger_1 = require("../../logger");
9
- const commitFormatters_1 = require("../commitFormatters");
10
- async function createStatusComment({ options, backportResponse, }) {
11
- const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
12
- if (!publishStatusComment || options.dryRun) {
13
- return;
14
- }
15
- try {
16
- const octokit = new rest_1.Octokit({
17
- auth: accessToken,
18
- baseUrl: githubApiBaseUrlV3,
19
- log: logger_1.logger,
20
- });
21
- await Promise.all(backportResponse.commits.map((commit) => {
22
- if (!commit.sourcePullRequest) {
23
- return;
24
- }
25
- const body = getCommentBody({
26
- options,
27
- pullNumber: commit.sourcePullRequest.number,
28
- backportResponse,
29
- });
30
- // only post comment if there is a body
31
- if (!body) {
32
- return;
33
- }
34
- return octokit.issues.createComment({
35
- baseUrl: githubApiBaseUrlV3,
36
- owner: repoOwner,
37
- repo: repoName,
38
- issue_number: commit.sourcePullRequest.number,
39
- body: (0, redact_1.redact)(options.accessToken, body),
40
- });
41
- }));
42
- }
43
- catch (e) {
44
- logger_1.logger.info(`Could not create status comment `, e);
45
- }
46
- }
47
- exports.createStatusComment = createStatusComment;
48
- function getCommentBody({ options, pullNumber, backportResponse, }) {
49
- const { repoName, repoOwner, autoMerge } = options;
50
- // custom handling when running backport locally (as opposed to on CI)
51
- if (!options.ci) {
52
- // only post successful backports when not running in CI
53
- if (backportResponse.status !== 'success') {
54
- return;
55
- }
56
- // only post a comment if all backports succeeded
57
- const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
58
- if (!didAllBackportsSucceed) {
59
- return;
60
- }
61
- }
62
- const packageVersionSection = `\n<!--- Backport version: ${packageVersion_1.PACKAGE_VERSION} -->`;
63
- const manualBackportCommand = `\n### Manual backport\nTo create the backport manually run:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\`\n`;
64
- const questionsAndLinkToBackport = '\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)\n';
65
- if (backportResponse.status === 'aborted' &&
66
- backportResponse.error.errorContext.code === 'no-branches-exception') {
67
- return `## ⚪ Backport skipped
68
- The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
69
- ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
70
- }
71
- if (backportResponse.status !== 'success') {
72
- return `## 💔 Backport failed
73
- The pull request could not be backported due to the following error:
74
- \`${backportResponse.error.message}\`
75
- ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
76
- }
77
- const tableBody = backportResponse.results
78
- .filter((result) => {
79
- // only post status updates for successful backports when running manually (non-ci)
80
- return options.ci || result.status === 'success';
81
- })
82
- .map((result) => {
83
- if (result.status === 'success') {
84
- return [
85
- '✅',
86
- result.targetBranch,
87
- `[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
88
- ];
89
- }
90
- if (result.error instanceof BackportError_1.BackportError &&
91
- result.error.errorContext.code === 'merge-conflict-exception') {
92
- const unmergedBackports = result.error.errorContext.commitsWithoutBackports.map((c) => {
93
- return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.sourceCommit.message)}](${c.commit.sourcePullRequest?.url})`;
94
- });
95
- const unmergedBackportsSection = unmergedBackports.length > 0
96
- ? `<br><br>You might need to backport the following PRs to ${result.targetBranch}:<br>${unmergedBackports.join('<br>')}`
97
- : '';
98
- return [
99
- '❌',
100
- result.targetBranch,
101
- `**Backport failed because of merge conflicts**${unmergedBackportsSection}`,
102
- ];
103
- }
104
- return ['❌', result.targetBranch, result.error.message];
105
- })
106
- .map((line) => line.join('|'))
107
- .join('|\n|');
108
- const table = backportResponse.results.length
109
- ? `\n\n| Status | Branch | Result |\n|:------:|:------:|:------|\n|${tableBody}|\n`
110
- : '';
111
- const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
112
- const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
113
- let header = '';
114
- if (didAllBackportsSucceed) {
115
- header = '## 💚 All backports created successfully';
116
- }
117
- else if (didAnyBackportsSucceed) {
118
- header = '## 💔 Some backports could not be created';
119
- }
120
- else {
121
- header = '## 💔 All backports failed';
122
- }
123
- const autoMergeMessage = autoMerge && didAnyBackportsSucceed
124
- ? '\nNote: Successful backport PRs will be merged automatically after passing CI.\n'
125
- : '';
126
- const backportPRCommandMessage = !didAllBackportsSucceed
127
- ? `${manualBackportCommand}`
128
- : '';
129
- return `${header}${table}${autoMergeMessage}${backportPRCommandMessage}${questionsAndLinkToBackport}${packageVersionSection}`;
130
- }
131
- exports.getCommentBody = getCommentBody;
@@ -1 +0,0 @@
1
- export {};
@@ -1,409 +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 BackportError_1 = require("../../BackportError");
8
- const createStatusComment_1 = require("./createStatusComment");
9
- describe('createStatusComment', () => {
10
- it('redacts accessToken if it is included in the error message', async () => {
11
- const accessToken = 'ghp_abcdefg';
12
- const scope = (0, nock_1.default)('https://api.github.com')
13
- .post('/repos/elastic/kibana/issues/100/comments')
14
- .reply(200, 'some response');
15
- let postedCommentBody = '';
16
- scope.on('request', (req, interceptor, body) => {
17
- postedCommentBody = JSON.parse(body).body;
18
- });
19
- await (0, createStatusComment_1.createStatusComment)({
20
- options: {
21
- repoName: 'kibana',
22
- repoOwner: 'elastic',
23
- accessToken,
24
- backportBinary: 'node scripts/backport',
25
- publishStatusComment: true,
26
- githubApiBaseUrlV3: 'https://api.github.com',
27
- ci: true,
28
- },
29
- backportResponse: {
30
- commits: [{ sourcePullRequest: { number: 100 } }],
31
- status: 'failure',
32
- error: new Error(`Error message containing very secret access token: ${accessToken}.`),
33
- },
34
- });
35
- expect(postedCommentBody).toContain('Error message containing very secret access token: <REDACTED>');
36
- scope.done();
37
- nock_1.default.cleanAll();
38
- });
39
- });
40
- describe('getCommentBody', () => {
41
- describe('when an unknown error occurs', () => {
42
- const getParams = (opts) => ({
43
- options: {
44
- backportBinary: 'node scripts/backport',
45
- ...opts,
46
- },
47
- pullNumber: 55,
48
- backportResponse: {
49
- status: 'failure',
50
- error: new Error('A terrible error occured'),
51
- },
52
- });
53
- it('posts a comment when running on ci', () => {
54
- const params = getParams({ ci: true });
55
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
56
- "## 💔 Backport failed
57
- The pull request could not be backported due to the following error:
58
- \`A terrible error occured\`
59
-
60
- ### Manual backport
61
- To create the backport manually run:
62
- \`\`\`
63
- node scripts/backport --pr 55
64
- \`\`\`
65
-
66
- ### Questions ?
67
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
68
-
69
- <!--- Backport version: 1.2.3-mocked -->"
70
- `);
71
- });
72
- it('does not post a comment when running manually', () => {
73
- const params = getParams({ ci: false });
74
- expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
75
- });
76
- });
77
- describe('when all backports succeed', () => {
78
- const getParams = (opts) => ({
79
- options: {
80
- repoName: 'kibana',
81
- repoOwner: 'elastic',
82
- autoMerge: true,
83
- ...opts,
84
- },
85
- pullNumber: 55,
86
- backportResponse: {
87
- status: 'success',
88
- results: [
89
- {
90
- status: 'success',
91
- targetBranch: '7.x',
92
- pullRequestNumber: 55,
93
- pullRequestUrl: 'url-to-pr',
94
- },
95
- {
96
- status: 'success',
97
- targetBranch: '7.1',
98
- pullRequestNumber: 66,
99
- pullRequestUrl: 'url-to-pr',
100
- },
101
- ],
102
- },
103
- });
104
- it('posts a comment on ci', () => {
105
- const params = getParams({ ci: true });
106
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
107
- "## 💚 All backports created successfully
108
-
109
- | Status | Branch | Result |
110
- |:------:|:------:|:------|
111
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
112
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
113
-
114
- Note: Successful backport PRs will be merged automatically after passing CI.
115
-
116
- ### Questions ?
117
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
118
-
119
- <!--- Backport version: 1.2.3-mocked -->"
120
- `);
121
- });
122
- it('posts a comment when running locally', () => {
123
- const params = getParams({ ci: false });
124
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
125
- "## 💚 All backports created successfully
126
-
127
- | Status | Branch | Result |
128
- |:------:|:------:|:------|
129
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
130
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
131
-
132
- Note: Successful backport PRs will be merged automatically after passing CI.
133
-
134
- ### Questions ?
135
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
136
-
137
- <!--- Backport version: 1.2.3-mocked -->"
138
- `);
139
- });
140
- });
141
- describe('when all backports fail', () => {
142
- const getParams = (opts) => ({
143
- options: {
144
- repoName: 'kibana',
145
- repoOwner: 'elastic',
146
- autoMerge: true,
147
- backportBinary: 'node scripts/backport',
148
- ...opts,
149
- },
150
- pullNumber: 55,
151
- backportResponse: {
152
- status: 'success',
153
- results: [
154
- {
155
- status: 'unhandled-error',
156
- targetBranch: '7.x',
157
- error: new Error('My boom error!'),
158
- },
159
- {
160
- status: 'unhandled-error',
161
- targetBranch: '7.1',
162
- error: new Error('My boom error!'),
163
- },
164
- ],
165
- },
166
- });
167
- it('posts a comment on CI', () => {
168
- const params = getParams({ ci: true });
169
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
170
- "## 💔 All backports failed
171
-
172
- | Status | Branch | Result |
173
- |:------:|:------:|:------|
174
- |❌|7.x|My boom error!|
175
- |❌|7.1|My boom error!|
176
-
177
- ### Manual backport
178
- To create the backport manually run:
179
- \`\`\`
180
- node scripts/backport --pr 55
181
- \`\`\`
182
-
183
- ### Questions ?
184
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
185
-
186
- <!--- Backport version: 1.2.3-mocked -->"
187
- `);
188
- });
189
- it('does not post a comment when running manaully', () => {
190
- const params = getParams({ ci: false });
191
- expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
192
- });
193
- });
194
- describe('when some backports fail', () => {
195
- const getParams = (opts) => ({
196
- options: {
197
- repoName: 'kibana',
198
- repoOwner: 'elastic',
199
- autoMerge: true,
200
- backportBinary: 'node scripts/backport',
201
- ...opts,
202
- },
203
- pullNumber: 55,
204
- backportResponse: {
205
- status: 'success',
206
- results: [
207
- {
208
- status: 'success',
209
- targetBranch: '7.x',
210
- pullRequestNumber: 55,
211
- pullRequestUrl: 'url-to-pr-55',
212
- },
213
- {
214
- status: 'failure',
215
- targetBranch: '7.1',
216
- error: new Error('My boom error!'),
217
- },
218
- ],
219
- },
220
- });
221
- it('post a comment when running on CI', () => {
222
- const params = getParams({ ci: true });
223
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
224
- "## 💔 Some backports could not be created
225
-
226
- | Status | Branch | Result |
227
- |:------:|:------:|:------|
228
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
229
- |❌|7.1|My boom error!|
230
-
231
- Note: Successful backport PRs will be merged automatically after passing CI.
232
-
233
- ### Manual backport
234
- To create the backport manually run:
235
- \`\`\`
236
- node scripts/backport --pr 55
237
- \`\`\`
238
-
239
- ### Questions ?
240
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
241
-
242
- <!--- Backport version: 1.2.3-mocked -->"
243
- `);
244
- });
245
- it('does not post a comment when running manually because some backports failed', () => {
246
- const params = getParams({ ci: false });
247
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
248
- });
249
- });
250
- describe('when some backports fail due to conflicts', () => {
251
- const getParams = (opts) => ({
252
- options: {
253
- repoName: 'kibana',
254
- repoOwner: 'elastic',
255
- autoMerge: true,
256
- backportBinary: 'node scripts/backport',
257
- ...opts,
258
- },
259
- pullNumber: 55,
260
- backportResponse: {
261
- status: 'success',
262
- results: [
263
- {
264
- status: 'success',
265
- targetBranch: '7.x',
266
- pullRequestNumber: 55,
267
- pullRequestUrl: 'url-to-pr-55',
268
- },
269
- {
270
- status: 'failure',
271
- targetBranch: '7.1',
272
- error: new BackportError_1.BackportError({
273
- code: 'merge-conflict-exception',
274
- conflictingFiles: ['readme.md'],
275
- commitsWithoutBackports: [
276
- {
277
- formatted: 'some-formatted-text',
278
- commit: {
279
- author: {
280
- email: 'soren.louv@elastic.co',
281
- name: 'Søren Louv-Jansen',
282
- },
283
- sourceBranch: 'master',
284
- sourcePullRequest: {
285
- number: 5,
286
- url: 'url-to-pr-5',
287
- mergeCommit: {
288
- sha: '',
289
- message: 'New Zealand commit message',
290
- },
291
- },
292
- sourceCommit: {
293
- committedDate: '',
294
- sha: '',
295
- message: 'New Zealand commit message',
296
- },
297
- expectedTargetPullRequests: [],
298
- },
299
- },
300
- {
301
- formatted: 'some-formatted-text',
302
- commit: {
303
- author: {
304
- email: 'soren.louv@elastic.co',
305
- name: 'Søren Louv-Jansen',
306
- },
307
- sourceBranch: 'master',
308
- sourcePullRequest: {
309
- number: 44,
310
- url: 'url-to-pr-44',
311
- mergeCommit: {
312
- sha: '',
313
- message: 'Australia commit',
314
- },
315
- },
316
- sourceCommit: {
317
- committedDate: '',
318
- sha: '',
319
- message: 'Australia commit',
320
- },
321
- expectedTargetPullRequests: [],
322
- },
323
- },
324
- ],
325
- }),
326
- },
327
- {
328
- status: 'failure',
329
- targetBranch: '7.2',
330
- error: new BackportError_1.BackportError({
331
- code: 'merge-conflict-exception',
332
- conflictingFiles: ['my-file.txt'],
333
- commitsWithoutBackports: [],
334
- }),
335
- },
336
- ],
337
- },
338
- });
339
- it('posts a comment when running on CI', () => {
340
- const params = getParams({ ci: true });
341
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
342
- "## 💔 Some backports could not be created
343
-
344
- | Status | Branch | Result |
345
- |:------:|:------:|:------|
346
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
347
- |❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
348
- |❌|7.2|**Backport failed because of merge conflicts**|
349
-
350
- Note: Successful backport PRs will be merged automatically after passing CI.
351
-
352
- ### Manual backport
353
- To create the backport manually run:
354
- \`\`\`
355
- node scripts/backport --pr 55
356
- \`\`\`
357
-
358
- ### Questions ?
359
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
360
-
361
- <!--- Backport version: 1.2.3-mocked -->"
362
- `);
363
- });
364
- it('does not post a comment when running manually because some backports failed', () => {
365
- const params = getParams({ ci: false });
366
- expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
367
- });
368
- });
369
- describe('when all backports fail due to missing branches', () => {
370
- const getParams = (opts) => ({
371
- options: {
372
- repoName: 'kibana',
373
- repoOwner: 'elastic',
374
- autoMerge: true,
375
- backportBinary: 'node scripts/backport',
376
- ...opts,
377
- },
378
- pullNumber: 55,
379
- backportResponse: {
380
- status: 'aborted',
381
- commits: [],
382
- error: new BackportError_1.BackportError({ code: 'no-branches-exception' }),
383
- errorMessage: 'my message',
384
- },
385
- });
386
- it('posts a comment when running on CI', () => {
387
- const params = getParams({ ci: true });
388
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
389
- "## ⚪ Backport skipped
390
- The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
391
-
392
- ### Manual backport
393
- To create the backport manually run:
394
- \`\`\`
395
- node scripts/backport --pr 55
396
- \`\`\`
397
-
398
- ### Questions ?
399
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
400
-
401
- <!--- Backport version: 1.2.3-mocked -->"
402
- `);
403
- });
404
- it('does not post a comment when running manually', () => {
405
- const params = getParams({ ci: false });
406
- expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
407
- });
408
- });
409
- });
@@ -1,14 +0,0 @@
1
- declare type GithubV3Error = {
2
- name: string;
3
- status: number;
4
- documentation_url: string;
5
- message?: string;
6
- errors?: Array<{
7
- resource: string;
8
- code: string;
9
- field: string;
10
- message?: string;
11
- }>;
12
- };
13
- export declare function getGithubV3ErrorMessage(e: GithubV3Error): string | undefined;
14
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGithubV3ErrorMessage = void 0;
4
- function getGithubV3ErrorMessage(e) {
5
- if (!e.errors) {
6
- return e.message;
7
- }
8
- const errorMessages = e.errors.map((error) => {
9
- if (error.message) {
10
- return error.message;
11
- }
12
- return JSON.stringify(error);
13
- });
14
- return `${errorMessages.join(', ')} (Github v3)`;
15
- }
16
- exports.getGithubV3ErrorMessage = getGithubV3ErrorMessage;
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- export declare function fetchPullRequestId(options: ValidConfigOptions, pullNumber: number): Promise<string>;
@@ -1,36 +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
- exports.fetchPullRequestId = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const apiRequestV4_1 = require("./apiRequestV4");
9
- async function fetchPullRequestId(options, pullNumber) {
10
- const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
11
- const prQuery = (0, graphql_tag_1.default) `
12
- query PullRequestId(
13
- $repoOwner: String!
14
- $repoName: String!
15
- $pullNumber: Int!
16
- ) {
17
- repository(owner: $repoOwner, name: $repoName) {
18
- pullRequest(number: $pullNumber) {
19
- id
20
- }
21
- }
22
- }
23
- `;
24
- const prResponse = await (0, apiRequestV4_1.apiRequestV4)({
25
- githubApiBaseUrlV4,
26
- accessToken,
27
- query: prQuery,
28
- variables: {
29
- repoOwner,
30
- repoName,
31
- pullNumber,
32
- },
33
- });
34
- return prResponse.repository.pullRequest.id;
35
- }
36
- exports.fetchPullRequestId = fetchPullRequestId;
@@ -1,31 +0,0 @@
1
- import { AxiosResponse } from 'axios';
2
- import { DocumentNode } from 'graphql';
3
- interface GithubError {
4
- type?: string;
5
- path?: string[];
6
- locations?: {
7
- line: number;
8
- column: number;
9
- }[];
10
- message: string;
11
- }
12
- export interface GithubV4Response<DataResponse> {
13
- data: DataResponse;
14
- errors?: GithubError[];
15
- }
16
- declare type Variables = Record<string, string | number | null>;
17
- export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, }: {
18
- githubApiBaseUrlV4?: string;
19
- accessToken: string;
20
- query: DocumentNode;
21
- variables?: Variables;
22
- }): Promise<DataResponse>;
23
- declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
24
- export declare class GithubV4Exception<DataResponse> extends Error {
25
- githubResponse: AxiosGithubResponse<DataResponse> & {
26
- request: undefined;
27
- };
28
- constructor(githubResponse: AxiosGithubResponse<DataResponse>, errorMessage?: string);
29
- }
30
- export declare function getQueryName(query: DocumentNode): string;
31
- export {};