backport 5.6.5 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +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 +34 -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 +28 -12
  12. package/dist/options/cliArgs.d.ts +36 -35
  13. package/dist/options/cliArgs.js +91 -52
  14. package/dist/options/cliArgs.test.js +41 -42
  15. package/dist/options/config/config.d.ts +34 -57
  16. package/dist/options/config/config.js +5 -39
  17. package/dist/options/config/config.test.js +11 -25
  18. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  19. package/dist/options/config/getOptionsFromGit.js +1 -3
  20. package/dist/options/config/globalConfig.d.ts +2 -49
  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 -49
  24. package/dist/options/config/projectConfig.js +2 -2
  25. package/dist/options/config/projectConfig.test.js +53 -16
  26. package/dist/options/config/readConfigFile.d.ts +43 -39
  27. package/dist/options/config/readConfigFile.js +30 -4
  28. package/dist/options/options.d.ts +57 -31
  29. package/dist/options/options.js +102 -10
  30. package/dist/options/options.test.js +263 -61
  31. package/dist/options/parseRequiredOptions.d.ts +19 -14
  32. package/dist/options/parseRequiredOptions.js +9 -15
  33. package/dist/options/parseRequiredOptions.test.js +30 -26
  34. package/dist/runSequentially.d.ts +20 -0
  35. package/dist/runSequentially.js +41 -0
  36. package/dist/runSequentially.test.d.ts +1 -0
  37. package/dist/runSequentially.test.js +196 -0
  38. package/dist/runWithOptions.js +7 -14
  39. package/dist/runWithOptions.test.js +140 -17
  40. package/dist/scripts/generate-gql.d.ts +1 -0
  41. package/dist/scripts/generate-gql.js +15 -0
  42. package/dist/scripts/postinstall.js +4 -4
  43. package/dist/scripts/postinstall.test.js +9 -2
  44. package/dist/scripts/runPostinstall.js +1 -1
  45. package/dist/services/HandledError.d.ts +11 -1
  46. package/dist/services/HandledError.js +2 -1
  47. package/dist/services/child-process-promisified.d.ts +1 -1
  48. package/dist/services/child-process-promisified.js +1 -1
  49. package/dist/services/env.js +5 -5
  50. package/dist/services/env.test.js +11 -4
  51. package/dist/services/fs-promisified.js +4 -4
  52. package/dist/services/getExpectedTarget.d.ts +9 -0
  53. package/dist/services/getExpectedTarget.js +77 -0
  54. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  55. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  56. package/dist/services/git.d.ts +20 -6
  57. package/dist/services/git.integration.test.d.ts +1 -0
  58. package/dist/services/git.integration.test.js +168 -0
  59. package/dist/services/git.js +93 -67
  60. package/dist/services/git.test.js +68 -68
  61. package/dist/services/github/commitFormatters.d.ts +3 -7
  62. package/dist/services/github/commitFormatters.js +10 -19
  63. package/dist/services/github/commitFormatters.test.js +2 -24
  64. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  66. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  67. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  68. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  69. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  70. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  71. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  72. package/dist/services/github/v3/createPullRequest.js +31 -29
  73. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  74. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  75. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  76. package/dist/services/github/v3/createStatusComment.js +97 -0
  77. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  78. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  79. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  80. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  81. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  82. package/dist/services/github/v4/apiRequestV4.js +8 -10
  83. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  84. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  90. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  91. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  92. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  93. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  95. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  96. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  113. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  121. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  122. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  123. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  124. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  125. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  126. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  127. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  128. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  129. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  130. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  131. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  132. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  133. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  134. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  135. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  136. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  137. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  138. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  139. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  142. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  143. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  144. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  145. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -9
  149. package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
  150. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
  151. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
  152. package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  154. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  155. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  156. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  158. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  159. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  160. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  162. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  163. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  165. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  166. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  167. package/dist/services/logger.d.ts +3 -3
  168. package/dist/services/logger.js +16 -15
  169. package/dist/services/prompt.test.d.ts +1 -0
  170. package/dist/services/prompt.test.js +87 -0
  171. package/dist/services/prompts.d.ts +10 -4
  172. package/dist/services/prompts.js +85 -22
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  175. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  176. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
  177. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  178. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  181. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  182. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  185. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  186. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  187. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  188. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  189. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  191. package/dist/services/sourceCommit.d.ts +78 -0
  192. package/dist/services/sourceCommit.js +86 -0
  193. package/dist/services/sourceCommit.test.d.ts +1 -0
  194. package/dist/services/sourceCommit.test.js +280 -0
  195. package/dist/test/inquirer.private.test.js +64 -49
  196. package/dist/test/integration/createSpies.js +6 -6
  197. package/dist/test/integration/envConstants.js +5 -6
  198. package/dist/test/integration/helpers.js +1 -1
  199. package/dist/test/integration/integration.private.test.d.ts +1 -0
  200. package/dist/test/integration/integration.private.test.js +327 -0
  201. package/dist/test/integration/integration.test.js +28 -29
  202. package/dist/test/mockConfigFiles.d.ts +5 -0
  203. package/dist/test/mockConfigFiles.js +37 -0
  204. package/dist/test/nockHelpers.d.ts +1 -1
  205. package/dist/test/nockHelpers.js +7 -11
  206. package/dist/test/private/getDevAccessToken.js +1 -1
  207. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  208. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  209. package/dist/types/Commit.d.ts +85 -0
  210. package/dist/types/Commit.js +139 -0
  211. package/dist/types/commitNode.d.ts +89 -0
  212. package/dist/types/commitNode.js +139 -0
  213. package/dist/types/commitNode.test.d.ts +1 -0
  214. package/dist/types/commitNode.test.js +255 -0
  215. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  216. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  217. package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
  218. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  219. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  220. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  221. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  222. package/dist/ui/getCommits.d.ts +1 -1
  223. package/dist/ui/getCommits.js +55 -25
  224. package/dist/ui/getTargetBranches.d.ts +3 -2
  225. package/dist/ui/getTargetBranches.js +33 -18
  226. package/dist/ui/getTargetBranches.test.js +75 -99
  227. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  228. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  229. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  230. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  231. package/dist/ui/maybeSetupRepo.js +11 -10
  232. package/dist/ui/maybeSetupRepo.test.js +54 -4
  233. package/dist/utils/excludeUndefined.d.ts +6 -0
  234. package/dist/utils/excludeUndefined.js +7 -0
  235. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  236. package/dist/utils/excludeUndefined.test.js +24 -0
  237. package/package.json +37 -51
  238. package/yarn.lock +2414 -2993
