backport 5.6.6 → 6.0.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 (206) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +13 -8
  10. package/dist/options/cliArgs.d.ts +11 -9
  11. package/dist/options/cliArgs.js +74 -36
  12. package/dist/options/cliArgs.test.js +33 -37
  13. package/dist/options/config/config.d.ts +17 -15
  14. package/dist/options/config/config.js +8 -8
  15. package/dist/options/config/config.test.js +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -1
  17. package/dist/options/config/globalConfig.d.ts +2 -51
  18. package/dist/options/config/globalConfig.js +8 -8
  19. package/dist/options/config/globalConfig.test.js +7 -3
  20. package/dist/options/config/projectConfig.d.ts +2 -51
  21. package/dist/options/config/projectConfig.js +2 -2
  22. package/dist/options/config/projectConfig.test.js +3 -3
  23. package/dist/options/config/readConfigFile.d.ts +2 -51
  24. package/dist/options/config/readConfigFile.js +2 -2
  25. package/dist/options/options.d.ts +19 -14
  26. package/dist/options/options.js +5 -6
  27. package/dist/options/options.test.js +48 -11
  28. package/dist/options/parseRequiredOptions.d.ts +18 -13
  29. package/dist/options/parseRequiredOptions.js +8 -12
  30. package/dist/options/parseRequiredOptions.test.js +25 -16
  31. package/dist/runSequentially.d.ts +20 -0
  32. package/dist/runSequentially.js +41 -0
  33. package/dist/runSequentially.test.d.ts +1 -0
  34. package/dist/runSequentially.test.js +235 -0
  35. package/dist/runWithOptions.js +7 -14
  36. package/dist/runWithOptions.test.js +138 -17
  37. package/dist/scripts/generate-gql.d.ts +1 -0
  38. package/dist/scripts/generate-gql.js +15 -0
  39. package/dist/scripts/postinstall.js +4 -4
  40. package/dist/scripts/postinstall.test.js +9 -2
  41. package/dist/scripts/runPostinstall.js +1 -1
  42. package/dist/services/HandledError.d.ts +11 -1
  43. package/dist/services/HandledError.js +2 -1
  44. package/dist/services/child-process-promisified.d.ts +1 -1
  45. package/dist/services/child-process-promisified.js +1 -1
  46. package/dist/services/env.js +5 -5
  47. package/dist/services/env.test.js +11 -4
  48. package/dist/services/fs-promisified.js +4 -4
  49. package/dist/services/getExpectedTarget.d.ts +9 -0
  50. package/dist/services/getExpectedTarget.js +77 -0
  51. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  52. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  53. package/dist/services/git.d.ts +15 -4
  54. package/dist/services/git.integration.test.d.ts +1 -0
  55. package/dist/services/git.integration.test.js +168 -0
  56. package/dist/services/git.js +86 -61
  57. package/dist/services/git.test.js +61 -64
  58. package/dist/services/github/commitFormatters.d.ts +3 -7
  59. package/dist/services/github/commitFormatters.js +10 -19
  60. package/dist/services/github/commitFormatters.test.js +2 -24
  61. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  62. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  63. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  64. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  66. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  67. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  68. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  69. package/dist/services/github/v3/createPullRequest.js +32 -23
  70. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  71. package/dist/services/github/v3/createStatusComment.js +97 -0
  72. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  73. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  74. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  75. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  76. package/dist/services/github/v4/apiRequestV4.js +5 -7
  77. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  78. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  79. package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
  80. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
  81. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  83. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  84. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  85. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  86. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  89. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  93. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  105. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  107. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  109. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  110. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  111. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  112. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  113. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  114. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  115. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  116. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  117. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  118. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  119. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  120. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  121. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  122. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  123. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  124. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  125. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
  126. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  127. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
  128. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
  129. package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
  130. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  131. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  132. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  134. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  135. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  136. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  137. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  138. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  139. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  140. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  141. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  142. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  143. package/dist/services/logger.d.ts +3 -3
  144. package/dist/services/logger.js +16 -15
  145. package/dist/services/prompt.test.d.ts +1 -0
  146. package/dist/services/prompt.test.js +87 -0
  147. package/dist/services/prompts.d.ts +10 -4
  148. package/dist/services/prompts.js +85 -22
  149. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  150. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  151. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  152. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  153. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  154. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  155. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  156. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  157. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  158. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  159. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  160. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  161. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  162. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  163. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  164. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  165. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  166. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  167. package/dist/services/sourceCommit.d.ts +78 -0
  168. package/dist/services/sourceCommit.js +86 -0
  169. package/dist/services/sourceCommit.test.d.ts +1 -0
  170. package/dist/services/sourceCommit.test.js +280 -0
  171. package/dist/test/inquirer.private.test.js +22 -15
  172. package/dist/test/integration/createSpies.js +6 -6
  173. package/dist/test/integration/envConstants.js +5 -6
  174. package/dist/test/integration/helpers.js +1 -1
  175. package/dist/test/integration/integration.private.test.d.ts +1 -0
  176. package/dist/test/integration/integration.private.test.js +308 -0
  177. package/dist/test/integration/integration.test.js +28 -29
  178. package/dist/test/nockHelpers.js +3 -7
  179. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  180. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  181. package/dist/types/Commit.d.ts +85 -0
  182. package/dist/types/Commit.js +139 -0
  183. package/dist/types/commitNode.d.ts +89 -0
  184. package/dist/types/commitNode.js +139 -0
  185. package/dist/types/commitNode.test.d.ts +1 -0
  186. package/dist/types/commitNode.test.js +255 -0
  187. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  188. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  189. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  190. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  191. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
  192. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  193. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  194. package/dist/ui/getCommits.d.ts +1 -1
  195. package/dist/ui/getCommits.js +55 -25
  196. package/dist/ui/getTargetBranches.d.ts +2 -2
  197. package/dist/ui/getTargetBranches.js +16 -17
  198. package/dist/ui/getTargetBranches.test.js +75 -99
  199. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  200. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  201. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  202. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  203. package/dist/ui/maybeSetupRepo.js +9 -9
  204. package/dist/ui/maybeSetupRepo.test.js +5 -1
  205. package/package.json +36 -51
  206. package/yarn.lock +2387 -2987
