backport 6.1.5 → 6.3.0-beta-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 (249) hide show
  1. package/README.md +15 -6
  2. package/dist/{main.d.ts → backportRun.d.ts} +3 -3
  3. package/dist/{main.js → backportRun.js} +21 -10
  4. package/dist/{entrypoint.module.private.test.d.ts → entrypoint.cli.e2e.private.test.d.ts} +0 -0
  5. package/dist/entrypoint.cli.e2e.private.test.js +277 -0
  6. package/dist/entrypoint.cli.js +3 -5
  7. package/dist/{options/getValidatedOptions.test.d.ts → entrypoint.cli.private.test.d.ts} +0 -0
  8. package/dist/{entrypoint.module.private.test.js → entrypoint.cli.private.test.js} +17 -8
  9. package/dist/entrypoint.module.d.ts +2 -2
  10. package/dist/entrypoint.module.js +4 -4
  11. package/dist/options/ConfigOptions.d.ts +5 -1
  12. package/dist/options/cliArgs.d.ts +16 -14
  13. package/dist/options/cliArgs.js +15 -5
  14. package/dist/options/cliArgs.test.js +28 -10
  15. package/dist/options/config/config.d.ts +10 -4
  16. package/dist/options/config/config.js +7 -6
  17. package/dist/options/config/config.test.js +11 -1
  18. package/dist/options/config/globalConfig.d.ts +1 -1
  19. package/dist/options/config/globalConfig.js +15 -9
  20. package/dist/options/config/globalConfig.test.js +19 -32
  21. package/dist/options/config/projectConfig.d.ts +3 -1
  22. package/dist/options/config/projectConfig.js +5 -2
  23. package/dist/options/config/projectConfig.test.js +41 -31
  24. package/dist/options/config/readConfigFile.d.ts +27 -23
  25. package/dist/options/config/readConfigFile.js +2 -2
  26. package/dist/options/options.d.ts +18 -39
  27. package/dist/options/options.js +40 -32
  28. package/dist/options/options.test.js +83 -47
  29. package/dist/runSequentially.d.ts +0 -1
  30. package/dist/runSequentially.js +0 -1
  31. package/dist/runSequentially.test.js +39 -20
  32. package/dist/scripts/postinstall.js +3 -3
  33. package/dist/services/HandledError.d.ts +6 -4
  34. package/dist/services/HandledError.js +18 -3
  35. package/dist/services/child-process-promisified.d.ts +3 -1
  36. package/dist/services/env.d.ts +3 -1
  37. package/dist/services/env.js +4 -1
  38. package/dist/services/env.test.js +2 -2
  39. package/dist/services/git.d.ts +22 -9
  40. package/dist/services/git.integration.test.js +123 -24
  41. package/dist/services/git.js +66 -54
  42. package/dist/services/git.test.js +35 -20
  43. package/dist/services/github/commitFormatters.d.ts +0 -1
  44. package/dist/services/github/commitFormatters.js +1 -8
  45. package/dist/services/github/v3/createPullRequest.js +16 -10
  46. package/dist/services/github/v3/createPullRequest.test.js +248 -33
  47. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  48. package/dist/services/github/v3/createStatusComment.js +26 -15
  49. package/dist/services/github/v3/createStatusComment.test.js +165 -70
  50. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +2 -1
  51. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -7
  52. package/dist/services/github/v4/apiRequestV4.d.ts +21 -17
  53. package/dist/services/github/v4/apiRequestV4.js +38 -28
  54. package/dist/services/github/v4/apiRequestV4.test.js +4 -4
  55. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -7
  56. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -7
  57. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +37 -19
  58. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +17 -8
  59. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -3
  60. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +23 -14
  61. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  62. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +4 -4
  63. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +41 -19
  64. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +1 -8
  65. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +31 -14
  66. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -4
  67. package/dist/services/github/v4/fetchExistingPullRequest.js +1 -2
  68. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -9
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +6 -2
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +41 -34
  71. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -0
  72. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +2 -1
  73. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  74. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +56 -0
  75. package/dist/{options/parseRequiredOptions.test.d.ts → services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts} +0 -0
  76. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  77. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +11 -11
  78. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +4 -5
  79. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -7
  80. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
  81. package/dist/services/logger.d.ts +9 -3
  82. package/dist/services/logger.js +38 -35
  83. package/dist/services/prompt.test.js +66 -19
  84. package/dist/services/prompts.js +12 -10
  85. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +1 -1
  86. package/dist/services/sourceCommit/getMockSourceCommit.js +6 -6
  87. package/dist/services/sourceCommit/parseSourceCommit.d.ts +18 -10
  88. package/dist/services/sourceCommit/parseSourceCommit.js +20 -14
  89. package/dist/services/sourceCommit/parseSourceCommit.test.js +18 -20
  90. package/dist/{runWithOptions.test.d.ts → test/backport-e2e.mutation.test.d.ts} +0 -0
  91. package/dist/test/{integration/integration.private.test.js → backport-e2e.mutation.test.js} +143 -123
  92. package/dist/{scripts/generate-gql.d.ts → test/handleUnbackportedPullRequests.private.test.d.ts} +0 -0
  93. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
  94. package/dist/test/mockConfigFiles.js +4 -20
  95. package/dist/test/mocks.d.ts +10 -0
  96. package/dist/test/mocks.js +23 -0
  97. package/dist/test/private/getDevAccessToken.js +5 -4
  98. package/dist/test/sandbox.d.ts +5 -0
  99. package/dist/test/sandbox.js +43 -0
  100. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  101. package/dist/test/setupFiles/automatic-mocks.js +27 -11
  102. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -1
  103. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -13
  104. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +50 -27
  105. package/dist/ui/getCommits.js +8 -14
  106. package/dist/ui/getCommitsWithoutBackports.js +6 -6
  107. package/dist/ui/getCommitsWithoutBackports.test.js +91 -39
  108. package/dist/ui/getTargetBranches.js +1 -1
  109. package/dist/ui/getTargetBranches.test.js +26 -8
  110. package/dist/ui/maybeSetupRepo.js +25 -5
  111. package/dist/ui/maybeSetupRepo.test.js +144 -14
  112. package/dist/utils/maybe.d.ts +1 -0
  113. package/dist/utils/maybe.js +7 -0
  114. package/dist/utils/packageVersion.d.ts +1 -0
  115. package/dist/{types/PromiseReturnType.js → utils/packageVersion.js} +2 -0
  116. package/package.json +24 -20
  117. package/yarn.lock +160 -237
  118. package/dist/index.d.ts +0 -783
  119. package/dist/index.js +0 -8001
  120. package/dist/ink.d.ts +0 -1
  121. package/dist/ink.js +0 -49
  122. package/dist/options/config/getOptionsFromGit.d.ts +0 -4
  123. package/dist/options/config/getOptionsFromGit.js +0 -8
  124. package/dist/options/getValidatedOptions.d.ts +0 -49
  125. package/dist/options/getValidatedOptions.js +0 -45
  126. package/dist/options/getValidatedOptions.test.js +0 -97
  127. package/dist/options/parseRequiredOptions.d.ts +0 -71
  128. package/dist/options/parseRequiredOptions.js +0 -68
  129. package/dist/options/parseRequiredOptions.test.js +0 -122
  130. package/dist/runWithOptions.d.ts +0 -9
  131. package/dist/runWithOptions.js +0 -43
  132. package/dist/runWithOptions.test.js +0 -304
  133. package/dist/scripts/generate-gql.js +0 -15
  134. package/dist/services/fs-promisified.d.ts +0 -6
  135. package/dist/services/fs-promisified.js +0 -12
  136. package/dist/services/getExpectedTarget.d.ts +0 -9
  137. package/dist/services/getExpectedTarget.js +0 -77
  138. package/dist/services/getExpectedTargetPullRequests.d.ts +0 -9
  139. package/dist/services/getExpectedTargetPullRequests.js +0 -77
  140. package/dist/services/github/v4/fetchCommitByPullNumber.d.ts +0 -5
  141. package/dist/services/github/v4/fetchCommitByPullNumber.js +0 -86
  142. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.d.ts +0 -1
  143. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +0 -57
  144. package/dist/services/github/v4/fetchCommitBySha.d.ts +0 -5
  145. package/dist/services/github/v4/fetchCommitBySha.js +0 -95
  146. package/dist/services/github/v4/fetchCommitBySha.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/fetchCommitBySha.private.test.js +0 -50
  148. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +0 -28
  149. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +0 -52
  150. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +0 -3
  151. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +0 -55
  152. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +0 -1
  153. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +0 -252
  154. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +0 -28
  155. package/dist/services/github/v4/fetchCommitsByAuthor.js +0 -161
  156. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.d.ts +0 -1
  157. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +0 -115
  158. package/dist/services/github/v4/fetchCommitsByAuthor.test.d.ts +0 -1
  159. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +0 -272
  160. package/dist/services/github/v4/fetchDefaultBranch.d.ts +0 -9
  161. package/dist/services/github/v4/fetchDefaultBranch.js +0 -24
  162. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -4
  163. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -52
  164. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
  165. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
  166. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +0 -4
  167. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +0 -72
  168. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +0 -1
  169. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +0 -34
  170. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +0 -40
  171. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +0 -72
  172. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -17
  173. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -69
  174. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
  175. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
  176. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +0 -37
  177. package/dist/services/github/v4/fetchMergedPullRequests.js +0 -37
  178. package/dist/services/github/v4/fetchMergedPullRequests.private.test.d.ts +0 -1
  179. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +0 -59
  180. package/dist/services/github/v4/fetchMergedPullRequests.test.d.ts +0 -1
  181. package/dist/services/github/v4/fetchMergedPullRequests.test.js +0 -22
  182. package/dist/services/github/v4/fetchProjectConfig.d.ts +0 -8
  183. package/dist/services/github/v4/fetchProjectConfig.js +0 -56
  184. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +0 -1
  185. package/dist/services/github/v4/fetchProjectConfig.private.test.js +0 -52
  186. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +0 -1
  187. package/dist/services/github/v4/fetchProjectConfig.test.js +0 -37
  188. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +0 -9
  189. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +0 -92
  190. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  191. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +0 -66
  192. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.d.ts +0 -1
  193. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +0 -242
  194. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +0 -7
  195. package/dist/services/github/v4/getExistingTargetPullRequests.js +0 -45
  196. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +0 -63
  197. package/dist/services/github/v4/getOptionsFromGithub/index.js +0 -139
  198. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +0 -1
  199. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +0 -147
  200. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -5
  201. package/dist/services/github/v4/getTargetBranchesFromLabels.js +0 -20
  202. package/dist/services/github/v4/getTargetBranchesFromLabels.test.d.ts +0 -1
  203. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +0 -201
  204. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +0 -2
  205. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +0 -843
  206. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +0 -2
  207. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +0 -73
  208. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +0 -12
  209. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +0 -44
  210. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +0 -5
  211. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +0 -20
  212. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +0 -1
  213. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +0 -201
  214. package/dist/services/sourceCommit/sourceCommit.d.ts +0 -78
  215. package/dist/services/sourceCommit/sourceCommit.js +0 -86
  216. package/dist/services/sourceCommit/sourceCommit.test.d.ts +0 -1
  217. package/dist/services/sourceCommit/sourceCommit.test.js +0 -287
  218. package/dist/services/sourceCommit.d.ts +0 -78
  219. package/dist/services/sourceCommit.js +0 -86
  220. package/dist/services/sourceCommit.test.d.ts +0 -1
  221. package/dist/services/sourceCommit.test.js +0 -280
  222. package/dist/test/inquirer.private.test.d.ts +0 -1
  223. package/dist/test/inquirer.private.test.js +0 -168
  224. package/dist/test/integration/createSpies.d.ts +0 -17
  225. package/dist/test/integration/createSpies.js +0 -85
  226. package/dist/test/integration/envConstants.d.ts +0 -5
  227. package/dist/test/integration/envConstants.js +0 -9
  228. package/dist/test/integration/helpers.d.ts +0 -7
  229. package/dist/test/integration/helpers.js +0 -31
  230. package/dist/test/integration/integration.private.test.d.ts +0 -1
  231. package/dist/test/integration/integration.test.d.ts +0 -1
  232. package/dist/test/integration/integration.test.js +0 -214
  233. package/dist/todo-delete.d.ts +0 -1
  234. package/dist/todo-delete.js +0 -17
  235. package/dist/types/Commit.d.ts +0 -85
  236. package/dist/types/Commit.js +0 -139
  237. package/dist/types/PromiseReturnType.d.ts +0 -1
  238. package/dist/types/commitNode.d.ts +0 -89
  239. package/dist/types/commitNode.js +0 -139
  240. package/dist/types/commitNode.test.d.ts +0 -1
  241. package/dist/types/commitNode.test.js +0 -255
  242. package/dist/types/commitWithAssociatedPullRequests.d.ts +0 -86
  243. package/dist/types/commitWithAssociatedPullRequests.js +0 -145
  244. package/dist/ui/cherrypickAndCreatePullRequest.test.d.ts +0 -1
  245. package/dist/ui/cherrypickAndCreatePullRequest.test.js +0 -617
  246. package/dist/ui/getTargetBranchesFromLabels.d.ts +0 -6
  247. package/dist/ui/getTargetBranchesFromLabels.js +0 -40
  248. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +0 -1
  249. package/dist/ui/getTargetBranchesFromLabels.test.js +0 -288
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const nock_1 = __importDefault(require("nock"));
3
7
  const HandledError_1 = require("../../HandledError");