@@ -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>;
24
+ }[]>;
16
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,83 +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
- // TODO: It should be possible to delete this since defaultBranch is already fetched during startup
47
- const defaultBranch = await fetchDefaultBranch_1.fetchDefaultBranch(options);
48
- const res = await apiRequestV4_1.apiRequestV4({
49
- 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)({
50
8
  accessToken,
51
- query,
52
- variables: {
53
- repoOwner,
54
- repoName,
55
- commitsCount: 50,
56
- sourceBranch: defaultBranch,
57
- since: dateRange.since,
58
- until: dateRange.until,
59
- },
9
+ branchLabelMapping,
10
+ commitsCount,
11
+ dateRange,
12
+ githubApiBaseUrlV4,
13
+ repoName,
14
+ repoOwner,
15
+ sourceBranch,
60
16
  });
61
- 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) => {
62
- const pullRequestNode = commitEdge.node.associatedPullRequests.edges[0].node;
63
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
64
- const expectedTargetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
65
- sourceBranch: pullRequestNode.baseRefName,
66
- existingTargetPullRequests: [],
67
- branchLabelMapping: options.branchLabelMapping,
68
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
69
- });
70
- const mergedTargetBranches = existingTargetPullRequests
17
+ return (commits ?? [])
18
+ .filter((commit) => !!commit.pullNumber)
19
+ .map((commit) => {
20
+ const mergedTargetBranches = commit.existingTargetPullRequests
71
21
  .filter((pr) => pr.state === 'MERGED')
72
22
  .map((pr) => pr.branch);
73
- 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);
74
26
  return {
75
- sourcePullNumber: pullRequestNode.number,
76
- existingTargetPullRequests,
27
+ sourcePullNumber: commit.pullNumber,
28
+ existingTargetPullRequests: commit.existingTargetPullRequests,
77
29
  expectedTargetBranches,
78
30
  remainingTargetBranches,
79
31
  };
80
- }).filter((res) => {
32
+ })
33
+ .filter((res) => {
81
34
  return res.remainingTargetBranches.length > 0;
82
35
  });
