backport 5.6.4 → 6.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 (253) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +33 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +56 -39
  12. package/dist/options/cliArgs.d.ts +38 -45
  13. package/dist/options/cliArgs.js +123 -104
  14. package/dist/options/cliArgs.test.js +106 -119
  15. package/dist/options/config/config.d.ts +56 -2
  16. package/dist/options/config/config.js +12 -6
  17. package/dist/options/config/config.test.js +11 -6
  18. package/dist/options/config/getOptionsFromGit.d.ts +4 -0
  19. package/dist/options/config/getOptionsFromGit.js +8 -0
  20. package/dist/options/config/globalConfig.d.ts +2 -1
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -1
  24. package/dist/options/config/projectConfig.js +3 -3
  25. package/dist/options/config/projectConfig.test.js +54 -17
  26. package/dist/options/config/readConfigFile.d.ts +53 -2
  27. package/dist/options/config/readConfigFile.js +31 -5
  28. package/dist/options/options.d.ts +67 -35
  29. package/dist/options/options.js +99 -16
  30. package/dist/options/options.test.js +214 -67
  31. package/dist/options/parseRequiredOptions.d.ts +71 -0
  32. package/dist/options/parseRequiredOptions.js +68 -0
  33. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  34. package/dist/options/parseRequiredOptions.test.js +122 -0
  35. package/dist/runSequentially.d.ts +20 -0
  36. package/dist/runSequentially.js +41 -0
  37. package/dist/runSequentially.test.d.ts +1 -0
  38. package/dist/runSequentially.test.js +192 -0
  39. package/dist/runWithOptions.js +7 -14
  40. package/dist/runWithOptions.test.js +142 -16
  41. package/dist/scripts/generate-gql.d.ts +1 -0
  42. package/dist/scripts/generate-gql.js +15 -0
  43. package/dist/scripts/postinstall.js +4 -4
  44. package/dist/scripts/postinstall.test.js +9 -2
  45. package/dist/scripts/runPostinstall.js +1 -1
  46. package/dist/services/HandledError.d.ts +11 -1
  47. package/dist/services/HandledError.js +2 -1
  48. package/dist/services/child-process-promisified.d.ts +1 -1
  49. package/dist/services/child-process-promisified.js +2 -2
  50. package/dist/services/env.js +5 -5
  51. package/dist/services/env.test.js +11 -4
  52. package/dist/services/fs-promisified.js +4 -4
  53. package/dist/services/getExpectedTarget.d.ts +9 -0
  54. package/dist/services/getExpectedTarget.js +77 -0
  55. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  56. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  57. package/dist/services/git.d.ts +23 -5
  58. package/dist/services/git.integration.test.d.ts +1 -0
  59. package/dist/services/git.integration.test.js +168 -0
  60. package/dist/services/git.js +133 -60
  61. package/dist/services/git.test.js +160 -53
  62. package/dist/services/github/commitFormatters.d.ts +3 -7
  63. package/dist/services/github/commitFormatters.js +10 -19
  64. package/dist/services/github/commitFormatters.test.js +2 -24
  65. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  66. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  67. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  68. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  69. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  70. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  71. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  72. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  73. package/dist/services/github/v3/createPullRequest.js +32 -26
  74. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  75. package/dist/services/github/v3/createPullRequest.test.js +78 -0
  76. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  77. package/dist/services/github/v3/createStatusComment.js +97 -0
  78. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  79. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  80. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  81. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  82. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  83. package/dist/services/github/v4/apiRequestV4.js +9 -11
  84. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  86. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  91. package/dist/services/github/v4/fetchAuthorId.d.ts +10 -2
  92. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  93. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  95. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  96. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  97. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  115. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  121. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  122. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  123. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  124. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  125. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  126. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  127. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  132. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  133. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  134. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  135. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  136. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  137. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  138. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  139. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  140. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  141. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  142. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  143. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  144. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  145. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  146. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  147. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  148. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  149. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  150. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  151. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  152. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  153. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  154. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  155. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  156. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  157. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  158. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  159. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  160. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  161. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +63 -0
  162. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  163. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  164. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
  165. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
  166. package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
  167. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  168. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  169. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  170. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  171. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  172. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  173. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  174. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  175. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  176. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  177. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  178. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  179. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  180. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  181. package/dist/services/logger.d.ts +3 -3
  182. package/dist/services/logger.js +24 -24
  183. package/dist/services/prompt.test.d.ts +1 -0
  184. package/dist/services/prompt.test.js +87 -0
  185. package/dist/services/prompts.d.ts +10 -4
  186. package/dist/services/prompts.js +85 -22
  187. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  188. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  189. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  191. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  192. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  193. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  194. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  195. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  196. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  197. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  198. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  199. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  200. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  201. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  202. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  203. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  204. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  205. package/dist/services/sourceCommit.d.ts +78 -0
  206. package/dist/services/sourceCommit.js +86 -0
  207. package/dist/services/sourceCommit.test.d.ts +1 -0
  208. package/dist/services/sourceCommit.test.js +280 -0
  209. package/dist/test/inquirer.private.test.js +105 -61
  210. package/dist/test/integration/createSpies.d.ts +1 -1
  211. package/dist/test/integration/createSpies.js +21 -9
  212. package/dist/test/integration/envConstants.js +5 -6
  213. package/dist/test/integration/helpers.js +1 -1
  214. package/dist/test/integration/integration.private.test.d.ts +1 -0
  215. package/dist/test/integration/integration.private.test.js +317 -0
  216. package/dist/test/integration/integration.test.js +30 -31
  217. package/dist/test/mockConfigFiles.d.ts +5 -0
  218. package/dist/test/mockConfigFiles.js +37 -0
  219. package/dist/test/nockHelpers.d.ts +3 -3
  220. package/dist/test/nockHelpers.js +7 -11
  221. package/dist/test/private/getDevAccessToken.js +1 -1
  222. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  223. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  224. package/dist/types/Commit.d.ts +85 -0
  225. package/dist/types/Commit.js +139 -0
  226. package/dist/types/commitNode.d.ts +89 -0
  227. package/dist/types/commitNode.js +139 -0
  228. package/dist/types/commitNode.test.d.ts +1 -0
  229. package/dist/types/commitNode.test.js +255 -0
  230. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  231. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  232. package/dist/ui/cherrypickAndCreatePullRequest.test.js +333 -76
  233. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  234. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  235. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  236. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  237. package/dist/ui/getCommits.d.ts +1 -1
  238. package/dist/ui/getCommits.js +55 -25
  239. package/dist/ui/getTargetBranches.d.ts +3 -2
  240. package/dist/ui/getTargetBranches.js +33 -18
  241. package/dist/ui/getTargetBranches.test.js +75 -99
  242. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  243. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  244. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  245. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  246. package/dist/ui/maybeSetupRepo.js +11 -10
  247. package/dist/ui/maybeSetupRepo.test.js +54 -4
  248. package/dist/utils/excludeUndefined.d.ts +6 -0
  249. package/dist/utils/excludeUndefined.js +7 -0
  250. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  251. package/dist/utils/excludeUndefined.test.js +24 -0
  252. package/package.json +37 -51
  253. package/yarn.lock +2416 -2987
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
5
+ describe('fetchCommitByPullNumber', () => {
6
+ let devAccessToken;
7
+ beforeAll(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ describe('when PR was merged', () => {
11
+ it('is returned', async () => {
12
+ const options = {
13
+ accessToken: devAccessToken,
14
+ pullNumber: 5,
15
+ repoName: 'backport-e2e',
16
+ repoOwner: 'backport-org',
17
+ sourceBranch: 'main',
18
+ historicalBranchLabelMappings: [],
19
+ };
20
+ expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
21
+ committedDate: '2020-08-15T12:40:19Z',
22
+ originalMessage: 'Add 🍏 emoji (#5)',
23
+ pullNumber: 5,
24
+ pullUrl: 'https://github.com/backport-org/backport-e2e/pull/5',
25
+ sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
26
+ sourceBranch: 'master',
27
+ expectedTargetPullRequests: [
28
+ {
29
+ branch: '7.x',
30
+ state: 'MERGED',
31
+ number: 6,
32
+ url: 'https://github.com/backport-org/backport-e2e/pull/6',
33
+ },
34
+ {
35
+ branch: '7.8',
36
+ state: 'MERGED',
37
+ number: 7,
38
+ url: 'https://github.com/backport-org/backport-e2e/pull/7',
39
+ },
40
+ ],
41
+ });
42
+ });
43
+ });
44
+ describe('when PR is still open', () => {
45
+ it('throws an error', async () => {
46
+ const options = {
47
+ accessToken: devAccessToken,
48
+ pullNumber: 11,
49
+ repoName: 'backport-e2e',
50
+ repoOwner: 'backport-org',
51
+ sourceBranch: 'main',
52
+ historicalBranchLabelMappings: [],
53
+ };
54
+ await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
55
+ });
56
+ });
57
+ describe('when PR does not exist', () => {
58
+ it('throws an error', async () => {
59
+ const options = {
60
+ accessToken: devAccessToken,
61
+ pullNumber: 9999999999999,
62
+ repoName: 'backport-e2e',
63
+ repoOwner: 'backport-org',
64
+ sourceBranch: 'main',
65
+ historicalBranchLabelMappings: [],
66
+ };
67
+ await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,12 @@
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
+ historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
8
+ repoName: string;
9
+ repoOwner: string;
10
+ sha: string;
11
+ sourceBranch: string;
12
+ }): Promise<Commit>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchCommitBySha = void 0;
4
+ const HandledError_1 = require("../../../HandledError");
5
+ const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
+ const apiRequestV4_1 = require("../apiRequestV4");
7
+ async function fetchCommitBySha(options) {
8
+ const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
+ const query = /* GraphQL */ `
10
+ query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
11
+ repository(owner: $repoOwner, name: $repoName) {
12
+ object(expression: $oid) {
13
+ ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
14
+ }
15
+ }
16
+ }
17
+
18
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
19
+ `;
20
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
21
+ githubApiBaseUrlV4,
22
+ accessToken,
23
+ query,
24
+ variables: {
25
+ repoOwner,
26
+ repoName,
27
+ oid: sha,
28
+ },
29
+ });
30
+ const sourceCommit = res.repository.object;
31
+ if (!sourceCommit) {
32
+ throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
33
+ }
34
+ return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
35
+ }
36
+ exports.fetchCommitBySha = fetchCommitBySha;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitBySha_1 = require("./fetchCommitBySha");
5
+ describe('fetchCommitBySha', () => {
6
+ let devAccessToken;
7
+ beforeEach(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ it('should return single commit with pull request', async () => {
11
+ await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
12
+ repoOwner: 'elastic',
13
+ repoName: 'kibana',
14
+ accessToken: devAccessToken,
15
+ sha: 'cb6fbc0',
16
+ sourceBranch: 'master',
17
+ historicalBranchLabelMappings: [],
18
+ })).toEqual({
19
+ committedDate: '2020-07-07T20:40:28Z',
20
+ originalMessage: '[APM] Add API tests (#70740)',
21
+ pullNumber: 70740,
22
+ pullUrl: 'https://github.com/elastic/kibana/pull/70740',
23
+ sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
24
+ sourceBranch: 'master',
25
+ expectedTargetPullRequests: [
26
+ {
27
+ branch: '7.x',
28
+ state: 'MERGED',
29
+ number: 71014,
30
+ url: 'https://github.com/elastic/kibana/pull/71014',
31
+ },
32
+ ],
33
+ });
34
+ });
35
+ it('throws if sha does not exist', async () => {
36
+ await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
37
+ repoOwner: 'elastic',
38
+ repoName: 'kibana',
39
+ accessToken: devAccessToken,
40
+ sha: 'fc22f59',
41
+ sourceBranch: 'main',
42
+ historicalBranchLabelMappings: [],
43
+ })).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
44
+ });
45
+ it('throws if sha is invalid', async () => {
46
+ await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
47
+ repoOwner: 'elastic',
48
+ repoName: 'kibana',
49
+ accessToken: devAccessToken,
50
+ sha: 'myCommitSha',
51
+ sourceBranch: 'main',
52
+ historicalBranchLabelMappings: [],
53
+ })).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
54
+ });
55
+ });
@@ -0,0 +1,27 @@
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
+ githubApiBaseUrlV4?: string;
9
+ historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
10
+ maxNumber?: number;
11
+ repoName: string;
12
+ repoOwner: string;
13
+ sourceBranch: string;
14
+ }): Promise<Commit[]>;
15
+ export interface CommitByAuthorResponse {
16
+ repository: {
17
+ ref: {
18
+ target: {
19
+ history: {
20
+ edges: Array<{
21
+ node: SourceCommitWithTargetPullRequest;
22
+ }>;
23
+ };
24
+ };
25
+ } | null;
26
+ };
27
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchCommitsByAuthor = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const filterEmpty_1 = require("../../../../utils/filterEmpty");
6
+ const HandledError_1 = require("../../../HandledError");
7
+ const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
8
+ const apiRequestV4_1 = require("../apiRequestV4");
9
+ const fetchAuthorId_1 = require("../fetchAuthorId");
10
+ function fetchByCommitPath({ options, authorId, commitPath, }) {
11
+ const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, } = options;
12
+ const query = /* GraphQL */ `
13
+ query CommitsByAuthor(
14
+ $repoOwner: String!
15
+ $repoName: String!
16
+ $maxNumber: Int!
17
+ $sourceBranch: String!
18
+ $authorId: ID
19
+ $commitPath: String
20
+ ) {
21
+ repository(owner: $repoOwner, name: $repoName) {
22
+ ref(qualifiedName: $sourceBranch) {
23
+ target {
24
+ ... on Commit {
25
+ history(
26
+ first: $maxNumber
27
+ author: { id: $authorId }
28
+ path: $commitPath
29
+ ) {
30
+ edges {
31
+ node {
32
+ ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
43
+ `;
44
+ return (0, apiRequestV4_1.apiRequestV4)({
45
+ githubApiBaseUrlV4,
46
+ accessToken,
47
+ query,
48
+ variables: {
49
+ repoOwner,
50
+ repoName,
51
+ sourceBranch,
52
+ maxNumber,
53
+ authorId,
54
+ commitPath,
55
+ },
56
+ });
57
+ }
58
+ async function fetchCommitsByAuthor(options) {
59
+ const { sourceBranch, commitPaths = [] } = options;
60
+ const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
61
+ const responses = await Promise.all((0, lodash_1.isEmpty)(commitPaths)
62
+ ? [fetchByCommitPath({ options, authorId, commitPath: null })]
63
+ : commitPaths.map((commitPath) => fetchByCommitPath({ options, authorId, commitPath })));
64
+ // we only need to check if the first item is `null` (if the first is `null` they all are)
65
+ if (responses[0].repository.ref === null) {
66
+ throw new HandledError_1.HandledError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
67
+ }
68
+ const commits = responses
69
+ .flatMap((res) => {
70
+ return res.repository.ref?.target.history.edges.map((edge) => {
71
+ const sourceCommit = edge.node;
72
+ return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
73
+ });
74
+ })
75
+ .filter(filterEmpty_1.filterNil);
76
+ // terminate if not commits were found
77
+ if ((0, lodash_1.isEmpty)(commits)) {
78
+ const pathText = commitPaths.length > 0 ? ` touching files in path: "${commitPaths}"` : '';
79
+ const errorText = options.author
80
+ ? `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`
81
+ : `There are no commits in this repository${pathText}`;
82
+ throw new HandledError_1.HandledError(errorText);
83
+ }
84
+ const commitsUnique = (0, lodash_1.uniqBy)(commits, 'sha');
85
+ const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, 'committedDate', 'desc');
86
+ return commitsSorted;
87
+ }
88
+ exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
5
+ describe('fetchCommitsByAuthor', () => {
6
+ let devAccessToken;
7
+ beforeAll(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ describe('commitPaths', () => {
11
+ const getOptions = () => ({
12
+ accessToken: devAccessToken,
13
+ author: 'sqren',
14
+ historicalBranchLabelMappings: [],
15
+ maxNumber: 10,
16
+ repoName: 'repo-with-different-commit-paths',
17
+ repoOwner: 'backport-org',
18
+ sourceBranch: 'main',
19
+ });
20
+ const getCommitMessages = (commits) => {
21
+ return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
22
+ };
23
+ it('returns all commits', async () => {
24
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
25
+ ...getOptions(),
26
+ commitPaths: [],
27
+ });
28
+ const commitMessages = getCommitMessages(commits);
29
+ expect(commitMessages).toEqual([
30
+ 'Edit all lyrics',
31
+ 'Update .backportrc.json',
32
+ 'Edit "Take on me"',
33
+ 'Add backportrc.json',
34
+ 'Add "Bohemian Rhapsody""',
35
+ 'Add "99 Luftballons"',
36
+ 'Add "Take on me"',
37
+ ]);
38
+ });
39
+ it('only returns commits related to "99-luftballons.txt"', async () => {
40
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
41
+ ...getOptions(),
42
+ commitPaths: ['lyrics/99-luftballons.txt'],
43
+ });
44
+ const commitMessages = getCommitMessages(commits);
45
+ expect(commitMessages).toEqual([
46
+ 'Edit all lyrics',
47
+ 'Add "99 Luftballons"',
48
+ ]);
49
+ });
50
+ it('only returns commits related to "take-on-me.txt"', async () => {
51
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
52
+ ...getOptions(),
53
+ commitPaths: ['lyrics/take-on-me.txt'],
54
+ });
55
+ const commitMessages = getCommitMessages(commits);
56
+ expect(commitMessages).toEqual([
57
+ 'Edit all lyrics',
58
+ 'Edit "Take on me"',
59
+ 'Add "Take on me"',
60
+ ]);
61
+ });
62
+ it('removes duplicates and order by `committedDate`', async () => {
63
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
64
+ ...getOptions(),
65
+ commitPaths: [
66
+ 'lyrics/99-luftballons.txt',
67
+ 'lyrics/take-on-me.txt',
68
+ 'lyrics/bohemian-rhapsody.txt',
69
+ ],
70
+ });
71
+ const commitMessages = getCommitMessages(commits);
72
+ expect(commitMessages).toEqual([
73
+ 'Edit all lyrics',
74
+ 'Edit "Take on me"',
75
+ 'Add "Bohemian Rhapsody""',
76
+ 'Add "99 Luftballons"',
77
+ 'Add "Take on me"',
78
+ ]);
79
+ });
80
+ });
81
+ describe('expectedTargetPullRequests', () => {
82
+ let res;
83
+ beforeEach(async () => {
84
+ res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
85
+ accessToken: devAccessToken,
86
+ commitPaths: [],
87
+ historicalBranchLabelMappings: [],
88
+ maxNumber: 10,
89
+ repoName: 'backport-e2e',
90
+ repoOwner: 'backport-org',
91
+ sourceBranch: 'master',
92
+ author: null,
93
+ });
94
+ });
95
+ it('returns related OPEN PRs', async () => {
96
+ const commitWithOpenPR = res.find((commit) => commit.pullNumber === 9);
97
+ expect(commitWithOpenPR?.expectedTargetPullRequests).toEqual([
98
+ {
99
+ branch: '7.8',
100
+ state: 'OPEN',
101
+ number: 10,
102
+ url: 'https://github.com/backport-org/backport-e2e/pull/10',
103
+ },
104
+ ]);
105
+ });
106
+ it('returns related MERGED PRs', async () => {
107
+ const commitWithMergedPRs = res.find((commit) => commit.pullNumber === 5);
108
+ expect(commitWithMergedPRs?.expectedTargetPullRequests).toEqual([
109
+ {
110
+ branch: '7.x',
111
+ state: 'MERGED',
112
+ number: 6,
113
+ url: 'https://github.com/backport-org/backport-e2e/pull/6',
114
+ },
115
+ {
116
+ branch: '7.8',
117
+ state: 'MERGED',
118
+ number: 7,
119
+ url: 'https://github.com/backport-org/backport-e2e/pull/7',
120
+ },
121
+ ]);
122
+ });
123
+ it('returns empty if there are no related PRs', async () => {
124
+ const commitWithoutPRs = res.find((commit) => commit.pullNumber === 8);
125
+ expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([]);
126
+ });
127
+ });
128
+ });
@@ -0,0 +1,125 @@
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
+ historicalBranchLabelMappings: [],
15
+ maxNumber: 10,
16
+ repoName: 'kibana',
17
+ repoOwner: 'elastic',
18
+ sourceBranch: 'source-branch-from-options',
19
+ };
20
+ const authorIdMockData = { user: { id: 'myUserId' } };
21
+ describe('fetchCommitsByAuthor', () => {
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+ afterEach(() => {
26
+ nock_1.default.cleanAll();
27
+ });
28
+ describe('when commit has an associated pull request', () => {
29
+ let res;
30
+ let authorIdCalls;
31
+ let commitsByAuthorCalls;
32
+ beforeEach(async () => {
33
+ authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
34
+ name: 'AuthorId',
35
+ statusCode: 200,
36
+ body: { data: authorIdMockData },
37
+ });
38
+ commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
39
+ name: 'CommitsByAuthor',
40
+ statusCode: 200,
41
+ body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
42
+ });
43
+ res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
44
+ });
45
+ it('should return a list of commits with pullNumber and existing backports', () => {
46
+ const expectedCommits = [
47
+ {
48
+ committedDate: '2021-12-24T00:00:00Z',
49
+ sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
50
+ originalMessage: 'Add 👻',
51
+ expectedTargetPullRequests: [],
52
+ sourceBranch: 'source-branch-from-options',
53
+ },
54
+ {
55
+ committedDate: '2021-12-23T00:00:00Z',
56
+ sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
57
+ originalMessage: 'Add witch (#85)',
58
+ pullNumber: 85,
59
+ pullUrl: 'https://github.com/elastic/kibana/pull/85',
60
+ expectedTargetPullRequests: [],
61
+ sourceBranch: 'master',
62
+ },
63
+ {
64
+ committedDate: '2021-12-22T00:00:00Z',
65
+ sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
66
+ originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
67
+ pullNumber: 80,
68
+ pullUrl: 'https://github.com/elastic/kibana/pull/80',
69
+ expectedTargetPullRequests: [
70
+ {
71
+ branch: '6.3',
72
+ state: 'MERGED',
73
+ number: 99,
74
+ url: 'https://github.com/elastic/kibana/pull/99',
75
+ },
76
+ ],
77
+ sourceBranch: 'master',
78
+ },
79
+ {
80
+ committedDate: '2021-12-21T00:00:00Z',
81
+ sha: '3827bbbaf39914eda4f02f6940189844375fd097',
82
+ originalMessage: 'Add backport config',
83
+ expectedTargetPullRequests: [],
84
+ sourceBranch: 'source-branch-from-options',
85
+ },
86
+ {
87
+ committedDate: '2021-12-20T00:00:00Z',
88
+ sha: '5ea0da550ac191029459289d67f99ad7d310812b',
89
+ originalMessage: 'Initial commit',
90
+ expectedTargetPullRequests: [],
91
+ sourceBranch: 'source-branch-from-options',
92
+ },
93
+ ];
94
+ expect(res).toEqual(expectedCommits);
95
+ });
96
+ it('should call with correct args to fetch author id', () => {
97
+ expect(authorIdCalls).toMatchSnapshot();
98
+ });
99
+ it('should call with correct args to fetch commits', () => {
100
+ expect(commitsByAuthorCalls).toMatchSnapshot();
101
+ });
102
+ });
103
+ describe('when a custom github api hostname is supplied', () => {
104
+ it('should be used in gql requests', async () => {
105
+ const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
106
+ name: 'AuthorId',
107
+ statusCode: 200,
108
+ body: { data: authorIdMockData },
109
+ apiBaseUrl: 'http://localhost/my-custom-api',
110
+ });
111
+ const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
112
+ name: 'CommitsByAuthor',
113
+ statusCode: 200,
114
+ body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
115
+ apiBaseUrl: 'http://localhost/my-custom-api',
116
+ });
117
+ await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
118
+ ...defaultOptions,
119
+ githubApiBaseUrlV4: 'http://localhost/my-custom-api',
120
+ });
121
+ expect(authorIdCalls.length).toBe(1);
122
+ expect(commitsByAuthorCalls.length).toBe(1);
123
+ });
124
+ });
125
+ });
@@ -0,0 +1,28 @@
1
+ import { ValidConfigOptions } from '../../../../options/options';
2
+ import { Commit, CommitNode } from '../../../../types/commitNode';
3
+ export declare function fetchCommitsInDateRange({ accessToken, branchLabelMapping, commitsCount, dateRange, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch, }: {
4
+ accessToken: string;
5
+ branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
6
+ commitsCount: number;
7
+ dateRange: {
8
+ since: string;
9
+ until: string;
10
+ };
11
+ githubApiBaseUrlV4: string;
12
+ repoName: string;
13
+ repoOwner: string;
14
+ sourceBranch: string;
15
+ }): Promise<Commit[] | undefined>;
16
+ export interface CommitsSinceDateResponse {
17
+ repository: {
18
+ ref: {
19
+ target: {
20
+ history: {
21
+ edges: Array<{
22
+ node: CommitNode;
23
+ }>;
24
+ };
25
+ };
26
+ } | null;
27
+ };
28
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchCommitsInDateRange = void 0;
4
+ const commitNode_1 = require("../../../../types/commitNode");
5
+ const apiRequestV4_1 = require("../apiRequestV4");
6
+ async function fetchCommitsInDateRange({ accessToken, branchLabelMapping, commitsCount, dateRange, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch, }) {
7
+ const query = /* GraphQL */ `
8
+ query CommitsSinceDate($repoOwner: String!, $repoName: String!, $commitsCount: Int!, $sourceBranch: String!, $since: GitTimestamp!, $until: GitTimestamp!) {
9
+ repository(owner: $repoOwner, name: $repoName) {
10
+ id
11
+ ref(qualifiedName: $sourceBranch) {
12
+ target {
13
+ ... on Commit {
14
+ history(first: $commitsCount, since: $since, until: $until) {
15
+ totalCount
16
+ edges {
17
+ node {
18
+ ...${commitNode_1.commitNodeFragment.name}
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ ${commitNode_1.commitNodeFragment.source}
29
+ `;
30
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
31
+ githubApiBaseUrlV4,
32
+ accessToken,
33
+ query,
34
+ variables: {
35
+ repoOwner,
36
+ repoName,
37
+ commitsCount,
38
+ sourceBranch,
39
+ since: dateRange.since,
40
+ until: dateRange.until,
41
+ },
42
+ });
43
+ return res.repository.ref?.target.history.edges
44
+ .filter((commitEdge) => {
45
+ return commitEdge.node.associatedPullRequests.edges?.[0].node != null;
46
+ })
47
+ .map((commitEdge) => {
48
+ const commitNode = commitEdge.node;
49
+ return (0, commitNode_1.getCommit)({ sourceBranch, branchLabelMapping, commitNode });
50
+ });
51
+ }
52
+ exports.fetchCommitsInDateRange = fetchCommitsInDateRange;
@@ -0,0 +1,3 @@
1
+ import { ConfigFileOptions } from '../../../../entrypoint.module';
2
+ import { ValidConfigOptions } from '../../../../options/options';
3
+ export declare function fetchProjectConfig(options: ValidConfigOptions): Promise<ConfigFileOptions>;