4
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
+ });
5
40
  describe('getCommentBody', () => {
6
41
  describe('when an unknown error occurs', () => {
7
42
  const getParams = (opts) => ({
@@ -12,25 +47,26 @@ describe('getCommentBody', () => {
12
47
  pullNumber: 55,
13
48
  backportResponse: {
14
49
  status: 'failure',
15
- errorMessage: 'A terrible error occured',
50
+ error: new Error('A terrible error occured'),
16
51
  },
17
52
  });
18
53
  it('posts a comment when running on ci', () => {
19
54
  const params = getParams({ ci: true });
20
55
  expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
21
- "## 💔 Backport failed
22
- The pull request could not be backported due to the following error:
23
- \`A terrible error occured\`
56
+ "## 💔 Backport failed
57
+ The pull request could not be backported due to the following error:
58
+ \`A terrible error occured\`
24
59
 
25
- ### How to fix
26
- Re-run the backport manually:
27
- \`\`\`
28
- node scripts/backport --pr 55
29
- \`\`\`
60
+ ### Manual backport
61
+ To create the backport manually run:
62
+ \`\`\`
63
+ node scripts/backport --pr 55
64
+ \`\`\`
30
65
 
31
- ### Questions ?
32
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
33
- `);
66
+ ### Questions ?
67
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
68
+ <!--- Backport version: 1.2.3 -->"
69
+ `);
34
70
  });
35
71
  it('does not post a comment when running manually', () => {
36
72
  const params = getParams({ ci: false });
@@ -67,34 +103,36 @@ describe('getCommentBody', () => {
67
103
  it('posts a comment on ci', () => {
68
104
  const params = getParams({ ci: true });
69
105
  expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
70
- "## 💚 All backports created successfully
106
+ "## 💚 All backports created successfully
71
107
 
72
- | Status | Branch | Result |
73
- |:------:|:------:|:------|
74
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
75
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
108
+ | Status | Branch | Result |
109
+ |:------:|:------:|:------|
110
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
111
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
76
112
 
77
- Note: Successful backport PRs will be merged automatically after passing CI.
113
+ Note: Successful backport PRs will be merged automatically after passing CI.
78
114
 
79
- ### Questions ?
80
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
81
- `);
115
+ ### Questions ?
116
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
117
+ <!--- Backport version: 1.2.3 -->"
118
+ `);
82
119
  });
83
120
  it('posts a comment when running locally', () => {
84
121
  const params = getParams({ ci: false });
85
122
  expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
86
- "## 💚 All backports created successfully
123
+ "## 💚 All backports created successfully
87
124
 
88
- | Status | Branch | Result |
89
- |:------:|:------:|:------|
90
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
91
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
125
+ | Status | Branch | Result |
126
+ |:------:|:------:|:------|
127
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
128
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
92
129
 
93
- Note: Successful backport PRs will be merged automatically after passing CI.
130
+ Note: Successful backport PRs will be merged automatically after passing CI.
94
131
 
95
- ### Questions ?
96
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
97
- `);
132
+ ### Questions ?
133
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
134
+ <!--- Backport version: 1.2.3 -->"
135
+ `);
98
136
  });
99
137
  });
100
138
  describe('when all backports fail', () => {
@@ -113,14 +151,12 @@ describe('getCommentBody', () => {
113
151
  {
114
152
  status: 'failure',
115
153
  targetBranch: '7.x',
116
- error: new Error('Boom!'),
117
- errorMessage: 'My boom error!',
154
+ error: new Error('My boom error!'),
118
155
  },
119
156
  {
120
157
  status: 'failure',
121
158
  targetBranch: '7.1',
122
- error: new Error('Boom!'),
123
- errorMessage: 'My boom error!',
159
+ error: new Error('My boom error!'),
124
160
  },
125
161
  ],
126
162
  },
@@ -135,14 +171,15 @@ describe('getCommentBody', () => {
135
171
  |❌|7.x|My boom error!|
136
172
  |❌|7.1|My boom error!|
137
173
 
138
- ### How to fix
139
- Re-run the backport manually:
174
+ ### Manual backport
175
+ To create the backport manually run:
140
176
  \`\`\`
141
177
  node scripts/backport --pr 55
142
178
  \`\`\`
143
179
 
144
180
  ### Questions ?
145
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
181
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
182
+ <!--- Backport version: 1.2.3 -->"
146
183
  `);
147
184
  });
148
185
  it('does not post a comment when running manaully', () => {
@@ -172,8 +209,7 @@ describe('getCommentBody', () => {
172
209
  {
173
210
  status: 'failure',
174
211
  targetBranch: '7.1',
175
- error: new Error('Boom!'),
176
- errorMessage: 'My boom error!',
212
+ error: new Error('My boom error!'),
177
213
  },
178
214
  ],
179
215
  },
@@ -181,23 +217,24 @@ describe('getCommentBody', () => {
181
217
  it('post a comment when running on CI', () => {
182
218
  const params = getParams({ ci: true });
183
219
  expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
184
- "## 💔 Some backports could not be created
220
+ "## 💔 Some backports could not be created
185
221
 
186
- | Status | Branch | Result |
187
- |:------:|:------:|:------|
188
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
189
- |❌|7.1|My boom error!|
222
+ | Status | Branch | Result |
223
+ |:------:|:------:|:------|
224
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
225
+ |❌|7.1|My boom error!|
190
226
 
191
- ### How to fix
192
- Re-run the backport manually:
193
- \`\`\`
194
- node scripts/backport --pr 55
195
- \`\`\`
196
- Note: Successful backport PRs will be merged automatically after passing CI.
227
+ ### Manual backport
228
+ To create the backport manually run:
229
+ \`\`\`
230
+ node scripts/backport --pr 55
231
+ \`\`\`
232
+ Note: Successful backport PRs will be merged automatically after passing CI.
197
233
 
198
- ### Questions ?
199
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
200
- `);
234
+ ### Questions ?
235
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
236
+ <!--- Backport version: 1.2.3 -->"
237
+ `);
201
238
  });
202
239
  it('does not post a comment when running manually because some backports failed', () => {
203
240
  const params = getParams({ ci: false });
@@ -226,24 +263,45 @@ describe('getCommentBody', () => {
226
263
  {
227
264
  status: 'failure',
228
265
  targetBranch: '7.1',
229
- errorMessage: 'My boom error!',
230
- error: new HandledError_1.HandledError('Boom!', {
231
- type: 'merge-conflict-due-to-missing-backports',
266
+ error: new HandledError_1.HandledError({
267
+ code: 'merge-conflict-exception',
232
268
  commitsWithoutBackports: [
269
+ //@ts-expect-error
233
270
  {
234
- //@ts-expect-error
235
271
  commit: {
236
- pullNumber: 5,
237
- pullUrl: 'url-to-pr-5',
238
- originalMessage: 'New Zealand commit message',
272
+ sourceBranch: 'master',
273
+ sourcePullRequest: {
274
+ number: 5,
275
+ url: 'url-to-pr-5',
276
+ mergeCommit: {
277
+ sha: '',
278
+ message: 'New Zealand commit message',
279
+ },
280
+ },
281
+ sourceCommit: {
282
+ committedDate: '',
283
+ sha: '',
284
+ message: 'New Zealand commit message',
285
+ },
286
+ expectedTargetPullRequests: [],
239
287
  },
240
288
  },
241
289
  {
242
290
  //@ts-expect-error
243
291
  commit: {
244
- pullNumber: 44,
245
- pullUrl: 'url-to-pr-44',
246
- originalMessage: 'Australia commit',
292
+ sourcePullRequest: {
293
+ number: 44,
294
+ url: 'url-to-pr-44',
295
+ mergeCommit: {
296
+ sha: '',
297
+ message: 'Australia commit',
298
+ },
299
+ },
300
+ sourceCommit: {
301
+ committedDate: '',
302
+ sha: '',
303
+ message: 'Australia commit',
304
+ },
247
305
  },
248
306
  },
249
307
  ],
@@ -252,9 +310,8 @@ describe('getCommentBody', () => {
252
310
  {
253
311
  status: 'failure',
254
312
  targetBranch: '7.2',
255
- errorMessage: 'My boom error!',
256
- error: new HandledError_1.HandledError('Boom!', {
257
- type: 'merge-conflict-due-to-missing-backports',
313
+ error: new HandledError_1.HandledError({
314
+ code: 'merge-conflict-exception',
258
315
  commitsWithoutBackports: [],
259
316
  }),
260
317
  },
@@ -272,20 +329,58 @@ describe('getCommentBody', () => {
272
329
  |❌|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)|
273
330
  |❌|7.2|**Backport failed because of merge conflicts**|
274
331
 
275
- ### How to fix
276
- Re-run the backport manually:
332
+ ### Manual backport
333
+ To create the backport manually run:
277
334
  \`\`\`
278
335
  node scripts/backport --pr 55
279
336
  \`\`\`
280
337
  Note: Successful backport PRs will be merged automatically after passing CI.
281
338
 
282
339
  ### Questions ?
283
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
340
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
341
+ <!--- Backport version: 1.2.3 -->"
284
342
  `);
285
343
  });
286
344
  it('does not post a comment when running manually because some backports failed', () => {
287
345
  const params = getParams({ ci: false });
288
- expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
346
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
347
+ });
348
+ });
349
+ describe('when all backports fail due to missing branches', () => {
350
+ const getParams = (opts) => ({
351
+ options: {
352
+ repoName: 'kibana',
353
+ repoOwner: 'elastic',
354
+ autoMerge: true,
355
+ backportBinary: 'node scripts/backport',
356
+ ...opts,
357
+ },
358
+ pullNumber: 55,
359
+ backportResponse: {
360
+ status: 'failure',
361
+ error: new HandledError_1.HandledError({ code: 'no-branches-exception' }),
362
+ },
363
+ });
364
+ it('posts a comment when running on CI', () => {
365
+ const params = getParams({ ci: true });
366
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
367
+ "## ⚪ Backport skipped
368
+ 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.
369
+
370
+ ### Manual backport
371
+ To create the backport manually run:
372
+ \`\`\`
373
+ node scripts/backport --pr 55
374
+ \`\`\`
375
+
376
+ ### Questions ?
377
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
378
+ <!--- Backport version: 1.2.3 -->"
379
+ `);
380
+ });
381
+ it('does not post a comment when running manually', () => {
382
+ const params = getParams({ ci: false });
383
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
289
384
  });
290
385
  });
291
386
  });