83
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
+ });
@@ -0,0 +1,11 @@
1
+ import { ValidConfigOptions } from '../../../options/options';
2
+ export interface PullRequestAutoMergeResponse {
3
+ repository: {
4
+ pullRequest?: {
5
+ autoMergeRequest?: {
6
+ mergeMethod: string;
7
+ };
8
+ };
9
+ };
10
+ }
11
+ export declare function fetchPullRequestAutoMergeMethod(options: ValidConfigOptions, pullNumber: number): Promise<string | undefined>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchPullRequestAutoMergeMethod = void 0;
4
+ const apiRequestV4_1 = require("./apiRequestV4");
5
+ async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
6
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
7
+ const query = /* GraphQL */ `
8
+ query PullRequestAutoMergeMethod(
9
+ $repoOwner: String!
10
+ $repoName: String!
11
+ $pullNumber: Int!
12
+ ) {
13
+ repository(owner: $repoOwner, name: $repoName) {
14
+ pullRequest(number: $pullNumber) {
15
+ autoMergeRequest {
16
+ enabledAt
17
+ mergeMethod
18
+ }
19
+ }
20
+ }
21
+ }
22
+ `;
23
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
24
+ githubApiBaseUrlV4,
25
+ accessToken,
26
+ query,
27
+ variables: {
28
+ repoOwner,
29
+ repoName,
30
+ pullNumber,
31
+ },
32
+ });
33
+ return res.repository.pullRequest?.autoMergeRequest?.mergeMethod;
34
+ }
35
+ exports.fetchPullRequestAutoMergeMethod = fetchPullRequestAutoMergeMethod;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchPullRequestBySearchQuery = void 0;
7
- const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
7
+ const lodash_1 = require("lodash");
8
8
  const ora_1 = __importDefault(require("ora"));
9
9
  const HandledError_1 = require("../../HandledError");
10
10
  const commitFormatters_1 = require("../commitFormatters");
@@ -18,20 +18,20 @@ async function fetchPullRequestBySearchQuery(options) {
18
18
  search(query: $query, type: ISSUE, first: $maxNumber) {
19
19
  nodes {
20
20
  ... on PullRequest {
21
- ...${getExistingTargetPullRequests_1.pullRequestFragmentName}
21
+ ...${getExistingTargetPullRequests_1.pullRequestFragment.name}
22
22
  }
23
23
  }
24
24
  }
25
25
  }
26
26
 
27
- ${getExistingTargetPullRequests_1.pullRequestFragment}
27
+ ${getExistingTargetPullRequests_1.pullRequestFragment.source}
28
28
  `;
29
29
  const authorFilter = all ? '' : `author:${author}`;
30
30
  const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName} ${authorFilter} ${prFilter} base:${sourceBranch}`;
31
- const spinner = ora_1.default('Loading pull requests...').start();
31
+ const spinner = (0, ora_1.default)('Loading pull requests...').start();
32
32
  let res;
