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,157 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const nock_1 = __importDefault(require("nock"));
7
- const nockHelpers_1 = require("../../../../test/nockHelpers");
8
- const commitsByAuthorMock_1 = require("../mocks/commitsByAuthorMock");
9
- const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
10
- const defaultOptions = {
11
- accessToken: 'myAccessToken',
12
- author: 'sqren',
13
- githubApiBaseUrlV4: 'http://localhost/graphql',
14
- maxNumber: 10,
15
- repoName: 'kibana',
16
- repoOwner: 'elastic',
17
- sourceBranch: 'source-branch-from-options',
18
- dateSince: null,
19
- dateUntil: null,
20
- };
21
- const authorIdMockData = { user: { id: 'myUserId' } };
22
- describe('fetchCommitsByAuthor', () => {
23
- beforeEach(() => {
24
- jest.clearAllMocks();
25
- });
26
- afterEach(() => {
27
- nock_1.default.cleanAll();
28
- });
29
- describe('when commit has an associated pull request', () => {
30
- let res;
31
- let authorIdCalls;
32
- let commitsByAuthorCalls;
33
- beforeEach(async () => {
34
- authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
35
- name: 'AuthorId',
36
- statusCode: 200,
37
- body: { data: authorIdMockData },
38
- });
39
- commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
40
- name: 'CommitsByAuthor',
41
- statusCode: 200,
42
- body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
43
- });
44
- res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
45
- });
46
- it('should return a list of commits with pullNumber and existing backports', () => {
47
- const expectedCommits = [
48
- {
49
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
50
- sourceCommit: {
51
- committedDate: '2021-12-24T00:00:00Z',
52
- sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
53
- message: 'Add 👻',
54
- },
55
- expectedTargetPullRequests: [],
56
- sourceBranch: 'source-branch-from-options',
57
- },
58
- {
59
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
60
- sourceCommit: {
61
- committedDate: '2021-12-23T00:00:00Z',
62
- sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
63
- message: 'Add witch (#85)',
64
- },
65
- sourcePullRequest: {
66
- number: 85,
67
- url: 'https://github.com/elastic/kibana/pull/85',
68
- mergeCommit: {
69
- sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
70
- message: 'Add witch (#85)',
71
- },
72
- },
73
- expectedTargetPullRequests: [],
74
- sourceBranch: 'master',
75
- },
76
- {
77
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
78
- sourceCommit: {
79
- committedDate: '2021-12-22T00:00:00Z',
80
- sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
81
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
82
- },
83
- sourcePullRequest: {
84
- number: 80,
85
- url: 'https://github.com/elastic/kibana/pull/80',
86
- mergeCommit: {
87
- sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
88
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
89
- },
90
- },
91
- expectedTargetPullRequests: [
92
- {
93
- branch: '6.3',
94
- state: 'MERGED',
95
- number: 99,
96
- url: 'https://github.com/elastic/kibana/pull/99',
97
- mergeCommit: {
98
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
99
- sha: 'target-merge-commit-sha',
100
- },
101
- },
102
- ],
103
- sourceBranch: 'master',
104
- },
105
- {
106
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
107
- sourceCommit: {
108
- committedDate: '2021-12-21T00:00:00Z',
109
- sha: '3827bbbaf39914eda4f02f6940189844375fd097',
110
- message: 'Add backport config',
111
- },
112
- expectedTargetPullRequests: [],
113
- sourceBranch: 'source-branch-from-options',
114
- },
115
- {
116
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
117
- sourceCommit: {
118
- committedDate: '2021-12-20T00:00:00Z',
119
- sha: '5ea0da550ac191029459289d67f99ad7d310812b',
120
- message: 'Initial commit',
121
- },
122
- expectedTargetPullRequests: [],
123
- sourceBranch: 'source-branch-from-options',
124
- },
125
- ];
126
- expect(res).toEqual(expectedCommits);
127
- });
128
- it('should call with correct args to fetch author id', () => {
129
- expect(authorIdCalls).toMatchSnapshot();
130
- });
131
- it('should call with correct args to fetch commits', () => {
132
- expect(commitsByAuthorCalls).toMatchSnapshot();
133
- });
134
- });
135
- describe('when a custom github api hostname is supplied', () => {
136
- it('should be used in gql requests', async () => {
137
- const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
138
- name: 'AuthorId',
139
- statusCode: 200,
140
- body: { data: authorIdMockData },
141
- apiBaseUrl: 'http://localhost/my-custom-api',
142
- });
143
- const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
144
- name: 'CommitsByAuthor',
145
- statusCode: 200,
146
- body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
147
- apiBaseUrl: 'http://localhost/my-custom-api',
148
- });
149
- await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
150
- ...defaultOptions,
151
- githubApiBaseUrlV4: 'http://localhost/my-custom-api',
152
- });
153
- expect(authorIdCalls.length).toBe(1);
154
- expect(commitsByAuthorCalls.length).toBe(1);
155
- });
156
- });
157
- });
@@ -1,3 +0,0 @@
1
- import { ValidConfigOptions } from '../../../../options/options';
2
- import { Commit } from '../../../sourceCommit/parseSourceCommit';
3
- export declare function fetchPullRequestsBySearchQuery(options: ValidConfigOptions): Promise<Commit[]>;
@@ -1,61 +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.fetchPullRequestsBySearchQuery = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const lodash_1 = require("lodash");
9
- const HandledError_1 = require("../../../HandledError");
10
- const remoteConfig_1 = require("../../../remoteConfig");
11
- const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
12
- const apiRequestV4_1 = require("../apiRequestV4");
13
- async function fetchPullRequestsBySearchQuery(options) {
14
- const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
15
- const query = (0, graphql_tag_1.default) `
16
- query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
17
- search(query: $query, type: ISSUE, first: $maxNumber) {
18
- nodes {
19
- ... on PullRequest {
20
- mergeCommit {
21
- ...SourceCommitWithTargetPullRequestFragment
22
- }
23
- }
24
- }
25
- }
26
- }
27
-
28
- ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
29
- `;
30
- const authorFilter = author ? ` author:${author}` : '';
31
- const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
32
- const variables = {
33
- query: searchQuery,
34
- maxNumber: maxNumber,
35
- };
36
- let res;
37
- try {
38
- res = await (0, apiRequestV4_1.apiRequestV4)({
39
- githubApiBaseUrlV4,
40
- accessToken,
41
- query,
42
- variables,
43
- });
44
- }
45
- catch (e) {
46
- res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
47
- }
48
- const commits = res.search.nodes.map((pullRequestNode) => {
49
- const sourceCommit = pullRequestNode.mergeCommit;
50
- return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
51
- });
52
- // terminate if not commits were found
53
- if ((0, lodash_1.isEmpty)(commits)) {
54
- const errorText = options.author
55
- ? `There are no commits by "${options.author}" matching the filter "${prFilter}". Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`
56
- : `There are no pull requests matching the filter "${prFilter}"`;
57
- throw new HandledError_1.HandledError(errorText);
58
- }
59
- return commits;
60
- }
61
- exports.fetchPullRequestsBySearchQuery = fetchPullRequestsBySearchQuery;
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
- const fetchPullRequestsBySearchQuery_1 = require("./fetchPullRequestsBySearchQuery");
5
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
- describe('fetchPullRequestsBySearchQuery', () => {
7
- describe('when filter does not match any PRs', () => {
8
- it('throws an error', async () => {
9
- const options = {
10
- accessToken,
11
- maxNumber: 10,
12
- prFilter: 'label:non-existing',
13
- repoName: 'backport-e2e',
14
- repoOwner: 'backport-org',
15
- sourceBranch: 'master',
16
- author: 'sqren',
17
- };
18
- await expect((0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)(options)).rejects
19
- .toThrowErrorMatchingInlineSnapshot(`
20
- "No commits found for query:
21
- type:pr is:merged sort:updated-desc repo:backport-org/backport-e2e author:sqren base:master label:non-existing
22
-
23
- Use \`--all\` to see commits by all users or \`--author=<username>\` for commits from a specific user"
24
- `);
25
- });
26
- });
27
- describe('when filter matches PRs', () => {
28
- it('returns the merge commits for those PRs', async () => {
29
- const options = {
30
- accessToken,
31
- maxNumber: 10,
32
- prFilter: 'label:v7.8.0',
33
- repoName: 'backport-e2e',
34
- repoOwner: 'backport-org',
35
- sourceBranch: 'master',
36
- author: 'sqren',
37
- };
38
- const expectedCommits = [
39
- {
40
- author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
41
- sourceCommit: {
42
- committedDate: '2020-08-16T21:44:28Z',
43
- message: 'Add sheep emoji (#9)',
44
- sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
45
- },
46
- sourcePullRequest: {
47
- number: 9,
48
- url: 'https://github.com/backport-org/backport-e2e/pull/9',
49
- mergeCommit: {
50
- message: 'Add sheep emoji (#9)',
51
- sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
52
- },
53
- },
54
- sourceBranch: 'master',
55
- expectedTargetPullRequests: [
56
- {
57
- branch: '7.8',
58
- state: 'OPEN',
59
- number: 10,
60
- url: 'https://github.com/backport-org/backport-e2e/pull/10',
61
- },
62
- ],
63
- },
64
- {
65
- author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
66
- sourceCommit: {
67
- committedDate: '2020-08-15T12:40:19Z',
68
- message: 'Add 🍏 emoji (#5)',
69
- sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
70
- },
71
- sourcePullRequest: {
72
- number: 5,
73
- url: 'https://github.com/backport-org/backport-e2e/pull/5',
74
- mergeCommit: {
75
- message: 'Add 🍏 emoji (#5)',
76
- sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
77
- },
78
- },
79
- sourceBranch: 'master',
80
- expectedTargetPullRequests: [
81
- {
82
- branch: '7.x',
83
- state: 'MERGED',
84
- number: 6,
85
- url: 'https://github.com/backport-org/backport-e2e/pull/6',
86
- mergeCommit: {
87
- message: 'Add 🍏 emoji (#5) (#6)',
88
- sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
89
- },
90
- },
91
- {
92
- branch: '7.8',
93
- state: 'MERGED',
94
- number: 7,
95
- url: 'https://github.com/backport-org/backport-e2e/pull/7',
96
- mergeCommit: {
97
- message: 'Add 🍏 emoji (#5) (#7)',
98
- sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
99
- },
100
- },
101
- ],
102
- },
103
- ];
104
- expect(await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)(options)).toEqual(expectedCommits);
105
- });
106
- });
107
- });
@@ -1,12 +0,0 @@
1
- import { Commit } from '../../../sourceCommit/parseSourceCommit';
2
- export declare function fetchPullRequestsBySearchQuery(options: {
3
- accessToken: string;
4
- author: string | null;
5
- githubApiBaseUrlV4?: string;
6
- maxNumber?: number;
7
- onlyMissing?: boolean;
8
- prFilter: string;
9
- repoName: string;
10
- repoOwner: string;
11
- sourceBranch: string;
12
- }): Promise<Commit[]>;
@@ -1,69 +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.fetchPullRequestsBySearchQuery = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const lodash_1 = require("lodash");
9
- const filterUnmergedCommits_1 = require("../../../../utils/filterUnmergedCommits");
10
- const BackportError_1 = require("../../../BackportError");
11
- const remoteConfig_1 = require("../../../remoteConfig");
12
- const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
13
- const apiRequestV4_1 = require("../apiRequestV4");
14
- async function fetchPullRequestsBySearchQuery(options) {
15
- const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
16
- const query = (0, graphql_tag_1.default) `
17
- query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
18
- search(query: $query, type: ISSUE, first: $maxNumber) {
19
- nodes {
20
- ... on PullRequest {
21
- mergeCommit {
22
- ...SourceCommitWithTargetPullRequestFragment
23
- }
24
- }
25
- }
26
- }
27
- }
28
-
29
- ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
30
- `;
31
- const authorFilter = options.author ? ` author:${options.author}` : '';
32
- const sourceBranchFilter = prFilter.includes('base:')
33
- ? ''
34
- : ` base:${sourceBranch}`;
35
- const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter}${sourceBranchFilter} ${prFilter} `;
36
- const variables = {
37
- query: searchQuery,
38
- maxNumber,
39
- };
40
- let res;
41
- try {
42
- res = await (0, apiRequestV4_1.apiRequestV4)({
43
- githubApiBaseUrlV4,
44
- accessToken,
45
- query,
46
- variables,
47
- });
48
- }
49
- catch (e) {
50
- //@ts-expect-error
51
- res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
52
- }
53
- const commits = res.search.nodes.map((pullRequestNode) => {
54
- const sourceCommit = pullRequestNode.mergeCommit;
55
- return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
56
- });
57
- // terminate if not commits were found
58
- if ((0, lodash_1.isEmpty)(commits)) {
59
- const errorText = author
60
- ? `No commits found for query:\n ${searchQuery}\n\nUse \`--all\` to see commits by all users or \`--author=<username>\` for commits from a specific user`
61
- : `No commits found for query:\n ${searchQuery}`;
62
- throw new BackportError_1.BackportError(errorText);
63
- }
64
- if (options.onlyMissing) {
65
- return commits.filter(filterUnmergedCommits_1.filterUnmergedCommits);
66
- }
67
- return commits;
68
- }
69
- exports.fetchPullRequestsBySearchQuery = fetchPullRequestsBySearchQuery;
@@ -1,9 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- import { PullRequestPayload } from '../v3/createPullRequest';
3
- export declare function fetchExistingPullRequest({ options, prPayload, }: {
4
- options: ValidConfigOptions;
5
- prPayload: PullRequestPayload;
6
- }): Promise<{
7
- url: string;
8
- number: number;
9
- } | undefined>;
@@ -1,64 +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.fetchExistingPullRequest = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const apiRequestV4_1 = require("./apiRequestV4");
9
- async function fetchExistingPullRequest({ options, prPayload, }) {
10
- const { githubApiBaseUrlV4, accessToken } = options;
11
- const query = (0, graphql_tag_1.default) `
12
- query ExistingPullRequest(
13
- $repoOwner: String!
14
- $repoName: String!
15
- $base: String!
16
- $head: String!
17
- ) {
18
- repository(owner: $repoOwner, name: $repoName) {
19
- name
20
- ref(qualifiedName: $head) {
21
- name
22
- associatedPullRequests(
23
- first: 1
24
- states: OPEN
25
- baseRefName: $base
26
- headRefName: $head
27
- ) {
28
- edges {
29
- node {
30
- number
31
- url
32
- }
33
- }
34
- }
35
- }
36
- }
37
- }
38
- `;
39
- const { repoForkOwner, head } = splitHead(prPayload);
40
- const res = await (0, apiRequestV4_1.apiRequestV4)({
41
- githubApiBaseUrlV4,
42
- accessToken,
43
- query,
44
- variables: {
45
- repoOwner: repoForkOwner,
46
- repoName: prPayload.repo,
47
- base: prPayload.base,
48
- head: head,
49
- },
50
- });
51
- const existingPullRequest = res.repository.ref?.associatedPullRequests.edges[0];
52
- if (!existingPullRequest) {
53
- return;
54
- }
55
- return {
56
- url: existingPullRequest.node.url,
57
- number: existingPullRequest.node.number,
58
- };
59
- }
60
- exports.fetchExistingPullRequest = fetchExistingPullRequest;
61
- function splitHead(prPayload) {
62
- const [repoForkOwner, head] = prPayload.head.split(':');
63
- return { repoForkOwner, head };
64
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
- const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
5
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
- describe('fetchExistingPullRequest', () => {
7
- describe('when PR does not exist', () => {
8
- it('returns undefined', async () => {
9
- const options = {
10
- accessToken,
11
- };
12
- const prPayload = {
13
- owner: 'backport-org',
14
- repo: 'backport-e2e',
15
- title: 'My PR title',
16
- body: 'My PR body',
17
- head: 'sqren:backport/7.8/pr-foo',
18
- base: '7.8',
19
- };
20
- const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
21
- expect(res).toBe(undefined);
22
- });
23
- });
24
- describe('when PR exists', () => {
25
- it('returns the PR number and url', async () => {
26
- const options = {
27
- accessToken,
28
- };
29
- const prPayload = {
30
- owner: 'backport-org',
31
- repo: 'backport-e2e',
32
- title: 'My PR title',
33
- body: 'My PR body',
34
- head: 'sqren:backport/7.8/pr-9',
35
- base: '7.8',
36
- };
37
- const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
38
- expect(res).toEqual({
39
- url: 'https://github.com/backport-org/backport-e2e/pull/10',
40
- number: 10,
41
- });
42
- });
43
- });
44
- });
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../../../options/options';
2
- export declare function fetchPullRequestAutoMergeMethod(options: ValidConfigOptions, pullNumber: number): Promise<string | undefined>;
@@ -1,39 +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.fetchPullRequestAutoMergeMethod = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const apiRequestV4_1 = require("./apiRequestV4");
9
- async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
10
- const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
11
- const query = (0, graphql_tag_1.default) `
12
- query PullRequestAutoMergeMethod(
13
- $repoOwner: String!
14
- $repoName: String!
15
- $pullNumber: Int!
16
- ) {
17
- repository(owner: $repoOwner, name: $repoName) {
18
- pullRequest(number: $pullNumber) {
19
- autoMergeRequest {
20
- enabledAt
21
- mergeMethod
22
- }
23
- }
24
- }
25
- }
26
- `;
27
- const res = await (0, apiRequestV4_1.apiRequestV4)({
28
- githubApiBaseUrlV4,
29
- accessToken,
30
- query,
31
- variables: {
32
- repoOwner,
33
- repoName,
34
- pullNumber,
35
- },
36
- });
37
- return res.repository.pullRequest?.autoMergeRequest?.mergeMethod;
38
- }
39
- exports.fetchPullRequestAutoMergeMethod = fetchPullRequestAutoMergeMethod;
@@ -1,8 +0,0 @@
1
- import { ConfigFileOptions } from '../../../entrypoint.module';
2
- export declare function fetchRemoteProjectConfig(options: {
3
- accessToken: string;
4
- githubApiBaseUrlV4?: string;
5
- repoName: string;
6
- repoOwner: string;
7
- sourceBranch: string;
8
- }): Promise<ConfigFileOptions | undefined>;
@@ -1,49 +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.fetchRemoteProjectConfig = void 0;
7
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
- const remoteConfig_1 = require("../../remoteConfig");
9
- const apiRequestV4_1 = require("./apiRequestV4");
10
- async function fetchRemoteProjectConfig(options) {
11
- const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
12
- const query = (0, graphql_tag_1.default) `
13
- query ProjectConfig(
14
- $repoOwner: String!
15
- $repoName: String!
16
- $sourceBranch: String!
17
- ) {
18
- repository(owner: $repoOwner, name: $repoName) {
19
- ref(qualifiedName: $sourceBranch) {
20
- target {
21
- ...RemoteConfigHistoryFragment
22
- }
23
- }
24
- }
25
- }
26
-
27
- ${remoteConfig_1.RemoteConfigHistoryFragment}
28
- `;
29
- try {
30
- const res = await (0, apiRequestV4_1.apiRequestV4)({
31
- githubApiBaseUrlV4,
32
- accessToken,
33
- query,
34
- variables: {
35
- repoOwner,
36
- repoName,
37
- sourceBranch,
38
- },
39
- });
40
- const remoteConfig = res.repository.ref.target.remoteConfigHistory.edges?.[0].remoteConfig;
41
- if (remoteConfig) {
42
- return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
43
- }
44
- }
45
- catch (e) {
46
- throw new Error('Project config does not exist');
47
- }
48
- }
49
- exports.fetchRemoteProjectConfig = fetchRemoteProjectConfig;