@@ -1,4 +1,4 @@
1
- export declare type GithubV3Error = {
1
+ declare type GithubV3Error = {
2
2
  name: string;
3
3
  status: number;
4
4
  documentation_url: string;
@@ -11,3 +11,4 @@ export declare type GithubV3Error = {
11
11
  }>;
12
12
  };
13
13
  export declare function getGithubV3ErrorMessage(e: GithubV3Error): string | undefined;
14
+ export {};
@@ -1,9 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export interface PullRequestResponse {
3
- repository: {
4
- pullRequest: {
5
- id: string;
6
- };
7
- };
8
- }
9
2
  export declare function fetchPullRequestId(options: ValidConfigOptions, pullNumber: number): Promise<string>;
@@ -1,24 +1,28 @@
1
- import { AxiosError } from 'axios';
2
- import { HandledError } from '../../HandledError';
1
+ import { AxiosResponse } from 'axios';
2
+ interface GithubError {
3
+ type: string;
4
+ path: string[];
5
+ locations: {
6
+ line: number;
7
+ column: number;
8
+ }[];
9
+ message: string;
10
+ }
3
11
  export interface GithubV4Response<DataResponse> {
4
12
  data: DataResponse;
5
- errors?: {
6
- type: string;
7
- path: string[];
8
- locations: {
9
- line: number;
10
- column: number;
11
- }[];
12
- message: string;
13
- }[];
13
+ errors?: GithubError[];
14
14
  }
15
- export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, handleError, }: {
15
+ declare type Variables = Record<string, string | number | null>;
16
+ export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, }: {
16
17
  githubApiBaseUrlV4?: string;
17
18
  accessToken: string;
18
19
  query: string;
19
- variables?: {
20
- [key: string]: string | number | null;
21
- };
22
- handleError?: boolean;
20
+ variables?: Variables;
23
21
  }): Promise<DataResponse>;
