backport 8.0.0 → 8.1.0

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 (205) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +41 -42
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +4 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +58 -0
  18. package/dist/lib/env.d.ts +7 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +206 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +4 -2
  151. package/dist/options/cliArgs.d.ts +15 -12
  152. package/dist/options/cliArgs.js +34 -19
  153. package/dist/options/cliArgs.test.js +125 -1
  154. package/dist/options/config/config.d.ts +5 -4
  155. package/dist/options/config/config.js +3 -5
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +3 -1
  158. package/dist/options/config/globalConfig.js +5 -5
  159. package/dist/options/config/readConfigFile.d.ts +9 -7
  160. package/dist/options/config/readConfigFile.js +2 -2
  161. package/dist/options/options.d.ts +43 -7
  162. package/dist/options/options.js +20 -24
  163. package/dist/options/options.test.js +112 -54
  164. package/dist/runSequentially.d.ts +10 -7
  165. package/dist/runSequentially.js +5 -5
  166. package/dist/scripts/postinstall.js +3 -3
  167. package/dist/scripts/postinstall.test.js +1 -1
  168. package/dist/services/BackportError.d.ts +19 -0
  169. package/dist/services/BackportError.js +29 -0
  170. package/dist/services/HandledBackportError.d.ts +19 -0
  171. package/dist/services/HandledBackportError.js +29 -0
  172. package/dist/services/HandledError.d.ts +1 -1
  173. package/dist/services/HandledError.js +5 -5
  174. package/dist/services/git.js +7 -7
  175. package/dist/services/github/v3/createPullRequest.js +2 -2
  176. package/dist/services/github/v3/createStatusComment.js +2 -2
  177. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  178. package/dist/services/github/v4/apiRequestV4.js +2 -2
  179. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  180. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  181. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  182. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  183. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  184. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  185. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  186. package/dist/state.d.ts +0 -0
  187. package/dist/state.js +1 -0
  188. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  189. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  190. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
  191. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
  192. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  193. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  194. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  195. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  196. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  197. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  199. package/dist/ui/getCommits.js +2 -2
  200. package/dist/ui/getTargetBranches.js +3 -3
  201. package/dist/ui/setupRepo.js +2 -2
  202. package/dist/utils/packageVersion.d.ts +1 -1
  203. package/dist/utils/packageVersion.js +1 -1
  204. package/package.json +12 -12
  205. package/yarn.lock +112 -65
@@ -0,0 +1,157 @@
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
+ });
@@ -0,0 +1,107 @@
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
+ });
@@ -0,0 +1,12 @@
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[]>;
@@ -0,0 +1,69 @@
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;
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,64 @@
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
+ }
@@ -0,0 +1,44 @@
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
+ });
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../../../options/options';
2
+ export declare function fetchPullRequestAutoMergeMethod(options: ValidConfigOptions, pullNumber: number): Promise<string | undefined>;
@@ -0,0 +1,39 @@
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;
@@ -0,0 +1,8 @@
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>;
@@ -0,0 +1,49 @@
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;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
5
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
+ describe('fetchRemoteProjectConfig', () => {
7
+ it('returns the backport config from "main" branch', async () => {
8
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
9
+ repoOwner: 'backport-org',
10
+ repoName: 'repo-with-project-config',
11
+ accessToken,
12
+ sourceBranch: 'main',
13
+ });
14
+ expect(projectConfig).toEqual({
15
+ autoMerge: true,
16
+ autoMergeMethod: 'squash',
17
+ branchLabelMapping: {
18
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
19
+ '^v8.1.0$': 'main',
20
+ },
21
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
22
+ targetPRLabels: ['backport'],
23
+ repoOwner: 'backport-org',
24
+ repoName: 'repo-with-project-config',
25
+ });
26
+ });
27
+ it('returns the backport config from "branch-with-legacy-config" branch', async () => {
28
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
29
+ repoOwner: 'backport-org',
30
+ repoName: 'repo-with-project-config',
31
+ accessToken,
32
+ sourceBranch: 'branch-with-legacy-config',
33
+ });
34
+ expect(projectConfig).toEqual({
35
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
36
+ repoOwner: 'backport-org',
37
+ repoName: 'repo-with-project-config',
38
+ });
39
+ });
40
+ it('throws an error if config does not exist', async () => {
41
+ const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
42
+ repoOwner: 'backport-org',
43
+ repoName: 'repo-with-project-config',
44
+ accessToken,
45
+ sourceBranch: 'branch-with-no-config',
46
+ });
47
+ await expect(promise).rejects.toThrowError('Project config does not exist');
48
+ });
49
+ });