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,4 @@
1
+ import { OptionsFromCliArgs } from '../../../../options/cliArgs';
2
+ export declare function getOptionsFromGithub(options: OptionsFromCliArgs): Promise<{
3
+ defaultBranch: string;
4
+ }>;
@@ -0,0 +1,72 @@
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.getOptionsFromGithub = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const HandledError_1 = require("../../../HandledError");
9
+ const git_1 = require("../../../git");
10
+ const apiRequestV4_1 = require("../apiRequestV4");
11
+ const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
12
+ const query_1 = require("./query");
13
+ // fetches the default source branch for the repo (normally "master")
14
+ // startup checks:
15
+ // - verify the access token
16
+ // - ensure no branch named "backport" exists
17
+ async function getOptionsFromGithub(options) {
18
+ var _a, _b;
19
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
20
+ let res;
21
+ const spinner = ora_1.default().start('Initializing...');
22
+ try {
23
+ res = await apiRequestV4_1.apiRequestV4({
24
+ githubApiBaseUrlV4,
25
+ accessToken,
26
+ query: query_1.query,
27
+ variables: {
28
+ repoOwner,
29
+ repoName,
30
+ },
31
+ handleError: false,
32
+ });
33
+ spinner.stop();
34
+ }
35
+ catch (e) {
36
+ spinner.stop();
37
+ const error = e;
38
+ throwOnInvalidAccessToken_1.throwOnInvalidAccessToken({
39
+ error,
40
+ repoName,
41
+ repoOwner,
42
+ });
43
+ throw apiRequestV4_1.handleGithubV4Error(error);
44
+ }
45
+ // get the original repo (not the fork)
46
+ const repo = res.repository.isFork ? res.repository.parent : res.repository;
47
+ // it is not possible to have a branch named "backport"
48
+ if (((_a = repo.ref) === null || _a === void 0 ? void 0 : _a.name) === 'backport') {
49
+ throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
50
+ }
51
+ const remoteConfig = (_b = repo.defaultBranchRef.target.edges[0]) === null || _b === void 0 ? void 0 : _b.config;
52
+ const shouldUse = await shouldUseLocalConfig(options, remoteConfig);
53
+ // return default branch
54
+ return {
55
+ defaultBranch: repo.defaultBranchRef.name,
56
+ };
57
+ }
58
+ exports.getOptionsFromGithub = getOptionsFromGithub;
59
+ async function shouldUseLocalConfig(options, remoteConfig) {
60
+ if (options.useLocalConfig) {
61
+ return true;
62
+ }
63
+ const remoteCommitDate = remoteConfig === null || remoteConfig === void 0 ? void 0 : remoteConfig.committedDate;
64
+ if (!remoteCommitDate) {
65
+ return true;
66
+ }
67
+ const localCommitDate = await git_1.getLocalConfigFileCommitDate();
68
+ if (!localCommitDate) {
69
+ return false;
70
+ }
71
+ return localCommitDate > Date.parse(remoteCommitDate);
72
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const _1 = require(".");
5
+ describe('fetchDefaultRepoBranchAndPerformStartupChecks', () => {
6
+ let devAccessToken;
7
+ beforeAll(async () => {
8
+ devAccessToken = await getDevAccessToken_1.getDevAccessToken();
9
+ });
10
+ describe('accessToken is invalid', () => {
11
+ it('throws an error', async () => {
12
+ const options = {
13
+ accessToken: 'foo',
14
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
15
+ repoName: 'backport-e2e',
16
+ repoOwner: 'backport-org',
17
+ };
18
+ await expect(_1.getOptionsFromGithub(options)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
19
+ });
20
+ });
21
+ describe('accessToken is valid', () => {
22
+ it('returns the default branch', async () => {
23
+ const options = {
24
+ accessToken: devAccessToken,
25
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
26
+ repoName: 'backport-e2e',
27
+ repoOwner: 'backport-org',
28
+ };
29
+ expect(await _1.getOptionsFromGithub(options)).toEqual({
30
+ defaultBranch: 'master',
31
+ });
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,40 @@
1
+ export declare type RemoteConfig = {
2
+ committedDate: string;
3
+ file: {
4
+ object: {
5
+ text: string;
6
+ };
7
+ };
8
+ };
9
+ declare type Ref = {
10
+ name: string;
11
+ } | null;
12
+ declare type DefaultBranchRef = {
13
+ name: string;
14
+ target: {
15
+ edges: ({
16
+ config: RemoteConfig;
17
+ } | undefined)[];
18
+ };
19
+ };
20
+ export interface DataResponse {
21
+ viewer: {
22
+ login: string;
23
+ };
24
+ repository: {
25
+ isFork: boolean;
26
+ id: string;
27
+ ref: Ref;
28
+ defaultBranchRef: DefaultBranchRef;
29
+ parent: {
30
+ id: string;
31
+ ref: Ref;
32
+ defaultBranchRef: DefaultBranchRef;
33
+ owner: {
34
+ login: string;
35
+ };
36
+ };
37
+ };
38
+ }
39
+ export declare const query = "\n query getStartupChecks($repoOwner: String!, $repoName: String!) {\n viewer {\n login\n }\n repository(owner: $repoOwner, name: $repoName) {\n isFork\n ...UpstreamInfo\n parent {\n ...UpstreamInfo\n owner {\n login\n }\n }\n }\n }\n\n fragment UpstreamInfo on Repository {\n id\n ref(qualifiedName: \"refs/heads/7.x\") {\n name\n }\n defaultBranchRef {\n name\n target {\n ...JSONConfigFile\n ...JSConfigFile\n }\n }\n }\n\n fragment JSONConfigFile on Commit {\n jsonConfigFile: history(first: 1, path: \".backportrc.json\") {\n edges {\n config: node {\n committedDate\n file(path: \".backportrc.json\") {\n ... on TreeEntry {\n object {\n ... on Blob {\n text\n }\n }\n }\n }\n }\n }\n }\n }\n\n fragment JSConfigFile on Commit {\n jsConfigFile: history(first: 1, path: \".backportrc.js\") {\n edges {\n config: node {\n committedDate\n file(path: \".backportrc.js\") {\n ... on TreeEntry {\n object {\n ... on Blob {\n text\n }\n }\n }\n }\n }\n }\n }\n }\n";
40
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.query = void 0;
4
+ exports.query = `
5
+ query getStartupChecks($repoOwner: String!, $repoName: String!) {
6
+ viewer {
7
+ login
8
+ }
9
+ repository(owner: $repoOwner, name: $repoName) {
10
+ isFork
11
+ ...UpstreamInfo
12
+ parent {
13
+ ...UpstreamInfo
14
+ owner {
15
+ login
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ fragment UpstreamInfo on Repository {
22
+ id
23
+ ref(qualifiedName: "refs/heads/7.x") {
24
+ name
25
+ }
26
+ defaultBranchRef {
27
+ name
28
+ target {
29
+ ...JSONConfigFile
30
+ ...JSConfigFile
31
+ }
32
+ }
33
+ }
34
+
35
+ fragment JSONConfigFile on Commit {
36
+ jsonConfigFile: history(first: 1, path: ".backportrc.json") {
37
+ edges {
38
+ config: node {
39
+ committedDate
40
+ file(path: ".backportrc.json") {
41
+ ... on TreeEntry {
42
+ object {
43
+ ... on Blob {
44
+ text
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ fragment JSConfigFile on Commit {
55
+ jsConfigFile: history(first: 1, path: ".backportrc.js") {
56
+ edges {
57
+ config: node {
58
+ committedDate
59
+ file(path: ".backportrc.js") {
60
+ ... on TreeEntry {
61
+ object {
62
+ ... on Blob {
63
+ text
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ `;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.splitHead = exports.fetchExistingPullRequest = void 0;
4
4
  const apiRequestV4_1 = require("./apiRequestV4");
5
5
  async function fetchExistingPullRequest({ options, prPayload, }) {
6
- var _a;
7
6
  const { githubApiBaseUrlV4, accessToken } = options;
8
7
  const query = /* GraphQL */ `
9
8
  query ExistingPullRequest(
@@ -34,7 +33,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
34
33
  }
35
34
  `;
36
35
  const { repoForkOwner, head } = splitHead(prPayload);
37
- const res = await apiRequestV4_1.apiRequestV4({
36
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
38
37
  githubApiBaseUrlV4,
39
38
  accessToken,
40
39
  query,
@@ -45,7 +44,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
45
44
  head: head,
46
45
  },
47
46
  });
48
- const existingPullRequest = (_a = res.repository.ref) === null || _a === void 0 ? void 0 : _a.associatedPullRequests.edges[0];
47
+ const existingPullRequest = res.repository.ref?.associatedPullRequests.edges[0];
49
48
  if (!existingPullRequest) {
50
49
  return;
51
50
  }
@@ -5,13 +5,12 @@ const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
5
5
  describe('fetchExistingPullRequest', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  describe('when PR does not exist', () => {
11
11
  it('returns undefined', async () => {
12
12
  const options = {
13
13
  accessToken: devAccessToken,
14
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
15
14
  };
16
15
  const prPayload = {
17
16
  owner: 'backport-org',
@@ -21,7 +20,7 @@ describe('fetchExistingPullRequest', () => {
21
20
  head: 'sqren:backport/7.8/pr-foo',
22
21
  base: '7.8',
23
22
  };
24
- const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
23
+ const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
25
24
  expect(res).toBe(undefined);
26
25
  });
27
26
  });
@@ -29,7 +28,6 @@ describe('fetchExistingPullRequest', () => {
29
28
  it('returns the PR number and url', async () => {
30
29
  const options = {
31
30
  accessToken: devAccessToken,
32
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
33
31
  };
34
32
  const prPayload = {
35
33
  owner: 'backport-org',
@@ -39,7 +37,7 @@ describe('fetchExistingPullRequest', () => {
39
37
  head: 'sqren:backport/7.8/pr-9',
40
38
  base: '7.8',
41
39
  };
42
- const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
40
+ const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
43
41
  expect(res).toEqual({
44
42
  url: 'https://github.com/backport-org/backport-e2e/pull/10',
45
43
  number: 10,
@@ -1,10 +1,19 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- import { PullRequestNode } from './getExistingTargetPullRequests';
3
- export declare function fetchMergedPullRequests(options: ValidConfigOptions, dateRange: {
4
- since: string;
5
- until: string;
2
+ import { CommitNode } from '../../../types/commitNode';
3
+ export declare function fetchMergedPullRequests({ 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;
6
15
  }): Promise<{
7
- sourcePullNumber: number;
16
+ sourcePullNumber: number | undefined;
8
17
  existingTargetPullRequests: {
9
18
  number: number;
10
19
  branch: string;
@@ -12,27 +21,17 @@ export declare function fetchMergedPullRequests(options: ValidConfigOptions, dat
12
21
  }[];
13
22
  expectedTargetBranches: string[];
14
23
  remainingTargetBranches: string[];
15
- }[] | undefined>;
16
- export interface DataResponse {
24
+ }[]>;
25
+ export interface CommitsSinceDateResponse {
17
26
  repository: {
18
27
  ref: {
19
28
  target: {
20
29
  history: {
21
- edges: HistoryEdge[];
30
+ edges: Array<{
31
+ node: CommitNode;
32
+ }>;
22
33
  };
23
34
  };
24
35
  } | null;
25
36
  };
26
37
  }
27
- interface HistoryEdge {
28
- node: {
29
- oid: string;
30
- message: string;
31
- associatedPullRequests: {
32
- edges: {
33
- node: PullRequestNode;
34
- }[];
35
- };
36
- };
37
- }
38
- export {};
@@ -1,82 +1,36 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchMergedPullRequests = void 0;
7
- const lodash_difference_1 = __importDefault(require("lodash.difference"));
8
- const apiRequestV4_1 = require("./apiRequestV4");
9
- const fetchDefaultBranch_1 = require("./fetchDefaultBranch");
10
- const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
11
- const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
12
- async function fetchMergedPullRequests(options, dateRange) {
13
- var _a;
14
- const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
15
- const query = /* GraphQL */ `
16
- query CommitsSinceDate($repoOwner: String!, $repoName: String!, $commitsCount: Int!, $sourceBranch: String!, $since: GitTimestamp!, $until: GitTimestamp!) {
17
- repository(owner: $repoOwner, name: $repoName) {
18
- id
19
- ref(qualifiedName: $sourceBranch) {
20
- target {
21
- ... on Commit {
22
- history(first: $commitsCount, since: $since, until: $until) {
23
- totalCount
24
- edges {
25
- node {
26
- oid
27
- message
28
- associatedPullRequests(first: 1) {
29
- edges {
30
- node {
31
- ...${getExistingTargetPullRequests_1.pullRequestFragmentName}
32
- }
33
- }
34
- }
35
- }
36
- }
37
- }
38
- }
39
- }
40
- }
41
- }
42
- }
43
-
44
- ${getExistingTargetPullRequests_1.pullRequestFragment}
45
- `;
46
- const defaultBranch = await fetchDefaultBranch_1.fetchDefaultBranch(options);
47
- const res = await apiRequestV4_1.apiRequestV4({
48
- githubApiBaseUrlV4,
4
+ const lodash_1 = require("lodash");
5
+ const fetchCommitsInDateRange_1 = require("./fetchCommits/fetchCommitsInDateRange");
6
+ async function fetchMergedPullRequests({ accessToken, branchLabelMapping, commitsCount = 50, dateRange, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sourceBranch, }) {
7
+ const commits = await (0, fetchCommitsInDateRange_1.fetchCommitsInDateRange)({
49
8
  accessToken,
50
- query,
51
- variables: {
52
- repoOwner,
53
- repoName,
54
- commitsCount: 50,
55
- sourceBranch: defaultBranch,
56
- since: dateRange.since,
57
- until: dateRange.until,
58
- },
9
+ branchLabelMapping,
10
+ commitsCount,
11
+ dateRange,
12
+ githubApiBaseUrlV4,
13
+ repoName,
14
+ repoOwner,
15
+ sourceBranch,
59
16
  });
60
- return (_a = res.repository.ref) === null || _a === void 0 ? void 0 : _a.target.history.edges.filter((commitEdge) => { var _a; return !!((_a = commitEdge.node.associatedPullRequests.edges[0]) === null || _a === void 0 ? void 0 : _a.node); }).map((commitEdge) => {
61
- const pullRequestNode = commitEdge.node.associatedPullRequests.edges[0].node;
62
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
63
- const expectedTargetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
64
- sourceBranch: pullRequestNode.baseRefName,
65
- existingTargetPullRequests: [],
66
- branchLabelMapping: options.branchLabelMapping,
67
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
68
- });
69
- const mergedTargetBranches = existingTargetPullRequests
17
+ return (commits ?? [])
18
+ .filter((commit) => !!commit.pullNumber)
19
+ .map((commit) => {
20
+ const mergedTargetBranches = commit.existingTargetPullRequests
70
21
  .filter((pr) => pr.state === 'MERGED')
71
22
  .map((pr) => pr.branch);
72
- const remainingTargetBranches = lodash_difference_1.default(expectedTargetBranches, mergedTargetBranches);
23
+ const expectedTargetBranches = commit.targetBranchesFromLabels;
24
+ // missing and unmerged pull requests
25
+ const remainingTargetBranches = (0, lodash_1.difference)(expectedTargetBranches, mergedTargetBranches);
73
26
  return {
74
- sourcePullNumber: pullRequestNode.number,
75
- existingTargetPullRequests,
27
+ sourcePullNumber: commit.pullNumber,
28
+ existingTargetPullRequests: commit.existingTargetPullRequests,
76
29
  expectedTargetBranches,
77
30
  remainingTargetBranches,
78
31
  };
79
- }).filter((res) => {
32
+ })
33
+ .filter((res) => {
80
34
  return res.remainingTargetBranches.length > 0;
81
35
  });
82
36
  }
@@ -5,26 +5,25 @@ const fetchMergedPullRequests_1 = require("./fetchMergedPullRequests");
5
5
  describe('fetchMergedPullRequests', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  describe('fetchMergedPullRequests', () => {
11
11
  it('returns the unbackported PRs', async () => {
12
- const options = {
12
+ const res = await (0, fetchMergedPullRequests_1.fetchMergedPullRequests)({
13
13
  repoOwner: 'backport-org',
14
14
  repoName: 'backport-e2e',
15
+ sourceBranch: 'master',
15
16
  accessToken: devAccessToken,
16
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
17
17
  branchLabelMapping: {
18
18
  '^v8.0.0$': 'master',
19
19
  '^v7.9.0$': '7.x',
20
20
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
21
21
  },
22
- };
23
- const dateRange = {
24
- since: new Date('2020-01-01').toISOString(),
25
- until: new Date('2020-09-01').toISOString(),
26
- };
27
- const res = await fetchMergedPullRequests_1.fetchMergedPullRequests(options, dateRange);
22
+ dateRange: {
23
+ since: new Date('2020-01-01').toISOString(),
24
+ until: new Date('2020-09-01').toISOString(),
25
+ },
26
+ });
28
27
  expect(res).toMatchInlineSnapshot(`
29
28
  Array [
30
29
  Object {
@@ -0,0 +1,8 @@
1
+ import { ConfigFileOptions } from '../../../entrypoint.module';
2
+ export declare function fetchProjectConfig(options: {
3
+ accessToken: string;
4
+ githubApiBaseUrlV4?: string;
5
+ repoName: string;
6
+ repoOwner: string;
7
+ sourceBranch: string;
8
+ }): Promise<ConfigFileOptions>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchProjectConfig = void 0;
4
+ const readConfigFile_1 = require("../../../options/config/readConfigFile");
5
+ const apiRequestV4_1 = require("./apiRequestV4");
6
+ async function fetchProjectConfig(options) {
7
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
8
+ const query = /* GraphQL */ `
9
+ query ProjectConfig(
10
+ $repoOwner: String!
11
+ $repoName: String!
12
+ $sourceBranch: String!
13
+ ) {
14
+ repository(owner: $repoOwner, name: $repoName) {
15
+ ref(qualifiedName: $sourceBranch) {
16
+ target {
17
+ ... on Commit {
18
+ history(first: 1, path: ".backportrc.json") {
19
+ edges {
20
+ remoteConfig: node {
21
+ file(path: ".backportrc.json") {
22
+ ... on TreeEntry {
23
+ object {
24
+ ... on Blob {
25
+ text
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ `;
39
+ try {
40
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
41
+ githubApiBaseUrlV4,
42
+ accessToken,
43
+ query,
44
+ variables: {
45
+ repoOwner,
46
+ repoName,
47
+ sourceBranch,
48
+ },
49
+ });
50
+ return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(res.repository.ref.target.history.edges[0].remoteConfig.file.object.text));
51
+ }
52
+ catch (e) {
53
+ throw new Error('Project config does not exist');
54
+ }
55
+ }
56
+ exports.fetchProjectConfig = fetchProjectConfig;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchProjectConfig_1 = require("./fetchProjectConfig");
5
+ describe('fetchProjectConfig', () => {
6
+ let devAccessToken;
7
+ beforeEach(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ it('returns the backport config from "main" branch', async () => {
11
+ const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
12
+ repoOwner: 'backport-org',
13
+ repoName: 'repo-with-project-config',
14
+ accessToken: devAccessToken,
15
+ sourceBranch: 'main',
16
+ });
17
+ expect(projectConfig).toEqual({
18
+ autoMerge: true,
19
+ autoMergeMethod: 'squash',
20
+ branchLabelMapping: {
21
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
22
+ '^v8.1.0$': 'main',
23
+ },
24
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
25
+ targetPRLabels: ['backport'],
26
+ repoOwner: 'backport-org',
27
+ repoName: 'repo-with-project-config',
28
+ });
29
+ });
30
+ it('returns the backport config from "branch-with-legacy-config" branch', async () => {
31
+ const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
32
+ repoOwner: 'backport-org',
33
+ repoName: 'repo-with-project-config',
34
+ accessToken: devAccessToken,
35
+ sourceBranch: 'branch-with-legacy-config',
36
+ });
37
+ expect(projectConfig).toEqual({
38
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
39
+ repoOwner: 'backport-org',
40
+ repoName: 'repo-with-project-config',
41
+ });
42
+ });
43
+ it('throws an error if config does not exist', async () => {
44
+ const promise = (0, fetchProjectConfig_1.fetchProjectConfig)({
45
+ repoOwner: 'backport-org',
46
+ repoName: 'repo-with-project-config',
47
+ accessToken: devAccessToken,
48
+ sourceBranch: 'branch-with-no-config',
49
+ });
50
+ await expect(promise).rejects.toThrowError('Project config does not exist');
51
+ });
52
+ });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchProjectConfig_1 = require("./fetchProjectConfig");
5
+ describe('fetchProjectConfig', () => {
6
+ let devAccessToken;
7
+ beforeEach(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ it('returns the backport config from "main" branch', async () => {
11
+ const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
12
+ repoOwner: 'backport-org',
13
+ repoName: 'repo-with-project-config',
14
+ accessToken: devAccessToken,
15
+ sourceBranch: 'main',
16
+ });
17
+ expect(projectConfig).toEqual();
18
+ });
19
+ it('returns the backport config from "branch-with-minimal-config" branch', async () => {
20
+ const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
21
+ repoOwner: 'backport-org',
22
+ repoName: 'repo-with-project-config',
23
+ accessToken: devAccessToken,
24
+ sourceBranch: 'branch-with-minimal-config',
25
+ });
26
+ expect(projectConfig).toEqual();
27
+ });
28
+ it('throws an error if config does not exist', async () => {
29
+ const promise = (0, fetchProjectConfig_1.fetchProjectConfig)({
30
+ repoOwner: 'backport-org',
31
+ repoName: 'repo-with-project-config',
32
+ accessToken: devAccessToken,
33
+ sourceBranch: 'branch-with-no-config',
34
+ });
35
+ await expect(promise).rejects.toThrowError('something...');
36
+ });
37
+ });