backport 8.0.0 → 8.3.0-beta.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 (217) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +42 -48
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +25 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +60 -0
  18. package/dist/lib/env.d.ts +9 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +210 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +138 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +566 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/github/v4/validateTargetBranches.d.ts +9 -0
  125. package/dist/lib/github/v4/validateTargetBranches.js +46 -0
  126. package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
  127. package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
  128. package/dist/lib/logger.d.ts +11 -0
  129. package/dist/lib/logger.js +80 -0
  130. package/dist/lib/ora.d.ts +2 -0
  131. package/dist/lib/ora.js +21 -0
  132. package/dist/lib/prompt.test.d.ts +1 -0
  133. package/dist/lib/prompt.test.js +139 -0
  134. package/dist/lib/prompts.d.ts +17 -0
  135. package/dist/lib/prompts.js +132 -0
  136. package/dist/lib/remoteConfig.d.ts +20 -0
  137. package/dist/lib/remoteConfig.js +52 -0
  138. package/dist/lib/sequentially.d.ts +1 -0
  139. package/dist/lib/sequentially.js +10 -0
  140. package/dist/lib/setupRepo.d.ts +2 -0
  141. package/dist/lib/setupRepo.js +56 -0
  142. package/dist/lib/setupRepo.test.d.ts +1 -0
  143. package/dist/lib/setupRepo.test.js +278 -0
  144. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  145. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  146. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  147. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  148. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  149. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  150. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  151. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  152. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  153. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  154. package/dist/options/ConfigOptions.d.ts +4 -2
  155. package/dist/options/cliArgs.d.ts +12 -9
  156. package/dist/options/cliArgs.js +34 -19
  157. package/dist/options/cliArgs.test.js +126 -2
  158. package/dist/options/config/config.d.ts +5 -4
  159. package/dist/options/config/config.js +3 -5
  160. package/dist/options/config/config.test.js +0 -1
  161. package/dist/options/config/globalConfig.d.ts +3 -1
  162. package/dist/options/config/globalConfig.js +5 -5
  163. package/dist/options/config/readConfigFile.d.ts +6 -4
  164. package/dist/options/config/readConfigFile.js +2 -2
  165. package/dist/options/options.d.ts +40 -4
  166. package/dist/options/options.js +20 -24
  167. package/dist/options/options.test.js +112 -54
  168. package/dist/runSequentially.d.ts +10 -9
  169. package/dist/runSequentially.js +7 -8
  170. package/dist/scripts/postinstall.js +3 -3
  171. package/dist/scripts/postinstall.test.js +1 -1
  172. package/dist/services/BackportError.d.ts +19 -0
  173. package/dist/services/BackportError.js +29 -0
  174. package/dist/services/HandledBackportError.d.ts +19 -0
  175. package/dist/services/HandledBackportError.js +29 -0
  176. package/dist/services/HandledError.d.ts +1 -1
  177. package/dist/services/HandledError.js +5 -5
  178. package/dist/services/git.js +7 -7
  179. package/dist/services/github/v3/createPullRequest.js +2 -2
  180. package/dist/services/github/v3/createStatusComment.js +2 -2
  181. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  182. package/dist/services/github/v4/apiRequestV4.js +2 -2
  183. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  184. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  185. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  186. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  187. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  188. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  189. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  190. package/dist/state.d.ts +0 -0
  191. package/dist/state.js +1 -0
  192. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  193. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
  194. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +46 -250
  195. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
  196. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
  197. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
  198. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
  199. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
  200. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
  201. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
  202. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
  203. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +13 -15
  204. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  205. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  206. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  207. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  208. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  209. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  210. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  211. package/dist/ui/getCommits.js +2 -2
  212. package/dist/ui/getTargetBranches.js +3 -3
  213. package/dist/ui/setupRepo.js +2 -2
  214. package/dist/utils/packageVersion.d.ts +1 -1
  215. package/dist/utils/packageVersion.js +1 -1
  216. package/package.json +14 -14
  217. package/yarn.lock +125 -73
