backport 8.3.1 → 8.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +11 -178
  2. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +42 -21
  3. package/dist/lib/child-process-promisified.js +2 -2
  4. package/dist/lib/git.d.ts +4 -3
  5. package/dist/lib/git.js +22 -29
  6. package/dist/lib/git.private.test.js +10 -7
  7. package/dist/lib/git.test.js +47 -15
  8. package/dist/lib/github/v4/apiRequestV4.js +14 -8
  9. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  10. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  11. package/dist/lib/ora.d.ts +1 -0
  12. package/dist/options/ConfigOptions.d.ts +1 -0
  13. package/dist/options/cliArgs.d.ts +1 -0
  14. package/dist/options/cliArgs.js +5 -0
  15. package/dist/options/config/config.d.ts +1 -0
  16. package/dist/options/config/readConfigFile.d.ts +1 -0
  17. package/dist/options/options.d.ts +2 -0
  18. package/dist/options/options.js +3 -2
  19. package/dist/options/options.test.js +5 -4
  20. package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
  21. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
  22. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  23. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
  24. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  25. package/dist/{entrypoint.cli.private.test.d.ts → test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts} +0 -0
  26. package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
  27. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  28. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts} +0 -0
  29. package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
  30. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  31. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  32. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
  33. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  34. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  35. package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
  36. package/dist/test/replaceStringAndLinebreaks.js +8 -0
  37. package/dist/test/sandbox.js +6 -2
  38. package/dist/utils/packageVersion.d.ts +1 -1
  39. package/dist/utils/packageVersion.js +1 -1
  40. package/package.json +23 -24
  41. package/yarn.lock +841 -950
  42. package/dist/entrypoint.cli.private.test.js +0 -47
  43. package/dist/errors/BackportError.d.ts +0 -19
  44. package/dist/errors/BackportError.js +0 -29
  45. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  46. package/dist/runSequentially.test.d.ts +0 -1
  47. package/dist/runSequentially.test.js +0 -243
  48. package/dist/services/BackportError.d.ts +0 -19
  49. package/dist/services/BackportError.js +0 -29
  50. package/dist/services/HandledBackportError.d.ts +0 -19
  51. package/dist/services/HandledBackportError.js +0 -29
  52. package/dist/services/HandledError.d.ts +0 -19
  53. package/dist/services/HandledError.js +0 -29
  54. package/dist/services/child-process-promisified.d.ts +0 -25
  55. package/dist/services/child-process-promisified.js +0 -58
  56. package/dist/services/env.d.ts +0 -7
  57. package/dist/services/env.js +0 -30
  58. package/dist/services/env.test.d.ts +0 -1
  59. package/dist/services/env.test.js +0 -21
  60. package/dist/services/git.d.ts +0 -77
  61. package/dist/services/git.integration.test.d.ts +0 -1
  62. package/dist/services/git.integration.test.js +0 -616
  63. package/dist/services/git.js +0 -439
  64. package/dist/services/git.private.test.d.ts +0 -1
  65. package/dist/services/git.private.test.js +0 -618
  66. package/dist/services/git.test.d.ts +0 -1
  67. package/dist/services/git.test.js +0 -580
  68. package/dist/services/github/commitFormatters.d.ts +0 -3
  69. package/dist/services/github/commitFormatters.js +0 -17
  70. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  71. package/dist/services/github/commitFormatters.test.js +0 -11
  72. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  73. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  74. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  75. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  76. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  77. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  78. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  79. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  80. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  81. package/dist/services/github/v3/createPullRequest.js +0 -91
  82. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  83. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  84. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  85. package/dist/services/github/v3/createStatusComment.js +0 -131
  86. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  87. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  88. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  89. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  90. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  91. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  92. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  93. package/dist/services/github/v4/apiRequestV4.js +0 -71
  94. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  95. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  96. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  97. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  98. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  99. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  100. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  101. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  102. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  103. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  113. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  114. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  117. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  124. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  126. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  127. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  128. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  129. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  130. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  131. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  132. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  134. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  135. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  136. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  137. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  138. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  142. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  143. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  144. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  145. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  146. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  148. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  149. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  150. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  151. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  152. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  153. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  154. package/dist/services/logger.d.ts +0 -9
  155. package/dist/services/logger.js +0 -74
  156. package/dist/services/prompt.test.d.ts +0 -1
  157. package/dist/services/prompt.test.js +0 -139
  158. package/dist/services/prompts.d.ts +0 -17
  159. package/dist/services/prompts.js +0 -132
  160. package/dist/services/remoteConfig.d.ts +0 -20
  161. package/dist/services/remoteConfig.js +0 -52
  162. package/dist/services/sequentially.d.ts +0 -1
  163. package/dist/services/sequentially.js +0 -10
  164. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  165. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  166. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  168. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  169. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  170. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  171. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  172. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  173. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  174. package/dist/services/test.d.ts +0 -1
  175. package/dist/services/test.js +0 -23
  176. package/dist/state.d.ts +0 -0
  177. package/dist/state.js +0 -1
  178. package/dist/test/ExecError.d.ts +0 -16
  179. package/dist/test/ExecError.js +0 -15
  180. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  181. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  182. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  183. package/dist/test/e2e/cli/date-filters.js +0 -43
  184. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  185. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  186. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  187. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  188. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  189. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  190. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  191. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  192. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  193. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  194. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  195. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  196. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  197. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  199. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  200. package/dist/ui/getCommits.d.ts +0 -2
  201. package/dist/ui/getCommits.js +0 -75
  202. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  203. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  204. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  205. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  206. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  207. package/dist/ui/getGitConfigAuthor.js +0 -15
  208. package/dist/ui/getTargetBranches.d.ts +0 -5
  209. package/dist/ui/getTargetBranches.js +0 -67
  210. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  211. package/dist/ui/getTargetBranches.test.js +0 -204
  212. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  213. package/dist/ui/maybeSetupRepo.js +0 -53
  214. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  215. package/dist/ui/maybeSetupRepo.test.js +0 -238
  216. package/dist/ui/ora.d.ts +0 -2
  217. package/dist/ui/ora.js +0 -21
  218. package/dist/ui/setupRepo.d.ts +0 -2
  219. package/dist/ui/setupRepo.js +0 -56
  220. package/dist/ui/setupRepo.test.d.ts +0 -1
  221. package/dist/ui/setupRepo.test.js +0 -273
  222. package/dist/utils/filterMissingCommits.d.ts +0 -2
  223. package/dist/utils/filterMissingCommits.js +0 -7
  224. package/dist/utils/redact.d.ts +0 -1
  225. package/dist/utils/redact.js +0 -7
@@ -1,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
- });