24
- export declare function handleGithubV4Error(e: AxiosError<GithubV4Response<unknown>>): HandledError | AxiosError<GithubV4Response<unknown>, any>;
22
+ declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
23
+ export declare class GithubV4Exception<DataResponse> extends Error {
24
+ message: string;
25
+ axiosResponse: AxiosGithubResponse<DataResponse>;
26
+ constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
27
+ }
28
+ export {};
@@ -3,11 +3,11 @@ 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.handleGithubV4Error = exports.apiRequestV4 = void 0;
6
+ exports.GithubV4Exception = exports.apiRequestV4 = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const HandledError_1 = require("../../HandledError");
9
9
  const logger_1 = require("../../logger");
10
- async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, handleError = true, }) {
10
+ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
11
11
  try {
12
12
  const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
13
13
  headers: {
@@ -16,40 +16,50 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
16
16
  },
17
17
  });
18
18
  if (response.data.errors) {
19
- const newError = new Error();
20
- //@ts-expect-error
21
- newError.response = response;
22
- throw newError;
19
+ const message = `${response.data.errors
20
+ .map((error) => error.message)
21
+ .join(',')} (Github API v4)`;
22
+ throw new GithubV4Exception(message, response);
23
23
  }
24
- logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${response.status})`);
25
- logger_1.logger.verbose('Query:', query);
26
- logger_1.logger.verbose('Variables:', variables);
27
- logger_1.logger.verbose('Response headers:', response.headers);
28
- logger_1.logger.verbose('Response data:', response.data);
24
+ addDebugLogs({
25
+ githubApiBaseUrlV4,
26
+ query,
27
+ variables,
28
+ axiosResponse: response,
29
+ didSucceed: false,
30
+ });
29
31
  return response.data.data;
30
32
  }
31
33
  catch (e) {
32
- logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${e.response?.status})`);
33
- logger_1.logger.info('Query:', query);
34
- logger_1.logger.info('Variables:', variables);
35
- logger_1.logger.verbose('Response headers:', e.response?.headers);
36
- logger_1.logger.info('Response data:', e.response?.data);
37
- if (handleError) {
38
- throw handleGithubV4Error(e);
34
+ if (axios_1.default.isAxiosError(e) && e.response) {
35
+ addDebugLogs({
36
+ githubApiBaseUrlV4,
37
+ query,
38
+ variables,
39
+ axiosResponse: e.response,
40
+ didSucceed: false,
41
+ });
42
+ throw new GithubV4Exception(`${e.message} (Unhandled Github API v4)`, e.response);
39
43
  }
40
44
  throw e;
41
45
  }