@@ -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 {};
@@ -1,68 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExistingTargetPullRequests = exports.getPullRequestLabels = exports.pullRequestFragment = exports.pullRequestFragmentName = void 0;
3
+ exports.getExistingTargetPullRequests = void 0;
4
4
  const filterEmpty_1 = require("../../../utils/filterEmpty");
5
5
  const commitFormatters_1 = require("../commitFormatters");
6
- exports.pullRequestFragmentName = 'ExistingTargetPullRequests';
7
- exports.pullRequestFragment = `
8
- fragment ${exports.pullRequestFragmentName} on PullRequest {
9
- # Source PR
10
- number
11
- repository {
12
- name
13
- owner {
14
- login
15
- }
16
- }
17
- mergeCommit {
18
- oid
19
- message
20
- }
21
- labels(first: 50) {
22
- nodes {
23
- name
24
- }
25
- }
26
- baseRefName
27
- timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
28
- edges {
29
- node {
30
- ... on CrossReferencedEvent {
31
- source {
32
- __typename
33
-
34
- # Target PRs
35
- ... on PullRequest {
36
- title
37
- state
38
- baseRefName
39
- number
40
- commits(first: 20) {
41
- edges {
42
- node {
43
- commit {
44
- message
45
- }
46
- }
47
- }
48
- }
49
- }
50
- }
51
- }
52
- }
53
- }
54
- }
55
- }
56
- `;
57
- function getPullRequestLabels(pullRequestNode) {
58
- return pullRequestNode === null || pullRequestNode === void 0 ? void 0 : pullRequestNode.labels.nodes.map((label) => label.name);
59
- }
60
- exports.getPullRequestLabels = getPullRequestLabels;
61
6
  function getExistingTargetPullRequests(sourcePullRequest) {
62
7
  if (!sourcePullRequest || !sourcePullRequest.mergeCommit) {
63
8
  return [];
64
9
  }
65
- const sourcePRMergeCommitMessage = commitFormatters_1.getFirstCommitMessageLine(sourcePullRequest.mergeCommit.message);
10
+ const sourcePRMergeCommitMessage = (0, commitFormatters_1.getFirstCommitMessageLine)(sourcePullRequest.mergeCommit.message);
66
11
  return sourcePullRequest.timelineItems.edges
67
12
  .filter(filterEmpty_1.filterNil)
68
13
  .filter(filterPullRequests)
@@ -73,7 +18,7 @@ function getExistingTargetPullRequests(sourcePullRequest) {
73
18
  }
74
19
  // at least one of the commits in the target pull request should match the merge commit from the source pull request
75
20
  const commitMatch = source.commits.edges.some((commit) => {
76
- const targetPRCommitMessage = commitFormatters_1.getFirstCommitMessageLine(commit.node.commit.message);
21
+ const targetPRCommitMessage = (0, commitFormatters_1.getFirstCommitMessageLine)(commit.node.commit.message);
77
22
  return targetPRCommitMessage === sourcePRMergeCommitMessage;
78
23
  });
79
24
  const prTitleMatch = source.title.includes(sourcePRMergeCommitMessage);
@@ -1,15 +1,16 @@
1
+ import { ConfigFileOptions } from '../../../../options/ConfigOptions';
1
2
  import { OptionsFromCliArgs } from '../../../../options/cliArgs';
2
- import { OptionsFromConfigFiles } from '../../../../options/config/config';
3
- import { PromiseReturnType } from '../../../../types/PromiseReturnType';
4
- export declare type OptionsFromGithub = PromiseReturnType<typeof getOptionsFromGithub>;
5
- export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFromConfigFiles, optionsFromCliArgs: OptionsFromCliArgs): Promise<{
3
+ export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
4
+ export declare function getOptionsFromGithub(optionsFromConfigFiles: ConfigFileOptions, optionsFromCliArgs: OptionsFromCliArgs): Promise<{
5
+ historicalBranchLabelMappings: {
6
+ branchLabelMapping: Record<string, string>;
7
+ committedDate: string;
8
+ }[];
6
9
  accessToken?: string | undefined;
7
10
  all?: boolean | undefined;
8
11
  assignees?: string[] | undefined;
9
12
  author?: string | undefined;
10
13
  autoAssign?: boolean | undefined;
11
- autoMerge?: boolean | undefined;
12
- autoMergeMethod?: string | undefined;
13
14
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
14
15
  files: string[];
15
16
  directory: string;
@@ -22,8 +23,12 @@ export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFrom
22
23
  };
23
24
  targetBranch: string;
24
25
  }) => boolean | Promise<boolean>) | undefined;
