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,136 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const graphql_1 = require("graphql");
27
- const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
28
- const apiRequestV4Module = __importStar(require("../apiRequestV4"));
29
- const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
30
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
- describe('fetchCommitByPullNumber', () => {
32
- describe('snapshot request/response', () => {
33
- let spy;
34
- let commit;
35
- beforeEach(async () => {
36
- spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
37
- commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
38
- repoOwner: 'elastic',
39
- repoName: 'kibana',
40
- accessToken,
41
- pullNumber: 121633,
42
- sourceBranch: 'master',
43
- });
44
- });
45
- it('makes the right queries', () => {
46
- const queries = spy.mock.calls.reduce((acc, call) => {
47
- const query = call[0].query;
48
- const name = apiRequestV4Module.getQueryName(query);
49
- return { ...acc, [name]: (0, graphql_1.print)(query) };
50
- }, {});
51
- const queryNames = Object.keys(queries);
52
- expect(queryNames).toEqual(['CommitByPullNumber']);
53
- queryNames.forEach((name) => {
54
- expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
55
- });
56
- });
57
- it('returns the correct response', async () => {
58
- expect(commit).toMatchSnapshot();
59
- });
60
- });
61
- describe('when PR was merged', () => {
62
- it('is returned', async () => {
63
- const options = {
64
- accessToken,
65
- pullNumber: 5,
66
- repoName: 'backport-e2e',
67
- repoOwner: 'backport-org',
68
- sourceBranch: 'main',
69
- };
70
- const expectedCommit = {
71
- author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
72
- sourceCommit: {
73
- committedDate: '2020-08-15T12:40:19Z',
74
- message: 'Add 🍏 emoji (#5)',
75
- sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
76
- },
77
- sourcePullRequest: {
78
- number: 5,
79
- url: 'https://github.com/backport-org/backport-e2e/pull/5',
80
- mergeCommit: {
81
- message: 'Add 🍏 emoji (#5)',
82
- sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
83
- },
84
- },
85
- sourceBranch: 'master',
86
- expectedTargetPullRequests: [
87
- {
88
- branch: '7.x',
89
- state: 'MERGED',
90
- number: 6,
91
- url: 'https://github.com/backport-org/backport-e2e/pull/6',
92
- mergeCommit: {
93
- message: 'Add 🍏 emoji (#5) (#6)',
94
- sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
95
- },
96
- },
97
- {
98
- branch: '7.8',
99
- state: 'MERGED',
100
- number: 7,
101
- url: 'https://github.com/backport-org/backport-e2e/pull/7',
102
- mergeCommit: {
103
- message: 'Add 🍏 emoji (#5) (#7)',
104
- sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
105
- },
106
- },
107
- ],
108
- };
109
- expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual(expectedCommit);
110
- });
111
- });
112
- describe('when PR is still open', () => {
113
- it('throws an error', async () => {
114
- const options = {
115
- accessToken,
116
- pullNumber: 11,
117
- repoName: 'backport-e2e',
118
- repoOwner: 'backport-org',
119
- sourceBranch: 'main',
120
- };
121
- await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
122
- });
123
- });
124
- describe('when PR does not exist', () => {
125
- it('throws an error', async () => {
126
- const options = {
127
- accessToken,
128
- pullNumber: 9999999999999,
129
- repoName: 'backport-e2e',
130
- repoOwner: 'backport-org',
131
- sourceBranch: 'main',
132
- };
133
- await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
134
- });
135
- });
136
- });
@@ -1,11 +0,0 @@
1
- import { ValidConfigOptions } from '../../../../options/options';
2
- import { Commit } from '../../../sourceCommit/parseSourceCommit';
3
- export declare function fetchCommitBySha(options: {
4
- accessToken: string;
5
- branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
- githubApiBaseUrlV4?: string;
7
- repoName: string;
8
- repoOwner: string;
9
- sha: string;
10
- sourceBranch: string;
11
- }): Promise<Commit>;
@@ -1,48 +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.fetchCommitBySha = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const BackportError_1 = require("../../../BackportError");
9
- const remoteConfig_1 = require("../../../remoteConfig");
10
- const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
11
- const apiRequestV4_1 = require("../apiRequestV4");
12
- async function fetchCommitBySha(options) {
13
- const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
14
- const query = (0, graphql_tag_1.default) `
15
- query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
16
- repository(owner: $repoOwner, name: $repoName) {
17
- object(expression: $sha) {
18
- ...SourceCommitWithTargetPullRequestFragment
19
- }
20
- }
21
- }
22
-
23
- ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
24
- `;
25
- let res;
26
- try {
27
- res = await (0, apiRequestV4_1.apiRequestV4)({
28
- githubApiBaseUrlV4,
29
- accessToken,
30
- query,
31
- variables: {
32
- repoOwner,
33
- repoName,
34
- sha,
35
- },
36
- });
37
- }
38
- catch (e) {
39
- //@ts-expect-error
40
- res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
41
- }
42
- const sourceCommit = res.repository.object;
43
- if (!sourceCommit) {
44
- throw new BackportError_1.BackportError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
45
- }
46
- return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
47
- }
48
- exports.fetchCommitBySha = fetchCommitBySha;
@@ -1,118 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const graphql_1 = require("graphql");
27
- const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
28
- const apiRequestV4Module = __importStar(require("../apiRequestV4"));
29
- const fetchCommitBySha_1 = require("./fetchCommitBySha");
30
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
- describe('fetchCommitBySha', () => {
32
- describe('snapshot request/response', () => {
33
- let spy;
34
- let commit;
35
- beforeEach(async () => {
36
- spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
37
- commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({
38
- repoOwner: 'elastic',
39
- repoName: 'kibana',
40
- accessToken,
41
- sha: 'd421ddcf6157150596581c7885afa3690cec6339',
42
- sourceBranch: 'main',
43
- });
44
- });
45
- it('makes the right queries', () => {
46
- const queries = spy.mock.calls.reduce((acc, call) => {
47
- const query = call[0].query;
48
- //@ts-expect-error
49
- const name = query.definitions[0].name.value;
50
- return { ...acc, [name]: (0, graphql_1.print)(query) };
51
- }, {});
52
- const queryNames = Object.keys(queries);
53
- expect(queryNames).toEqual(['CommitsBySha']);
54
- queryNames.forEach((name) => {
55
- expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
56
- });
57
- });
58
- it('returns the correct response', async () => {
59
- expect(commit).toMatchSnapshot();
60
- });
61
- });
62
- it('should return single commit with pull request', async () => {
63
- const expectedCommit = {
64
- author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
65
- sourceCommit: {
66
- committedDate: '2020-07-07T20:40:28Z',
67
- message: '[APM] Add API tests (#70740)',
68
- sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
69
- },
70
- sourcePullRequest: {
71
- number: 70740,
72
- url: 'https://github.com/elastic/kibana/pull/70740',
73
- mergeCommit: {
74
- message: '[APM] Add API tests (#70740)',
75
- sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
76
- },
77
- },
78
- sourceBranch: 'master',
79
- expectedTargetPullRequests: [
80
- {
81
- branch: '7.x',
82
- state: 'MERGED',
83
- number: 71014,
84
- url: 'https://github.com/elastic/kibana/pull/71014',
85
- mergeCommit: {
86
- message: '[APM] Add API tests (#70740) (#71014)',
87
- sha: 'd15242be682582e58cd69f6b7707565434e99293',
88
- },
89
- },
90
- ],
91
- };
92
- await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
93
- repoOwner: 'elastic',
94
- repoName: 'kibana',
95
- accessToken,
96
- sha: 'cb6fbc0',
97
- sourceBranch: 'master',
98
- })).toEqual(expectedCommit);
99
- });
100
- it('throws if sha does not exist', async () => {
101
- await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
102
- repoOwner: 'elastic',
103
- repoName: 'kibana',
104
- accessToken,
105
- sha: 'fc22f59',
106
- sourceBranch: 'main',
107
- })).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
108
- });
109
- it('throws if sha is invalid', async () => {
110
- await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
111
- repoOwner: 'elastic',
112
- repoName: 'kibana',
113
- accessToken,
114
- sha: 'myCommitSha',
115
- sourceBranch: 'main',
116
- })).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
117
- });
118
- });
@@ -1,29 +0,0 @@
1
- import { ValidConfigOptions } from '../../../../options/options';
2
- import { Commit, SourceCommitWithTargetPullRequest } from '../../../sourceCommit/parseSourceCommit';
3
- export declare function fetchCommitsByAuthor(options: {
4
- accessToken: string;
5
- author: string | null;
6
- branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
7
- commitPaths?: string[];
8
- dateSince: string | null;
9
- dateUntil: string | null;
10
- githubApiBaseUrlV4?: string;
11
- maxNumber?: number;
12
- onlyMissing?: boolean;
13
- repoName: string;
14
- repoOwner: string;
15
- sourceBranch: string;
16
- }): Promise<Commit[]>;
17
- export interface CommitByAuthorResponse {
18
- repository: {
19
- ref: {
20
- target: {
21
- history: {
22
- edges: Array<{
23
- node: SourceCommitWithTargetPullRequest;
24
- }>;
25
- };
26
- };
27
- } | null;
28
- };
29
- }
@@ -1,110 +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.fetchCommitsByAuthor = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const lodash_1 = require("lodash");
9
- const filterEmpty_1 = require("../../../../utils/filterEmpty");
10
- const filterUnmergedCommits_1 = require("../../../../utils/filterUnmergedCommits");
11
- const BackportError_1 = require("../../../BackportError");
12
- const remoteConfig_1 = require("../../../remoteConfig");
13
- const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
14
- const apiRequestV4_1 = require("../apiRequestV4");
15
- const fetchAuthorId_1 = require("../fetchAuthorId");
16
- async function fetchByCommitPath({ options, authorId, commitPath, }) {
17
- const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
18
- const query = (0, graphql_tag_1.default) `
19
- query CommitsByAuthor(
20
- $repoOwner: String!
21
- $repoName: String!
22
- $maxNumber: Int!
23
- $sourceBranch: String!
24
- $authorId: ID
25
- $commitPath: String
26
- $dateSince: GitTimestamp
27
- $dateUntil: GitTimestamp
28
- ) {
29
- repository(owner: $repoOwner, name: $repoName) {
30
- ref(qualifiedName: $sourceBranch) {
31
- target {
32
- ... on Commit {
33
- history(
34
- first: $maxNumber
35
- author: { id: $authorId }
36
- path: $commitPath
37
- since: $dateSince
38
- until: $dateUntil
39
- ) {
40
- edges {
41
- node {
42
- ...SourceCommitWithTargetPullRequestFragment
43
- }
44
- }
45
- }
46
- }
47
- }
48
- }
49
- }
50
- }
51
-
52
- ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
53
- `;
54
- const variables = {
55
- repoOwner,
56
- repoName,
57
- sourceBranch,
58
- maxNumber,
59
- authorId,
60
- commitPath,
61
- dateSince,
62
- dateUntil,
63
- };
64
- try {
65
- return await (0, apiRequestV4_1.apiRequestV4)({
66
- githubApiBaseUrlV4,
67
- accessToken,
68
- query,
69
- variables,
70
- });
71
- }
72
- catch (e) {
73
- //@ts-expect-error
74
- return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
75
- }
76
- }
77
- async function fetchCommitsByAuthor(options) {
78
- const { sourceBranch, commitPaths = [] } = options;
79
- const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
80
- const responses = await Promise.all((0, lodash_1.isEmpty)(commitPaths)
81
- ? [fetchByCommitPath({ options, authorId, commitPath: null })]
82
- : commitPaths.map((commitPath) => fetchByCommitPath({ options, authorId, commitPath })));
83
- // we only need to check if the first item is `null` (if the first is `null` they all are)
84
- if (responses[0].repository.ref === null) {
85
- throw new BackportError_1.BackportError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
86
- }
87
- const commits = responses
88
- .flatMap((res) => {
89
- return res.repository.ref?.target.history.edges.map((edge) => {
90
- const sourceCommit = edge.node;
91
- return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
92
- });
93
- })
94
- .filter(filterEmpty_1.filterNil);
95
- // terminate if not commits were found
96
- if ((0, lodash_1.isEmpty)(commits)) {
97
- const pathText = commitPaths.length > 0 ? ` touching files in path: "${commitPaths}"` : '';
98
- const errorText = options.author
99
- ? `There are no commits by "${options.author}" in this repository${pathText}. Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`
100
- : `There are no commits in this repository${pathText}`;
101
- throw new BackportError_1.BackportError(errorText);
102
- }
103
- const commitsUnique = (0, lodash_1.uniqBy)(commits, (c) => c.sourceCommit.sha);
104
- const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, (c) => c.sourceCommit.committedDate, 'desc');
105
- if (options.onlyMissing) {
106
- return commitsSorted.filter(filterUnmergedCommits_1.filterUnmergedCommits);
107
- }
108
- return commitsSorted;
109
- }
110
- exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
@@ -1,196 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const graphql_1 = require("graphql");
27
- const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
28
- const apiRequestV4Module = __importStar(require("../apiRequestV4"));
29
- const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
30
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
- describe('fetchCommitsByAuthor', () => {
32
- describe('snapshot request/response', () => {
33
- let spy;
34
- let commits;
35
- beforeEach(async () => {
36
- spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
37
- commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
38
- accessToken,
39
- author: 'sqren',
40
- maxNumber: 10,
41
- repoName: 'kibana',
42
- repoOwner: 'elastic',
43
- sourceBranch: 'main',
44
- dateSince: '2021-01-10T00:00:00Z',
45
- dateUntil: '2022-01-01T00:00:00Z',
46
- commitPaths: [],
47
- });
48
- });
49
- it('makes the right queries', () => {
50
- const queries = spy.mock.calls.reduce((acc, call) => {
51
- const query = call[0].query;
52
- //@ts-expect-error
53
- const name = query.definitions[0].name.value;
54
- return { ...acc, [name]: (0, graphql_1.print)(query) };
55
- }, {});
56
- const queryNames = Object.keys(queries);
57
- expect(queryNames).toEqual(['AuthorId', 'CommitsByAuthor']);
58
- queryNames.forEach((name) => {
59
- expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
60
- });
61
- });
62
- it('returns the correct response', async () => {
63
- expect(commits).toMatchSnapshot();
64
- });
65
- });
66
- describe('commitPaths', () => {
67
- const getOptions = () => ({
68
- accessToken,
69
- author: 'sqren',
70
- maxNumber: 10,
71
- repoName: 'repo-with-different-commit-paths',
72
- repoOwner: 'backport-org',
73
- sourceBranch: 'main',
74
- dateSince: null,
75
- dateUntil: null,
76
- });
77
- const getCommitMessages = (commits) => {
78
- return commits.map((c) => c.sourceCommit.message.replace(/(\r\n|\n|\r)/gm, ''));
79
- };
80
- it('returns all commits', async () => {
81
- const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
82
- ...getOptions(),
83
- commitPaths: [],
84
- });
85
- const commitMessages = getCommitMessages(commits);
86
- expect(commitMessages).toEqual([
87
- 'Edit all lyrics',
88
- 'Update .backportrc.json',
89
- 'Edit "Take on me"',
90
- 'Add backportrc.json',
91
- 'Add "Bohemian Rhapsody""',
92
- 'Add "99 Luftballons"',
93
- 'Add "Take on me"',
94
- ]);
95
- });
96
- it('only returns commits related to "99-luftballons.txt"', async () => {
97
- const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
98
- ...getOptions(),
99
- commitPaths: ['lyrics/99-luftballons.txt'],
100
- });
101
- const commitMessages = getCommitMessages(commits);
102
- expect(commitMessages).toEqual([
103
- 'Edit all lyrics',
104
- 'Add "99 Luftballons"',
105
- ]);
106
- });
107
- it('only returns commits related to "take-on-me.txt"', async () => {
108
- const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
109
- ...getOptions(),
110
- commitPaths: ['lyrics/take-on-me.txt'],
111
- });
112
- const commitMessages = getCommitMessages(commits);
113
- expect(commitMessages).toEqual([
114
- 'Edit all lyrics',
115
- 'Edit "Take on me"',
116
- 'Add "Take on me"',
117
- ]);
118
- });
119
- it('removes duplicates and order by `committedDate`', async () => {
120
- const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
121
- ...getOptions(),
122
- commitPaths: [
123
- 'lyrics/99-luftballons.txt',
124
- 'lyrics/take-on-me.txt',
125
- 'lyrics/bohemian-rhapsody.txt',
126
- ],
127
- });
128
- const commitMessages = getCommitMessages(commits);
129
- expect(commitMessages).toEqual([
130
- 'Edit all lyrics',
131
- 'Edit "Take on me"',
132
- 'Add "Bohemian Rhapsody""',
133
- 'Add "99 Luftballons"',
134
- 'Add "Take on me"',
135
- ]);
136
- });
137
- });
138
- describe('expectedTargetPullRequests', () => {
139
- let res;
140
- beforeEach(async () => {
141
- res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
142
- accessToken,
143
- commitPaths: [],
144
- maxNumber: 10,
145
- repoName: 'backport-e2e',
146
- repoOwner: 'backport-org',
147
- sourceBranch: 'master',
148
- author: null,
149
- dateSince: null,
150
- dateUntil: null,
151
- });
152
- });
153
- it('returns related OPEN PRs', async () => {
154
- const commitWithOpenPR = res.find((commit) => commit.sourcePullRequest?.number === 9);
155
- expect(commitWithOpenPR?.expectedTargetPullRequests).toEqual([
156
- {
157
- branch: '7.8',
158
- state: 'OPEN',
159
- number: 10,
160
- url: 'https://github.com/backport-org/backport-e2e/pull/10',
161
- },
162
- ]);
163
- });
164
- it('returns related MERGED PRs', async () => {
165
- const commitWithMergedPRs = res.find((commit) => commit.sourcePullRequest?.number === 5);
166
- expect(commitWithMergedPRs?.expectedTargetPullRequests).toEqual([
167
- {
168
- branch: '7.x',
169
- state: 'MERGED',
170
- number: 6,
171
- url: 'https://github.com/backport-org/backport-e2e/pull/6',
172
- mergeCommit: {
173
- message: 'Add 🍏 emoji (#5) (#6)',
174
- sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
175
- },
176
- },
177
- {
178
- branch: '7.8',
179
- state: 'MERGED',
180
- number: 7,
181
- url: 'https://github.com/backport-org/backport-e2e/pull/7',
182
- mergeCommit: {
183
- message: 'Add 🍏 emoji (#5) (#7)',
184
- sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
185
- },
186
- },
187
- ]);
188
- });
189
- it('returns missing pull requests', async () => {
190
- const commitWithoutPRs = res.find((commit) => commit.sourcePullRequest?.number === 8);
191
- expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([
192
- { branch: '7.x', state: 'NOT_CREATED' },
193
- ]);
194
- });
195
- });
196
- });