@@ -0,0 +1,566 @@
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 logger_1 = require("../../logger");
9
+ const createStatusComment_1 = require("./createStatusComment");
10
+ jest.unmock('../../logger');
11
+ describe('createStatusComment', () => {
12
+ it('redacts accessToken if it is included in the error message', async () => {
13
+ const accessToken = 'ghp_abcdefg';
14
+ (0, logger_1.setAccessToken)(accessToken);
15
+ const scope = (0, nock_1.default)('https://api.github.com')
16
+ .post('/repos/elastic/kibana/issues/100/comments')
17
+ .reply(200, 'some response');
18
+ let postedCommentBody = '';
19
+ scope.on('request', (req, interceptor, body) => {
20
+ postedCommentBody = JSON.parse(body).body;
21
+ });
22
+ await (0, createStatusComment_1.createStatusComment)({
23
+ options: {
24
+ repoName: 'kibana',
25
+ repoOwner: 'elastic',
26
+ accessToken,
27
+ backportBinary: 'node scripts/backport',
28
+ publishStatusCommentOnSuccess: true,
29
+ publishStatusCommentOnFailure: true,
30
+ githubApiBaseUrlV3: 'https://api.github.com',
31
+ interactive: false,
32
+ },
33
+ backportResponse: {
34
+ commits: [{ sourcePullRequest: { number: 100 } }],
35
+ status: 'failure',
36
+ error: new Error(`Error message containing very secret access token: ${accessToken}.`),
37
+ },
38
+ });
39
+ expect(postedCommentBody).toContain('Error message containing very secret access token: <REDACTED>');
40
+ scope.done();
41
+ nock_1.default.cleanAll();
42
+ });
43
+ });
44
+ describe('getCommentBody', () => {
45
+ describe('when an unknown error occurs', () => {
46
+ const getParams = (opts) => ({
47
+ options: {
48
+ backportBinary: 'node scripts/backport',
49
+ ...opts,
50
+ },
51
+ pullNumber: 55,
52
+ backportResponse: {
53
+ status: 'failure',
54
+ error: new Error('A terrible error occured'),
55
+ },
56
+ });
57
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
58
+ const params = getParams({ publishStatusCommentOnFailure: true });
59
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
60
+ "## 💔 Backport failed
61
+ The pull request could not be backported due to the following error:
62
+ \`A terrible error occured\`
63
+
64
+ ### Manual backport
65
+ To create the backport manually run:
66
+ \`\`\`
67
+ node scripts/backport --pr 55
68
+ \`\`\`
69
+
70
+ ### Questions ?
71
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
72
+
73
+ <!--- Backport version: 1.2.3-mocked -->"
74
+ `);
75
+ });
76
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
77
+ const params = getParams({ publishStatusCommentOnFailure: false });
78
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
79
+ });
80
+ });
81
+ describe('when all backports succeed', () => {
82
+ const getParams = (opts) => ({
83
+ options: {
84
+ repoName: 'kibana',
85
+ repoOwner: 'elastic',
86
+ autoMerge: true,
87
+ ...opts,
88
+ },
89
+ pullNumber: 55,
90
+ backportResponse: {
91
+ status: 'success',
92
+ results: [
93
+ {
94
+ status: 'success',
95
+ targetBranch: '7.x',
96
+ pullRequestNumber: 55,
97
+ pullRequestUrl: 'url-to-pr',
98
+ },
99
+ {
100
+ status: 'success',
101
+ targetBranch: '7.1',
102
+ pullRequestNumber: 66,
103
+ pullRequestUrl: 'url-to-pr',
104
+ },
105
+ ],
106
+ },
107
+ });
108
+ it('posts a comment when `publishStatusCommentOnSuccess = true`', () => {
109
+ const params = getParams({ publishStatusCommentOnSuccess: true });
110
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
111
+ "## 💚 All backports created successfully
112
+
113
+ | Status | Branch | Result |
114
+ |:------:|:------:|:------|
115
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
116
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
117
+
118
+ Note: Successful backport PRs will be merged automatically after passing CI.
119
+
120
+ ### Questions ?
121
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
122
+
123
+ <!--- Backport version: 1.2.3-mocked -->"
124
+ `);
125
+ });
126
+ it('does not post a comment when `publishStatusCommentOnSuccess = false`', () => {
127
+ const params = getParams({ interactive: true });
128
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
129
+ });
130
+ });
131
+ describe('when all backports fail', () => {
132
+ const getParams = (opts) => ({
133
+ options: {
134
+ repoName: 'kibana',
135
+ repoOwner: 'elastic',
136
+ autoMerge: true,
137
+ backportBinary: 'node scripts/backport',
138
+ ...opts,
139
+ },
140
+ pullNumber: 55,
141
+ backportResponse: {
142
+ status: 'success',
143
+ results: [
144
+ {
145
+ status: 'unhandled-error',
146
+ targetBranch: '7.x',
147
+ error: new Error('My boom error!'),
148
+ },
149
+ {
150
+ status: 'unhandled-error',
151
+ targetBranch: '7.1',
152
+ error: new Error('My boom error!'),
153
+ },
154
+ ],
155
+ },
156
+ });
157
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
158
+ const params = getParams({ publishStatusCommentOnFailure: true });
159
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
160
+ "## 💔 All backports failed
161
+
162
+ | Status | Branch | Result |
163
+ |:------:|:------:|:------|
164
+ |❌|7.x|An unhandled error occurred. Please see the logs for details|
165
+ |❌|7.1|An unhandled error occurred. Please see the logs for details|
166
+
167
+ ### Manual backport
168
+ To create the backport manually run:
169
+ \`\`\`
170
+ node scripts/backport --pr 55
171
+ \`\`\`
172
+
173
+ ### Questions ?
174
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
175
+
176
+ <!--- Backport version: 1.2.3-mocked -->"
177
+ `);
178
+ });
179
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
180
+ const params = getParams({ publishStatusCommentOnFailure: false });
181
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
182
+ });
183
+ });
184
+ describe('when some backports fail', () => {
185
+ const getParams = (opts) => ({
186
+ options: {
187
+ repoName: 'kibana',
188
+ repoOwner: 'elastic',
189
+ autoMerge: true,
190
+ backportBinary: 'node scripts/backport',
191
+ ...opts,
192
+ },
193
+ pullNumber: 55,
194
+ backportResponse: {
195
+ status: 'success',
196
+ results: [
197
+ {
198
+ status: 'success',
199
+ targetBranch: '7.x',
200
+ pullRequestNumber: 55,
201
+ pullRequestUrl: 'url-to-pr-55',
202
+ },
203
+ {
204
+ status: 'failure',
205
+ targetBranch: '7.1',
206
+ error: new Error('My boom error!'),
207
+ },
208
+ ],
209
+ },
210
+ });
211
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
212
+ const params = getParams({ publishStatusCommentOnFailure: true });
213
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
214
+ "## 💔 Some backports could not be created
215
+
216
+ | Status | Branch | Result |
217
+ |:------:|:------:|:------|
218
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
219
+ |❌|7.1|An unhandled error occurred. Please see the logs for details|
220
+
221
+ Note: Successful backport PRs will be merged automatically after passing CI.
222
+
223
+ ### Manual backport
224
+ To create the backport manually run:
225
+ \`\`\`
226
+ node scripts/backport --pr 55
227
+ \`\`\`
228
+
229
+ ### Questions ?
230
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
231
+
232
+ <!--- Backport version: 1.2.3-mocked -->"
233
+ `);
234
+ });
235
+ it('does not post a comment when running `publishStatusCommentOnFailure = false`', () => {
236
+ const params = getParams({ publishStatusCommentOnFailure: false });
237
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
238
+ });
239
+ });
240
+ describe('when some backports fail due to conflicts', () => {
241
+ const getParams = (opts) => ({
242
+ options: {
243
+ repoName: 'kibana',
244
+ repoOwner: 'elastic',
245
+ autoMerge: true,
246
+ backportBinary: 'node scripts/backport',
247
+ ...opts,
248
+ },
249
+ pullNumber: 55,
250
+ backportResponse: {
251
+ status: 'success',
252
+ results: [
253
+ {
254
+ status: 'success',
255
+ targetBranch: '7.x',
256
+ pullRequestNumber: 55,
257
+ pullRequestUrl: 'url-to-pr-55',
258
+ },
259
+ {
260
+ status: 'failure',
261
+ targetBranch: '7.1',
262
+ error: new BackportError_1.BackportError({
263
+ code: 'merge-conflict-exception',
264
+ conflictingFiles: ['readme.md'],
265
+ commitsWithoutBackports: [
266
+ {
267
+ formatted: 'some-formatted-text',
268
+ commit: {
269
+ author: {
270
+ email: 'soren.louv@elastic.co',
271
+ name: 'Søren Louv-Jansen',
272
+ },
273
+ sourceBranch: 'master',
274
+ sourcePullRequest: {
275
+ number: 5,
276
+ url: 'url-to-pr-5',
277
+ mergeCommit: {
278
+ sha: '',
279
+ message: 'New Zealand commit message',
280
+ },
281
+ },
282
+ sourceCommit: {
283
+ committedDate: '',
284
+ sha: '',
285
+ message: 'New Zealand commit message',
286
+ },
287
+ expectedTargetPullRequests: [],
288
+ },
289
+ },
290
+ {
291
+ formatted: 'some-formatted-text',
292
+ commit: {
293
+ author: {
294
+ email: 'soren.louv@elastic.co',
295
+ name: 'Søren Louv-Jansen',
296
+ },
297
+ sourceBranch: 'master',
298
+ sourcePullRequest: {
299
+ number: 44,
300
+ url: 'url-to-pr-44',
301
+ mergeCommit: {
302
+ sha: '',
303
+ message: 'Australia commit',
304
+ },
305
+ },
306
+ sourceCommit: {
307
+ committedDate: '',
308
+ sha: '',
309
+ message: 'Australia commit',
310
+ },
311
+ expectedTargetPullRequests: [],
312
+ },
313
+ },
314
+ ],
315
+ }),
316
+ },
317
+ {
318
+ status: 'failure',
319
+ targetBranch: '7.2',
320
+ error: new BackportError_1.BackportError({
321
+ code: 'merge-conflict-exception',
322
+ conflictingFiles: ['my-file.txt'],
323
+ commitsWithoutBackports: [],
324
+ }),
325
+ },
326
+ ],
327
+ },
328
+ });
329
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
330
+ const params = getParams({ publishStatusCommentOnFailure: true });
331
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
332
+ "## 💔 Some backports could not be created
333
+
334
+ | Status | Branch | Result |
335
+ |:------:|:------:|:------|
336
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
337
+ |❌|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)|
338
+ |❌|7.2|**Backport failed because of merge conflicts**|
339
+
340
+ Note: Successful backport PRs will be merged automatically after passing CI.
341
+
342
+ ### Manual backport
343
+ To create the backport manually run:
344
+ \`\`\`
345
+ node scripts/backport --pr 55
346
+ \`\`\`
347
+
348
+ ### Questions ?
349
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
350
+
351
+ <!--- Backport version: 1.2.3-mocked -->"
352
+ `);
353
+ });
354
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
355
+ const params = getParams({ publishStatusCommentOnFailure: false });
356
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
357
+ });
358
+ });
359
+ describe('when backport was aborted due to missing branches', () => {
360
+ const getParams = (opts) => ({
361
+ options: {
362
+ repoName: 'kibana',
363
+ repoOwner: 'elastic',
364
+ autoMerge: true,
365
+ backportBinary: 'node scripts/backport',
366
+ ...opts,
367
+ },
368
+ pullNumber: 55,
369
+ backportResponse: {
370
+ status: 'aborted',
371
+ commits: [],
372
+ error: new BackportError_1.BackportError({ code: 'no-branches-exception' }),
373
+ errorMessage: 'my message',
374
+ },
375
+ });
376
+ it('posts a comment when `publishStatusCommentOnAbort = true`', () => {
377
+ const params = getParams({
378
+ publishStatusCommentOnAbort: true,
379
+ });
380
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
381
+ "## ⚪ Backport skipped
382
+ 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.
383
+
384
+ ### Manual backport
385
+ To create the backport manually run:
386
+ \`\`\`
387
+ node scripts/backport --pr 55
388
+ \`\`\`
389
+
390
+ ### Questions ?
391
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
392
+
393
+ <!--- Backport version: 1.2.3-mocked -->"
394
+ `);
395
+ });
396
+ it('does not post a comment when `publishStatusCommentOnAbort = false`', () => {
397
+ const params = getParams({ publishStatusCommentOnAbort: false });
398
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
399
+ });
400
+ });
401
+ describe('when backport was aborted during conflict resolution', () => {
402
+ const getParams = (opts) => ({
403
+ options: {
404
+ interactive: true,
405
+ repoName: 'kibana',
406
+ repoOwner: 'elastic',
407
+ autoMerge: true,
408
+ backportBinary: 'node scripts/backport',
409
+ ...opts,
410
+ },
411
+ pullNumber: 55,
412
+ backportResponse: {
413
+ status: 'success',
414
+ commits: [],
415
+ results: [
416
+ {
417
+ targetBranch: 'staging',
418
+ status: 'handled-error',
419
+ error: new BackportError_1.BackportError({
420
+ code: 'abort-conflict-resolution-exception',
421
+ }),
422
+ },
423
+ ],
424
+ },
425
+ });
426
+ it('posts a comment when `publishStatusCommentOnAbort = true`', () => {
427
+ const params = getParams({
428
+ publishStatusCommentOnAbort: true,
429
+ });
430
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
431
+ });
432
+ it('does not post a comment when `publishStatusCommentOnAbort = false`', () => {
433
+ const params = getParams({ publishStatusCommentOnAbort: false });
434
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
435
+ });
436
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
437
+ const params = getParams({
438
+ publishStatusCommentOnFailure: true,
439
+ });
440
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
441
+ "## 💔 All backports failed
442
+
443
+ | Status | Branch | Result |
444
+ |:------:|:------:|:------|
445
+ |❌|staging|Conflict resolution was aborted by the user|
446
+
447
+ ### Manual backport
448
+ To create the backport manually run:
449
+ \`\`\`
450
+ node scripts/backport --pr 55
451
+ \`\`\`
452
+
453
+ ### Questions ?
454
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
455
+
456
+ <!--- Backport version: 1.2.3-mocked -->"
457
+ `);
458
+ });
459
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
460
+ const params = getParams({ publishStatusCommentOnFailure: false });
461
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
462
+ });
463
+ });
464
+ describe("when target branch doesn't exist", () => {
465
+ const getParams = (opts) => ({
466
+ options: {
467
+ interactive: true,
468
+ repoName: 'kibana',
469
+ repoOwner: 'elastic',
470
+ autoMerge: true,
471
+ backportBinary: 'node scripts/backport',
472
+ ...opts,
473
+ },
474
+ pullNumber: 55,
475
+ backportResponse: {
476
+ status: 'success',
477
+ commits: [],
478
+ results: [
479
+ {
480
+ targetBranch: 'main',
481
+ status: 'handled-error',
482
+ error: new BackportError_1.BackportError('The branch "main" is invalid or doesn\'t exist'),
483
+ },
484
+ ],
485
+ },
486
+ });
487
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
488
+ const params = getParams({
489
+ publishStatusCommentOnFailure: true,
490
+ });
491
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
492
+ "## 💔 All backports failed
493
+
494
+ | Status | Branch | Result |
495
+ |:------:|:------:|:------|
496
+ |❌|main|The branch \\"main\\" is invalid or doesn't exist|
497
+
498
+ ### Manual backport
499
+ To create the backport manually run:
500
+ \`\`\`
501
+ node scripts/backport --pr 55
502
+ \`\`\`
503
+
504
+ ### Questions ?
505
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
506
+
507
+ <!--- Backport version: 1.2.3-mocked -->"
508
+ `);
509
+ });
510
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
511
+ const params = getParams({ publishStatusCommentOnFailure: false });
512
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
513
+ });
514
+ });
515
+ describe('when target branch is invalid', () => {
516
+ const getParams = (opts) => ({
517
+ options: {
518
+ interactive: true,
519
+ repoName: 'kibana',
520
+ repoOwner: 'elastic',
521
+ autoMerge: true,
522
+ backportBinary: 'node scripts/backport',
523
+ ...opts,
524
+ },
525
+ pullNumber: 55,
526
+ backportResponse: {
527
+ status: 'success',
528
+ commits: [],
529
+ results: [
530
+ {
531
+ targetBranch: '--foo',
532
+ status: 'unhandled-error',
533
+ error: new BackportError_1.BackportError('The branch "--foo" does not exist'),
534
+ },
535
+ ],
536
+ },
537
+ });
538
+ it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
539
+ const params = getParams({
540
+ publishStatusCommentOnFailure: true,
541
+ });
542
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
543
+ "## 💔 All backports failed
544
+
545
+ | Status | Branch | Result |
546
+ |:------:|:------:|:------|
547
+ |❌|--foo|An unhandled error occurred. Please see the logs for details|
548
+
549
+ ### Manual backport
550
+ To create the backport manually run:
551
+ \`\`\`
552
+ node scripts/backport --pr 55
553
+ \`\`\`
554
+
555
+ ### Questions ?
556
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
557
+
558
+ <!--- Backport version: 1.2.3-mocked -->"
559
+ `);
560
+ });
561
+ it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
562
+ const params = getParams({ publishStatusCommentOnFailure: false });
563
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
564
+ });
565
+ });
566
+ });
@@ -0,0 +1,14 @@
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 {};
@@ -0,0 +1,16 @@
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;
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../../../options/options';
2
+ export declare function fetchPullRequestId(options: ValidConfigOptions, pullNumber: number): Promise<string>;
@@ -0,0 +1,36 @@
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;
@@ -0,0 +1,31 @@
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 {};