25
- branchLabelMapping?: Record<string, string> | undefined;
26
+ autoMerge?: boolean | undefined;
27
+ autoMergeMethod?: string | undefined;
26
28
  ci?: boolean | undefined;
29
+ cherrypickRef?: boolean | undefined;
30
+ commitPaths?: string[] | undefined;
31
+ details?: boolean | undefined;
27
32
  editor?: string | undefined;
28
33
  forceLocalConfig?: boolean | undefined;
29
34
  fork?: boolean | undefined;
@@ -35,21 +40,22 @@ export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFrom
35
40
  multipleBranches?: boolean | undefined;
36
41
  multipleCommits?: boolean | undefined;
37
42
  noVerify?: boolean | undefined;
38
- path?: string | undefined;
39
43
  prDescription?: string | undefined;
40
44
  prFilter?: string | undefined;
41
45
  prTitle?: string | undefined;
42
46
  pullNumber?: number | undefined;
43
47
  resetAuthor?: boolean | undefined;
48
+ reviewers?: string[] | undefined;
44
49
  sha?: string | undefined;
45
50
  sourceBranch: string;
46
51
  sourcePRLabels?: string[] | undefined;
47
- targetBranchChoices?: import("../../../../options/ConfigOptions").BranchChoiceRaw[] | undefined;
52
+ targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
48
53
  targetBranches?: string[] | undefined;