33
33
  try {
34
- res = await apiRequestV4_1.apiRequestV4({
34
+ res = await (0, apiRequestV4_1.apiRequestV4)({
35
35
  githubApiBaseUrlV4,
36
36
  accessToken,
37
37
  query,
@@ -52,22 +52,24 @@ async function fetchPullRequestBySearchQuery(options) {
52
52
  if (pullRequestNode.mergeCommit == null) {
53
53
  throw new Error('Pull Request is not merged');
54
54
  }
55
+ const committedDate = pullRequestNode.mergeCommit.committedDate;
55
56
  const sha = pullRequestNode.mergeCommit.oid;
56
57
  const pullNumber = pullRequestNode.number;
57
58
  const commitMessage = pullRequestNode.mergeCommit.message;
58
- const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
59
+ const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
59
60
  message: commitMessage,
60
61
  sha,
61
62
  pullNumber,
62
63
  });
63
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
64
- const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
64
+ const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
65
+ const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
65
66
  sourceBranch: pullRequestNode.baseRefName,
66
67
  existingTargetPullRequests,
67
68
  branchLabelMapping: options.branchLabelMapping,
68
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
69
+ labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
69
70
  });
70
71
  const choice = {
72
+ committedDate,
71
73
  sourceBranch,
72
74
  targetBranchesFromLabels,
73
75
  sha,
@@ -79,7 +81,7 @@ async function fetchPullRequestBySearchQuery(options) {
79
81
  return choice;
80
82
  });
81
83
  // terminate if not commits were found
82
- if (lodash_isempty_1.default(commits)) {
84
+ if ((0, lodash_1.isEmpty)(commits)) {
83
85
  const errorText = options.all
84
86
  ? `There are no pull requests matching the filter "${prFilter}"`
85
87
  : `There are no commits by "${options.author}" matching the filter "${prFilter}". Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
@@ -5,7 +5,7 @@ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery
5
5
  describe('fetchPullRequestBySearchQuery', () => {
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 filter does not match any PRs', () => {
11
11
  it('throws an error', async () => {
@@ -20,7 +20,7 @@ describe('fetchPullRequestBySearchQuery', () => {
20
20
  repoOwner: 'backport-org',
21
21
  sourceBranch: 'master',
22
22
  };
23
- await expect(fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
23
+ await expect((0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
24
24
  });
25
25
  });
26
26
  describe('when filter matches PRs', () => {
@@ -36,7 +36,7 @@ describe('fetchPullRequestBySearchQuery', () => {
36
36
  repoOwner: 'backport-org',
37
37
  sourceBranch: 'master',
38
38
  };
39
- expect(await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).toEqual([
39
+ expect(await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).toEqual([
40
40
  {
41
41
  existingTargetPullRequests: [
42
42
  { branch: '7.8', state: 'OPEN', number: 10 },
@@ -11,12 +11,12 @@ describe('fetchPullRequestBySearchQuery', () => {
11
11
  let res;
12
12
  let mockCalls;
13
13
  beforeEach(async () => {
14
- mockCalls = nockHelpers_1.mockGqlRequest({
14
+ mockCalls = (0, nockHelpers_1.mockGqlRequest)({
15
15
  name: 'PullRequestBySearchQuery',
16
16
  statusCode: 200,
17
17
  body: { data: fetchPullRequestBySearchQueryMock_1.fetchPullRequestBySearchQueryMock },
18
18
  });
19
- res = await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery({
19
+ res = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
20
20
  accessToken: 'myAccessToken',
21
21
  all: false,
22
22
  author: 'sqren',
@@ -1,61 +1,7 @@
1
- export declare const pullRequestFragmentName = "ExistingTargetPullRequests";
2
- export declare const pullRequestFragment: string;
3
- export interface PullRequestNode {
4
- baseRefName: string;
5
- number: number;
6
- mergeCommit: {
7
- oid: string;
8
- message: string;
9
- } | null;
10
- labels: {
11
- nodes: {
12
- name: string;
13
- }[];
14
- };
15
- repository: {
16
- owner: {
17
- login: string;
18
- };
19
- name: string;
20
- };
21
- timelineItems: {
22
- edges: TimelineItemEdge[];
23
- };
24
- }
25
- interface TimeLinePullRequestItem {
26
- node: {
27
- source: {
28
- __typename: 'PullRequest';
29
- title: string;
30
- state: 'OPEN' | 'CLOSED' | 'MERGED';
31
- baseRefName: string;
32
- number: number;
33
- commits: {
34
- edges: CommitEdge[];
35
- };
36
- };
37
- };
38
- }
39
- interface IssueTimelineItem {
40
- node: {
41
- source: {
42
- __typename: 'Issue';
43
- };
44
- };
45
- }
46
- declare type TimelineItemEdge = TimeLinePullRequestItem | IssueTimelineItem;
47
- interface CommitEdge {
48
- node: {
49
- commit: {
50
- message: string;
51
- };
52
- };
53
- }
54
- export declare function getPullRequestLabels(pullRequestNode?: PullRequestNode): string[] | undefined;
1
+ import { PullRequestNode } from '../../../types/Commit';
55
2
  export declare type ExistingTargetPullRequests = ReturnType<typeof getExistingTargetPullRequests>;
56
3
  export declare function getExistingTargetPullRequests(sourcePullRequest?: PullRequestNode): {
57
- number: number;
58
- branch: string;
59
- state: "OPEN" | "CLOSED" | "MERGED";
4
+ number: any;
5
+ branch: any;
6
+ state: any;
60
7
  }[];
61
- export {};