42
46
  }
43
47
  exports.apiRequestV4 = apiRequestV4;
44
- function handleGithubV4Error(e) {
45
- // re-throw unknown error
46
- if (!e.response?.data) {
47
- return e;
48
- }
49
- const errorMessages = e.response.data.errors?.map((error) => error.message);
50
- if (errorMessages) {
51
- return new HandledError_1.HandledError(`${errorMessages.join(', ')} (Unhandled Github v4 error)`);
48
+ function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
49
+ logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${axiosResponse.status})`);
50
+ const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
51
+ logMethod('Query:', query);
52
+ logMethod('Variables:', variables);
53
+ logMethod('Response headers:', axiosResponse.headers);
54
+ logMethod('Response data:', axiosResponse.data);
55
+ }
56
+ class GithubV4Exception extends Error {
57
+ constructor(message, axiosResponse) {
58
+ super(message);
59
+ this.message = message;
60
+ this.axiosResponse = axiosResponse;
61
+ Error.captureStackTrace(this, HandledError_1.HandledError);
62
+ this.name = 'GithubV4Exception';
52
63
  }
53
- return new HandledError_1.HandledError(`Unexpected response from Github API (v4):\n${JSON.stringify(e.response.data, null, 2)}`);
54
64
  }
55
- exports.handleGithubV4Error = handleGithubV4Error;
65
+ exports.GithubV4Exception = GithubV4Exception;
@@ -43,13 +43,13 @@ describe('apiRequestV4', () => {
43
43
  beforeEach(() => {
44
44
  (0, nockHelpers_1.mockGqlRequest)({
45
45
  name: 'MyQuery',
46
- statusCode: 500,
46
+ statusCode: 200,
47
47
  body: {
48
48
  errors: [{ message: 'some error' }, { message: 'some other error' }],
49
49
  },
50
50
  });
51
51
  });
52
- it('should return parsed github error', async () => {
52
+ it('should return error containing the error messages', async () => {
53
53
  return expect((0, apiRequestV4_1.apiRequestV4)({
54
54
  accessToken: 'myAccessToken',
55
55
  githubApiBaseUrlV4: 'http://localhost/graphql',
@@ -57,7 +57,7 @@ describe('apiRequestV4', () => {
57
57
  variables: {
58
58
  foo: 'bar',
59
59
  },
60
- })).rejects.toThrowError(new HandledError_1.HandledError(`some error, some other error (Unhandled Github v4 error)`));
60
+ })).rejects.toThrowError(new HandledError_1.HandledError(`some error,some other error (Github API v4)`));
61
61
  });
62
62
  });
63
63
  describe('when request fails without error messages', () => {
@@ -76,7 +76,7 @@ describe('apiRequestV4', () => {
76
76
  variables: {
77
77
  foo: 'bar',
78
78
  },
79
- })).rejects.toThrowErrorMatchingSnapshot();
79
+ })).rejects.toThrowError('Request failed with status code 500');
80
80
  });
81
81
  });
82
82
  });
@@ -1,9 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export interface PullRequestAutoMergeResponse {
3
- disablePullRequestAutoMerge: {
4
- pullRequest?: {
5
- number: number;
6
- };
7
- };
8
- }
9
2
  export declare function disablePullRequestAutoMerge(options: ValidConfigOptions, pullNumber: number): Promise<number | undefined>;
@@ -1,9 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export interface PullRequestAutoMergeResponse {
3
- enablePullRequestAutoMerge: {
4
- pullRequest?: {
5
- number: number;
6
- };
7
- };
8
- }
9
2
  export declare function enablePullRequestAutoMerge(options: ValidConfigOptions, targetPullRequestNumber: number): Promise<number | undefined>;