49
54
  targetPRLabels?: string[] | undefined;
50
55
  upstream?: string | undefined;
51
56
  username?: string | undefined;
52
57
  verbose?: boolean | undefined;
53
- branches?: import("../../../../options/ConfigOptions").BranchChoiceRaw[] | undefined;
58
+ branchLabelMapping?: Record<string, string> | undefined;
59
+ branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
54
60
  labels?: string[] | undefined;
55
61
  }>;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionsFromGithub = void 0;
7
7
  const ora_1 = __importDefault(require("ora"));
8
8
  const parseRequiredOptions_1 = require("../../../../options/parseRequiredOptions");
9
+ const filterEmpty_1 = require("../../../../utils/filterEmpty");
9
10
  const HandledError_1 = require("../../../HandledError");
10
11
  const git_1 = require("../../../git");
11
12
  const logger_1 = require("../../../logger");
@@ -13,17 +14,16 @@ const apiRequestV4_1 = require("../apiRequestV4");
13
14
  const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
14
15
  const query_1 = require("./query");
15
16
  async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs) {
16
- var _a, _b, _c, _d, _e;
17
17
  const options = {
18
18
  ...optionsFromConfigFiles,
19
19
  ...optionsFromCliArgs,
20
20
  };
21
21
  const { githubApiBaseUrlV4 } = options;
22
- const { accessToken, repoName, repoOwner } = parseRequiredOptions_1.getRequiredOptions(options);
22
+ const { accessToken, repoName, repoOwner } = (0, parseRequiredOptions_1.getRequiredOptions)(options);
23
23
  let res;
24
- const spinner = ora_1.default().start('Initializing...');
24
+ const spinner = (0, ora_1.default)().start('Initializing...');
25
25
  try {
26
- res = await apiRequestV4_1.apiRequestV4({
26
+ res = await (0, apiRequestV4_1.apiRequestV4)({
27
27
  githubApiBaseUrlV4,
28
28
  accessToken,
29
29
  query: query_1.query,
@@ -35,31 +35,32 @@ async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)
35
35
  catch (e) {
36
36
  spinner.stop();
37
37
  const error = e;
38
- throwOnInvalidAccessToken_1.throwOnInvalidAccessToken({
38
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
39
39
  error,
40
40
  repoName,
41
41
  repoOwner,
42
42
  });
43
- const configFileNotFound = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data.errors) === null || _b === void 0 ? void 0 : _b.some((error) => error.type === 'NOT_FOUND' &&
43
+ const configFileNotFound = error.response?.data.errors?.some((error) => error.type === 'NOT_FOUND' &&
44
44
  error.path.join('.') ===
45
- 'repository.defaultBranchRef.target.jsonConfigFile.edges.0.config.file');
46
- if (configFileNotFound && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data.data)) {
45
+ 'repository.defaultBranchRef.target.history.edges.0.remoteConfig.file');
46
+ if (configFileNotFound && error.response?.data.data) {
47
47
  // swallow error if caused by missing config file on Github
48
48
  res = error.response.data.data;
49
49
  }
50
50
  else {
51
51
  // throw generic Github error
52
- throw apiRequestV4_1.handleGithubV4Error(error);
52
+ throw (0, apiRequestV4_1.handleGithubV4Error)(error);
53
53
  }
54
54
  }
55
55
  // get the original repo (not the fork)
56
56
  const repo = res.repository.isFork ? res.repository.parent : res.repository;
57
57
  // it is not possible to have a branch named "backport"
58
- if (((_d = repo.ref) === null || _d === void 0 ? void 0 : _d.name) === 'backport') {
58
+ if (repo.ref?.name === 'backport') {
59
59
  throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
60
60
  }
61
- const remoteConfig = (_e = repo.defaultBranchRef.target.jsonConfigFile.edges[0]) === null || _e === void 0 ? void 0 : _e.config;
62
- const remoteConfigFile = await getRemoteConfigFile(options, remoteConfig);
61
+ const historicalRemoteConfigs = repo.defaultBranchRef.target.history.edges;
62
+ const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
63
+ const skipRemoteConfig = await getSkipRemoteConfigFile(options, latestRemoteConfig);
63
64
  const defaultBranch = repo.defaultBranchRef.name;
64
65
  // if no sourceBranch is given, use the `defaultBranch` (normally "master")
65
66
  const sourceBranch = options.sourceBranch
@@ -67,35 +68,44 @@ async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)
67
68
  : defaultBranch;
68
69
  return {
69
70
  sourceBranch,
70
- ...remoteConfigFile,
71
+ ...(skipRemoteConfig ? {} : parseRemoteConfig(latestRemoteConfig)),
72
+ historicalBranchLabelMappings: skipRemoteConfig
73
+ ? []
74
+ : getHistoricalBranchLabelMappings(historicalRemoteConfigs),
71
75
  };
72
76
  }
73
77
  exports.getOptionsFromGithub = getOptionsFromGithub;
74
- async function getRemoteConfigFile(options, remoteConfig) {
78
+ async function getSkipRemoteConfigFile(options, remoteConfig) {
75
79
  if (options.forceLocalConfig) {
76
80
  logger_1.logger.info('Skipping remote config: `--force-local-config` specified via config file or cli');
77
- return;
81
+ return true;
78
82
  }
79
83
  if (!remoteConfig) {
80
84
  logger_1.logger.info("Skipping remote config: remote config doesn't exist");
81
- return;
85
+ return true;
82
86
  }
83
- const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate,] = await Promise.all([
84
- git_1.isLocalConfigFileModified(),
85
- git_1.isLocalConfigFileUntracked(),
86
- git_1.getLocalConfigFileCommitDate(),
87
+ const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
88
+ (0, git_1.isLocalConfigFileModified)(),
89
+ (0, git_1.isLocalConfigFileUntracked)(),
90
+ (0, git_1.getLocalConfigFileCommitDate)(),
87
91
  ]);
88
92
  if (isLocalConfigUntracked) {
89
93
  logger_1.logger.info('Skipping remote config: local config is new');
90
- return;
94
+ return true;
91
95
  }
92
96
  if (isLocalConfigModified) {
93
97
  logger_1.logger.info('Skipping remote config: local config is modified');
94
- return;
98
+ return true;
95
99
  }
96
100
  if (localCommitDate &&
97
101
  localCommitDate > Date.parse(remoteConfig.committedDate)) {
98
102
  logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
+ function parseRemoteConfig(remoteConfig) {
108
+ if (!remoteConfig) {
99
109
  return;
100
110
  }
101
111
  try {
@@ -107,3 +117,23 @@ async function getRemoteConfigFile(options, remoteConfig) {
107
117
  return;
108
118
  }
109
119
  }
120
+ function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
121
+ return historicalRemoteConfigs
122
+ .map((edge) => {
123
+ try {
124
+ const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
125
+ if (!remoteConfig.branchLabelMapping) {
126
+ return;
127
+ }
128
+ return {
129
+ branchLabelMapping: remoteConfig.branchLabelMapping,
130
+ committedDate: edge.remoteConfig.committedDate,
131
+ };
132
+ }
133
+ catch (e) {
134
+ logger_1.logger.info('Could not get historical remote config', e);
135
+ return;
136
+ }
137
+ })
138
+ .filter(filterEmpty_1.filterNil);
139
+ }
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const os_1 = __importDefault(require("os"));
3
7
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
8
  const _1 = require(".");
5
9
  describe('getOptionsFromGithub', () => {
6
10
  let devAccessToken;
7
11
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
12
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
13
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
9
14
  });
10
15
  describe('access token', () => {
11
16
  describe('is invalid', () => {
@@ -17,7 +22,7 @@ describe('getOptionsFromGithub', () => {
17
22
  upstream: 'backport-org/backport-e2e',
18
23
  };
19
24
  const optionsFromCliArgs = {};
20
- await expect(_1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
25
+ await expect((0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
21
26
  });
22
27
  });
23
28
  describe('is valid', () => {
@@ -29,7 +34,7 @@ describe('getOptionsFromGithub', () => {
29
34
  upstream: 'backport-org/backport-e2e',
30
35
  };
31
36
  const optionsFromCliArgs = {};
32
- expect(await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)).toEqual({
37
+ expect(await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs)).toEqual({
33
38
  branchLabelMapping: {
34
39
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
35
40
  '^v7.9.0$': '7.x',
@@ -56,7 +61,7 @@ describe('getOptionsFromGithub', () => {
56
61
  upstream: 'sqren/backport-e2e',
57
62
  };
58
63
  const optionsFromCliArgs = {};
59
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
64
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
60
65
  await expect(options.upstream).toEqual('backport-org/backport-e2e');
61
66
  });
62
67
  });
@@ -70,7 +75,7 @@ describe('getOptionsFromGithub', () => {
70
75
  upstream: 'backport-org/repo-with-non-standard-main-branch',
71
76
  };
72
77
  const optionsFromCliArgs = {};
73
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
78
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
74
79
  await expect(options.sourceBranch).toEqual('my-custom-default-branch');
75
80
  });
76
81
  });
@@ -84,7 +89,7 @@ describe('getOptionsFromGithub', () => {
84
89
  upstream: 'backport-org/repo-with-non-standard-main-branch',
85
90
  };
86
91
  const optionsFromCliArgs = {};
87
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
92
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
88
93
  await expect(options.sourceBranch).toEqual('my-specific-source-branch');
89
94
  });
90
95
  });
@@ -100,9 +105,22 @@ describe('getOptionsFromGithub', () => {
100
105
  };
101
106
  const optionsFromCliArgs = {};
102
107
  await expect(async () => {
103
- await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
108
+ await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
104
109
  }).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
105
110
  });
106
111
  });
107
112
  });
113
+ describe('when a backportrc.json config was deleted from repo', () => {
114
+ it('does not throw', async () => {
115
+ const optionsFromConfigFiles = {
116
+ username: 'sqren',
117
+ accessToken: devAccessToken,
118
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
119
+ upstream: 'backport-org/repo-with-backportrc-removed',
120
+ };
121
+ const optionsFromCliArgs = {};
122
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
123
+ expect(options).toEqual({ sourceBranch: 'main' });
124
+ });
125
+ });
108
126
  });
@@ -6,23 +6,21 @@ export declare type RemoteConfig = {
6
6
  };
7
7
  };
8
8
  };
9
- declare type Ref = {
10
- name: string;
11
- } | null;
12
- declare type DefaultBranchRef = {
13
- name: string;
14
- target: {
15
- jsonConfigFile: {
16
- edges: ({
17
- config: RemoteConfig;
18
- } | undefined)[];
9
+ export declare type Repository = {
10
+ ref: {
11
+ name: string;
12
+ } | null;
13
+ defaultBranchRef: {
14
+ name: string;
15
+ target: {
16
+ history: {
17
+ edges: Array<{
18
+ remoteConfig: RemoteConfig;
19
+ }>;
20
+ };
19
21
  };
20
22
  };
21
23
  };
22
- export declare type Repository = {
23
- ref: Ref;
24
- defaultBranchRef: DefaultBranchRef;
25
- };
26
24
  export interface GithubConfigOptionsResponse {
27
25
  repository: {
28
26
  isFork: true;
@@ -33,5 +31,4 @@ export interface GithubConfigOptionsResponse {
33
31
  parent: null;
34
32
  } & Repository);
35
33
  }
36
- export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n repository(owner: $repoOwner, name: $repoName) {\n isFork\n ...Repo\n parent {\n ...Repo\n }\n }\n }\n\n fragment Repo on Repository {\n # check to see if a branch named \"backport\" exists\n ref(qualifiedName: \"refs/heads/backport\") {\n name\n }\n defaultBranchRef {\n name\n target {\n ...JSONConfigFile\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";
37
- export {};
34
+ export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n repository(owner: $repoOwner, name: $repoName) {\n isFork\n ...Repo\n parent {\n ...Repo\n }\n }\n }\n\n fragment Repo on Repository {\n # check to see if a branch named \"backport\" exists\n ref(qualifiedName: \"refs/heads/backport\") {\n name\n }\n defaultBranchRef {\n name\n target {\n ... on Commit {\n history(first: 20, path: \".backportrc.json\") {\n edges {\n remoteConfig: 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 }\n }\n";
@@ -20,21 +20,19 @@ exports.query = `
20
20
  defaultBranchRef {
21
21
  name
22
22
  target {
23
- ...JSONConfigFile
24
- }
25
- }
26
- }
27
-
28
- fragment JSONConfigFile on Commit {
29
- jsonConfigFile: history(first: 1, path: ".backportrc.json") {
30
- edges {
31
- config: node {
32
- committedDate
33
- file(path: ".backportrc.json") {
34
- ... on TreeEntry {
35
- object {
36
- ... on Blob {
37
- text
23
+ ... on Commit {
24
+ history(first: 20, path: ".backportrc.json") {
25
+ edges {
26
+ remoteConfig: node {
27
+ committedDate
28
+ file(path: ".backportrc.json") {
29
+ ... on TreeEntry {
30
+ object {
31
+ ... on Blob {
32
+ text
33
+ }
34
+ }
35
+ }
38
36
  }
39
37
  }
40
38
  }
@@ -1,12 +1,5 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- import { ExistingTargetPullRequests } from './getExistingTargetPullRequests';
3
2
  export declare function getTargetBranchForLabel({ branchLabelMapping, label, }: {
4
3
  branchLabelMapping: NonNullable<ValidConfigOptions['branchLabelMapping']>;
5
4
  label: string;
6
5
  }): string | undefined;
7
- export declare function getTargetBranchesFromLabels({ sourceBranch, existingTargetPullRequests, branchLabelMapping, labels, }: {
8
- sourceBranch: string;
9
- existingTargetPullRequests: ExistingTargetPullRequests;
10
- branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
11
- labels?: string[];
12
- }): string[];
@@ -1,12 +1,6 @@
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
- exports.getTargetBranchesFromLabels = exports.getTargetBranchForLabel = void 0;
7
- const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
8
- const filterEmpty_1 = require("../../../utils/filterEmpty");
9
- const logger_1 = require("../../logger");
3
+ exports.getTargetBranchForLabel = void 0;
10
4
  function getTargetBranchForLabel({ branchLabelMapping, label, }) {
11
5
  // only get first match
12
6
  const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
@@ -24,22 +18,3 @@ function getTargetBranchForLabel({ branchLabelMapping, label, }) {
24
18
  }
25
19
  }
26
20
  exports.getTargetBranchForLabel = getTargetBranchForLabel;
27
- function getTargetBranchesFromLabels({ sourceBranch, existingTargetPullRequests, branchLabelMapping, labels, }) {
28
- if (!branchLabelMapping || !labels) {
29
- return [];
30
- }
31
- const existingBranches = existingTargetPullRequests.map((pr) => pr.branch);
32
- const targetBranches = labels
33
- .map((label) => getTargetBranchForLabel({ branchLabelMapping, label }))
34
- .filter(filterEmpty_1.filterNil)
35
- .filter((targetBranch) => !existingBranches.includes(targetBranch))
36
- .filter((targetBranch) => targetBranch !== sourceBranch);
37
- logger_1.logger.verbose('Inputs when calculating target branches:', {
38
- labels,
39
- branchLabelMapping,
40
- existingTargetPullRequests,
41
- });
42
- logger_1.logger.verbose('Target branches inferred from labels:', targetBranches);
43
- return lodash_uniq_1.default(targetBranches);
44
- }
45
- exports.getTargetBranchesFromLabels = getTargetBranchesFromLabels;