backport 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +41 -42
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +4 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +58 -0
  18. package/dist/lib/env.d.ts +7 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +206 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +4 -2
  151. package/dist/options/cliArgs.d.ts +15 -12
  152. package/dist/options/cliArgs.js +34 -19
  153. package/dist/options/cliArgs.test.js +125 -1
  154. package/dist/options/config/config.d.ts +5 -4
  155. package/dist/options/config/config.js +3 -5
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +3 -1
  158. package/dist/options/config/globalConfig.js +5 -5
  159. package/dist/options/config/readConfigFile.d.ts +9 -7
  160. package/dist/options/config/readConfigFile.js +2 -2
  161. package/dist/options/options.d.ts +43 -7
  162. package/dist/options/options.js +20 -24
  163. package/dist/options/options.test.js +112 -54
  164. package/dist/runSequentially.d.ts +10 -7
  165. package/dist/runSequentially.js +5 -5
  166. package/dist/scripts/postinstall.js +3 -3
  167. package/dist/scripts/postinstall.test.js +1 -1
  168. package/dist/services/BackportError.d.ts +19 -0
  169. package/dist/services/BackportError.js +29 -0
  170. package/dist/services/HandledBackportError.d.ts +19 -0
  171. package/dist/services/HandledBackportError.js +29 -0
  172. package/dist/services/HandledError.d.ts +1 -1
  173. package/dist/services/HandledError.js +5 -5
  174. package/dist/services/git.js +7 -7
  175. package/dist/services/github/v3/createPullRequest.js +2 -2
  176. package/dist/services/github/v3/createStatusComment.js +2 -2
  177. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  178. package/dist/services/github/v4/apiRequestV4.js +2 -2
  179. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  180. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  181. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  182. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  183. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  184. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  185. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  186. package/dist/state.d.ts +0 -0
  187. package/dist/state.js +1 -0
  188. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  189. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  190. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
  191. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
  192. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  193. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  194. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  195. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  196. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  197. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  199. package/dist/ui/getCommits.js +2 -2
  200. package/dist/ui/getTargetBranches.js +3 -3
  201. package/dist/ui/setupRepo.js +2 -2
  202. package/dist/utils/packageVersion.d.ts +1 -1
  203. package/dist/utils/packageVersion.js +1 -1
  204. package/package.json +12 -12
  205. package/yarn.lock +112 -65
@@ -0,0 +1,108 @@
1
+ import { ValidConfigOptions } from '../../options/options';
2
+ import { RemoteConfigHistory } from '../remoteConfig';
3
+ import { ExpectedTargetPullRequest } from './getExpectedTargetPullRequests';
4
+ export interface Commit {
5
+ author: SourceCommitWithTargetPullRequest['author'];
6
+ sourceCommit: {
7
+ committedDate: string;
8
+ message: string;
9
+ sha: string;
10
+ };
11
+ sourcePullRequest?: {
12
+ number: number;
13
+ url: string;
14
+ mergeCommit: {
15
+ message: string;
16
+ sha: string;
17
+ };
18
+ };
19
+ sourceBranch: string;
20
+ expectedTargetPullRequests: ExpectedTargetPullRequest[];
21
+ }
22
+ export interface SourcePullRequestNode {
23
+ baseRefName: string;
24
+ url: string;
25
+ number: number;
26
+ labels: {
27
+ nodes: {
28
+ name: string;
29
+ }[];
30
+ };
31
+ mergeCommit: {
32
+ remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
33
+ sha: string;
34
+ message: string;
35
+ };
36
+ timelineItems: {
37
+ edges: TimelineEdge[];
38
+ };
39
+ }
40
+ export declare type TimelineEdge = TimelinePullRequestEdge | TimelineIssueEdge;
41
+ export interface TimelinePullRequestEdge {
42
+ node: {
43
+ targetPullRequest: {
44
+ __typename: 'PullRequest';
45
+ url: string;
46
+ title: string;
47
+ state: 'OPEN' | 'CLOSED' | 'MERGED';
48
+ baseRefName: string;
49
+ number: number;
50
+ targetMergeCommit: {
51
+ sha: string;
52
+ message: string;
53
+ } | null;
54
+ repository: {
55
+ name: string;
56
+ owner: {
57
+ login: string;
58
+ };
59
+ };
60
+ commits: {
61
+ edges: Array<{
62
+ node: {
63
+ targetCommit: {
64
+ message: string;
65
+ sha: string;
66
+ };
67
+ };
68
+ }>;
69
+ };
70
+ };
71
+ };
72
+ }
73
+ interface TimelineIssueEdge {
74
+ node: {
75
+ targetPullRequest: {
76
+ __typename: 'Issue';
77
+ };
78
+ };
79
+ }
80
+ export declare type SourceCommitWithTargetPullRequest = {
81
+ repository: {
82
+ name: string;
83
+ owner: {
84
+ login: string;
85
+ };
86
+ };
87
+ sha: string;
88
+ message: string;
89
+ committedDate: string;
90
+ author: {
91
+ name: string;
92
+ email: string;
93
+ };
94
+ associatedPullRequests: {
95
+ edges: {
96
+ node: SourcePullRequestNode;
97
+ }[] | null;
98
+ };
99
+ };
100
+ export declare function parseSourceCommit({ sourceCommit, options, }: {
101
+ sourceCommit: SourceCommitWithTargetPullRequest;
102
+ options: {
103
+ branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
104
+ sourceBranch: string;
105
+ };
106
+ }): Commit;
107
+ export declare const SourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
108
+ export {};
@@ -0,0 +1,123 @@
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.SourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const remoteConfig_1 = require("../remoteConfig");
9
+ const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
10
+ function parseSourceCommit({ sourceCommit, options, }) {
11
+ const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
12
+ return {
13
+ author: sourceCommit.author,
14
+ sourceCommit: {
15
+ committedDate: sourceCommit.committedDate,
16
+ message: sourceCommit.message,
17
+ sha: sourceCommit.sha,
18
+ },
19
+ sourcePullRequest: sourcePullRequest
20
+ ? {
21
+ number: sourcePullRequest.number,
22
+ url: sourcePullRequest.url,
23
+ mergeCommit: {
24
+ message: sourcePullRequest.mergeCommit.message,
25
+ sha: sourcePullRequest.mergeCommit.sha,
26
+ },
27
+ }
28
+ : undefined,
29
+ sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
30
+ expectedTargetPullRequests: (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
31
+ sourceCommit,
32
+ latestBranchLabelMapping: options.branchLabelMapping,
33
+ }),
34
+ };
35
+ }
36
+ exports.parseSourceCommit = parseSourceCommit;
37
+ exports.SourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
38
+ fragment SourceCommitWithTargetPullRequestFragment on Commit {
39
+ # Source Commit
40
+ repository {
41
+ name
42
+ owner {
43
+ login
44
+ }
45
+ }
46
+ sha: oid
47
+ message
48
+ committedDate
49
+
50
+ author {
51
+ name
52
+ email
53
+ }
54
+
55
+ # Source pull request: PR where source commit was merged in
56
+ associatedPullRequests(first: 1) {
57
+ edges {
58
+ node {
59
+ url
60
+ number
61
+ labels(first: 50) {
62
+ nodes {
63
+ name
64
+ }
65
+ }
66
+ baseRefName
67
+
68
+ # source merge commit (the commit that actually went into the source branch)
69
+ mergeCommit {
70
+ ...RemoteConfigHistoryFragment
71
+ sha: oid
72
+ message
73
+ }
74
+
75
+ # (possible) backport pull requests referenced in the source pull request
76
+ timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
77
+ edges {
78
+ node {
79
+ ... on CrossReferencedEvent {
80
+ targetPullRequest: source {
81
+ __typename
82
+
83
+ # Target PRs (backport PRs)
84
+ ... on PullRequest {
85
+ # target merge commit: the backport commit that was merged into the target branch
86
+ targetMergeCommit: mergeCommit {
87
+ sha: oid
88
+ message
89
+ }
90
+ repository {
91
+ name
92
+ owner {
93
+ login
94
+ }
95
+ }
96
+ url
97
+ title
98
+ state
99
+ baseRefName
100
+ number
101
+ commits(first: 20) {
102
+ edges {
103
+ node {
104
+ targetCommit: commit {
105
+ message
106
+ sha: oid
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ ${remoteConfig_1.RemoteConfigHistoryFragment}
123
+ `;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getMockSourceCommit_1 = require("./getMockSourceCommit");
4
+ const parseSourceCommit_1 = require("./parseSourceCommit");
5
+ describe('parseSourceCommit', () => {
6
+ describe('pullNumber', () => {
7
+ it('receives `pullNumber` from the associated pull request', () => {
8
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
9
+ sourceCommit: { message: 'My commit message (#1234)' },
10
+ sourcePullRequest: { number: 55 },
11
+ });
12
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
13
+ sourceCommit: mockSourceCommit,
14
+ options: {},
15
+ });
16
+ expect(commit.sourcePullRequest?.number).toBe(55);
17
+ });
18
+ });
19
+ describe('sourceBranch', () => {
20
+ it('sets sourceBranch based on `baseRefName` from associated PR', () => {
21
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
22
+ sourceCommit: { message: 'My commit message (#66)' },
23
+ sourcePullRequest: { number: 55, sourceBranch: 'a sourcebranch' },
24
+ });
25
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
26
+ sourceCommit: mockSourceCommit,
27
+ options: {},
28
+ });
29
+ expect(commit.sourceBranch).toBe('a sourcebranch');
30
+ });
31
+ it('sets uses options.sourceBranch as fallback', () => {
32
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
33
+ sourceCommit: { message: 'My commit message (#66)' },
34
+ sourcePullRequest: null,
35
+ });
36
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
37
+ sourceCommit: mockSourceCommit,
38
+ options: {
39
+ sourceBranch: 'sourcebranch-from-options',
40
+ },
41
+ });
42
+ expect(commit.sourceBranch).toBe('sourcebranch-from-options');
43
+ });
44
+ });
45
+ describe('expectedTargetPullRequests', () => {
46
+ it('uses options.branchLabelMapping when historicalBranchLabelMappings is empty', () => {
47
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
48
+ sourceCommit: {
49
+ message: 'My commit message (#66)',
50
+ commitedDate: '2021-03-03T00:00:00Z',
51
+ },
52
+ sourcePullRequest: {
53
+ sourceBranch: 'main',
54
+ number: 55,
55
+ labels: ['v6.4.0', 'v6.3.0', 'v6.2.0', 'v6.1.0'],
56
+ },
57
+ timelineItems: [
58
+ {
59
+ state: 'MERGED',
60
+ targetBranch: '6.3',
61
+ commitMessages: ['My commit message (#66)'],
62
+ number: 5678,
63
+ },
64
+ {
65
+ state: 'OPEN',
66
+ targetBranch: '6.2',
67
+ commitMessages: ['My commit message (#66)'],
68
+ number: 9876,
69
+ },
70
+ ],
71
+ });
72
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
73
+ sourceCommit: mockSourceCommit,
74
+ options: {
75
+ branchLabelMapping: {
76
+ '^v6.4.0$': 'main',
77
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
78
+ },
79
+ },
80
+ });
81
+ expect(commit.expectedTargetPullRequests).toEqual([
82
+ {
83
+ branch: '6.3',
84
+ number: 5678,
85
+ state: 'MERGED',
86
+ url: 'https://github.com/elastic/kibana/pull/5678',
87
+ mergeCommit: {
88
+ message: 'My commit message (#66)',
89
+ sha: 'target-merge-commit-sha',
90
+ },
91
+ },
92
+ {
93
+ branch: '6.2',
94
+ number: 9876,
95
+ state: 'OPEN',
96
+ url: 'https://github.com/elastic/kibana/pull/9876',
97
+ },
98
+ {
99
+ branch: '6.1',
100
+ state: 'NOT_CREATED',
101
+ },
102
+ ]);
103
+ });
104
+ it('uses the historical branchLabelMapping from 2021-02-02', () => {
105
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
106
+ sourceCommit: {
107
+ remoteConfig: {
108
+ branchLabelMapping: {
109
+ '^v6.3.0$': 'main',
110
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
111
+ },
112
+ committedDate: '2021-02-02T00:00:00Z',
113
+ },
114
+ message: 'My commit message (#66)',
115
+ commitedDate: '2021-03-03T00:00:00Z',
116
+ },
117
+ sourcePullRequest: {
118
+ sourceBranch: 'main',
119
+ number: 55,
120
+ labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
121
+ },
122
+ timelineItems: [
123
+ {
124
+ state: 'OPEN',
125
+ targetBranch: '6.2',
126
+ commitMessages: ['My commit message (#66)'],
127
+ number: 9876,
128
+ },
129
+ ],
130
+ });
131
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
132
+ sourceCommit: mockSourceCommit,
133
+ options: {
134
+ branchLabelMapping: {
135
+ '^v6.4.0$': 'main',
136
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
137
+ },
138
+ },
139
+ });
140
+ expect(commit.expectedTargetPullRequests).toEqual([
141
+ {
142
+ branch: '6.2',
143
+ number: 9876,
144
+ state: 'OPEN',
145
+ url: 'https://github.com/elastic/kibana/pull/9876',
146
+ },
147
+ {
148
+ branch: '6.1',
149
+ state: 'NOT_CREATED',
150
+ },
151
+ ]);
152
+ });
153
+ });
154
+ it('returns the correct source commit', () => {
155
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
156
+ sourceCommit: { message: 'My commit message (#1234)', sha: 'my-sha' },
157
+ sourcePullRequest: {
158
+ number: 1234,
159
+ labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
160
+ },
161
+ timelineItems: [
162
+ {
163
+ state: 'MERGED',
164
+ targetBranch: '6.x',
165
+ commitMessages: ['My commit message (#1234)'],
166
+ number: 5678,
167
+ },
168
+ {
169
+ state: 'OPEN',
170
+ targetBranch: '6.2',
171
+ commitMessages: ['My commit message (#1234)'],
172
+ number: 9876,
173
+ },
174
+ ],
175
+ });
176
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
177
+ sourceCommit: mockSourceCommit,
178
+ options: {
179
+ branchLabelMapping: {
180
+ '^v6.3.0$': '6.x',
181
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
182
+ },
183
+ },
184
+ });
185
+ const expectedCommit = {
186
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
187
+ sourceCommit: {
188
+ committedDate: '2021-12-22T00:00:00Z',
189
+ message: 'My commit message (#1234)',
190
+ sha: 'my-sha',
191
+ },
192
+ sourcePullRequest: {
193
+ number: 1234,
194
+ url: 'https://github.com/elastic/kibana/pull/1234',
195
+ mergeCommit: {
196
+ message: 'My commit message (#1234)',
197
+ sha: 'my-sha',
198
+ },
199
+ },
200
+ sourceBranch: 'source-branch-from-associated-pull-request',
201
+ expectedTargetPullRequests: [
202
+ {
203
+ branch: '6.x',
204
+ number: 5678,
205
+ state: 'MERGED',
206
+ url: 'https://github.com/elastic/kibana/pull/5678',
207
+ mergeCommit: {
208
+ message: 'My commit message (#1234)',
209
+ sha: 'target-merge-commit-sha',
210
+ },
211
+ },
212
+ {
213
+ branch: '6.2',
214
+ number: 9876,
215
+ state: 'OPEN',
216
+ url: 'https://github.com/elastic/kibana/pull/9876',
217
+ },
218
+ {
219
+ branch: '6.1',
220
+ state: 'NOT_CREATED',
221
+ },
222
+ ],
223
+ };
224
+ expect(commit).toEqual(expectedCommit);
225
+ });
226
+ });
@@ -20,7 +20,6 @@ declare type Options = Partial<{
20
20
  autoMergeMethod: string;
21
21
  backportBinary: string;
22
22
  cherrypickRef: boolean;
23
- ci: boolean;
24
23
  commitPaths: string[];
25
24
  details: boolean;
26
25
  dir: string;
@@ -32,6 +31,7 @@ declare type Options = Partial<{
32
31
  gitHostname: string;
33
32
  githubApiBaseUrlV3: string;
34
33
  githubApiBaseUrlV4: string;
34
+ interactive: boolean;
35
35
  logFilePath: string;
36
36
  ls: boolean;
37
37
  maxNumber: number;
@@ -43,7 +43,9 @@ declare type Options = Partial<{
43
43
  prFilter: string;
44
44
  projectConfigFile: string;
45
45
  prTitle: string;
46
- publishStatusComment: boolean;
46
+ publishStatusCommentOnAbort: boolean;
47
+ publishStatusCommentOnFailure: boolean;
48
+ publishStatusCommentOnSuccess: boolean;
47
49
  pullNumber: number;
48
50
  repoForkOwner: string;
49
51
  repoName: string;
@@ -1,28 +1,29 @@
1
- import yargs from 'yargs';
1
+ import { ConfigFileOptions } from './ConfigOptions';
2
2
  export declare type OptionsFromCliArgs = ReturnType<typeof getOptionsFromCliArgs>;
3
3
  export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
4
- cwd?: string | undefined;
5
- fork?: boolean | undefined;
6
- dir?: string | undefined;
4
+ logFilePath?: string | undefined;
7
5
  accessToken?: string | undefined;
8
6
  author?: string | null | undefined;
9
7
  autoAssign?: boolean | undefined;
10
8
  assignees?: string[] | undefined;
11
9
  autoMerge?: boolean | undefined;
12
10
  autoMergeMethod?: string | undefined;
13
- ci?: boolean | undefined;
14
11
  cherrypickRef?: boolean | undefined;
12
+ cwd?: string | undefined;
15
13
  projectConfigFile?: string | undefined;
14
+ globalConfigFile?: string | undefined;
15
+ dir?: string | undefined;
16
16
  details?: boolean | undefined;
17
17
  dryRun?: boolean | undefined;
18
18
  editor?: string | undefined;
19
19
  skipRemoteConfig?: boolean | undefined;
20
+ fork?: boolean | undefined;
20
21
  gitHostname?: string | undefined;
21
22
  githubApiBaseUrlV3?: string | undefined;
22
23
  githubApiBaseUrlV4?: string | undefined;
23
24
  gitAuthorName?: string | undefined;
24
25
  gitAuthorEmail?: string | undefined;
25
- logFilePath?: string | undefined;
26
+ interactive?: boolean | undefined;
26
27
  ls?: boolean | undefined;
27
28
  mainline?: number | undefined;
28
29
  maxNumber?: number | undefined;
@@ -48,10 +49,12 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
48
49
  targetBranchChoices?: string[] | undefined;
49
50
  targetBranches?: string[] | undefined;
50
51
  targetPRLabels?: string[] | undefined;
51
- publishStatusComment?: boolean | undefined;
52
+ publishStatusCommentOnSuccess?: boolean | undefined;
53
+ publishStatusCommentOnFailure?: boolean | undefined;
54
+ publishStatusCommentOnAbort?: boolean | undefined;
55
+ };
56
+ export declare function getEarlyArguments(processArgs: string[], optionsFromModule?: ConfigFileOptions): {
57
+ interactive: boolean;
58
+ logFilePath: any;
59
+ ls: any;
52
60
  };
53
- export declare class CliError extends Error {
54
- message: string;
55
- yargs: yargs.Argv;
56
- constructor(message: string, yargs: yargs.Argv);
57
- }
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CliError = exports.getOptionsFromCliArgs = void 0;
6
+ exports.getEarlyArguments = exports.getOptionsFromCliArgs = void 0;
7
7
  const yargs_1 = __importDefault(require("yargs"));
8
+ const yargs_parser_1 = __importDefault(require("yargs-parser"));
8
9
  const excludeUndefined_1 = require("../utils/excludeUndefined");
10
+ const options_1 = require("./options");
9
11
  function getOptionsFromCliArgs(processArgs) {
10
12
  const yargsInstance = (0, yargs_1.default)(processArgs)
11
13
  .strict()
@@ -54,10 +56,6 @@ function getOptionsFromCliArgs(processArgs) {
54
56
  alias: 'author',
55
57
  type: 'string',
56
58
  conflicts: 'all',
57
- })
58
- .option('ci', {
59
- description: 'Disable interactive prompts',
60
- type: 'boolean',
61
59
  })
62
60
  .option('cherrypickRef', {
63
61
  description: 'Append commit message with "(cherry picked from commit...)',
@@ -73,6 +71,10 @@ function getOptionsFromCliArgs(processArgs) {
73
71
  alias: 'config',
74
72
  description: 'Path to project config',
75
73
  type: 'string',
74
+ })
75
+ .option('globalConfigFile', {
76
+ description: 'Path to global config',
77
+ type: 'string',
76
78
  })
77
79
  .option('since', {
78
80
  description: 'ISO-8601 date for filtering commits',
@@ -130,6 +132,12 @@ function getOptionsFromCliArgs(processArgs) {
130
132
  .option('gitAuthorEmail', {
131
133
  description: `Set commit author email`,
132
134
  type: 'string',
135
+ })
136
+ .option('nonInteractive', {
137
+ alias: ['json'],
138
+ description: 'Disable interactive prompts and return response as JSON',
139
+ type: 'boolean',
140
+ conflicts: 'interactive',
133
141
  })
134
142
  .option('logFilePath', {
135
143
  hidden: true,
@@ -186,6 +194,8 @@ function getOptionsFromCliArgs(processArgs) {
186
194
  type: 'boolean',
187
195
  conflicts: ['cherrypickRef'],
188
196
  })
197
+ // cli-only
198
+ // negation of `publishStatusCommentOnSuccess` and `publishStatusCommentOnFailure`
189
199
  .option('noStatusComment', {
190
200
  description: "Don't publish status comment to Github",
191
201
  type: 'boolean',
@@ -304,24 +314,24 @@ function getOptionsFromCliArgs(processArgs) {
304
314
  .epilogue('For bugs, feature requests or questions: https://github.com/sqren/backport/issues\nOr contact me directly: https://twitter.com/sorenlouv')
305
315
  // don't kill process upon error
306
316
  // and don't log error to console
307
- .fail((msg, err, yargs) => {
317
+ .fail((msg, err) => {
308
318
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
309
319
  if (err) {
310
320
  throw err;
311
321
  }
312
- throw new CliError(msg, yargs);
322
+ throw new Error(msg);
313
323
  });
314
324
  const {
315
325
  /* eslint-disable @typescript-eslint/no-unused-vars */
316
326
  $0, _,
317
327
  /* eslint-enable @typescript-eslint/no-unused-vars */
318
328
  multiple, multipleBranches, multipleCommits, all,
319
- // repoName and repoOwner
329
+ // shorthands
320
330
  repo,
321
331
  // filters
322
332
  author, since, until,
323
333
  // negations
324
- noCherrypickRef, noFork, noStatusComment, noVerify, verify,
334
+ noCherrypickRef, noFork, noStatusComment, noVerify, verify, nonInteractive,
325
335
  // array types (should be renamed to plural form)
326
336
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
327
337
  const [repoOwner, repoName] = repo?.split('/') ?? [
@@ -352,17 +362,22 @@ function getOptionsFromCliArgs(processArgs) {
352
362
  cherrypickRef: noCherrypickRef === true ? false : restOptions.cherrypickRef,
353
363
  fork: noFork === true ? false : restOptions.fork,
354
364
  noVerify: verify ?? noVerify,
355
- publishStatusComment: noStatusComment === true ? false : undefined,
365
+ publishStatusCommentOnSuccess: noStatusComment === true ? false : undefined,
366
+ publishStatusCommentOnFailure: noStatusComment === true ? false : undefined,
367
+ publishStatusCommentOnAbort: noStatusComment === true ? false : undefined,
368
+ interactive: nonInteractive === true ? false : undefined,
356
369
  });
357
370
  }
358
371
  exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
359
- class CliError extends Error {
360
- constructor(message, yargs) {
361
- super(message);
362
- this.message = message;
363
- this.yargs = yargs;
364
- Error.captureStackTrace(this, CliError);
365
- this.name = 'CliError';
366
- }
372
+ function getEarlyArguments(processArgs, optionsFromModule) {
373
+ const { nonInteractive, json, logFilePath, ls } = (0, yargs_parser_1.default)(processArgs);
374
+ const base = { ...options_1.defaultConfigOptions, ...optionsFromModule };
375
+ return {
376
+ interactive: nonInteractive === undefined && json === undefined
377
+ ? base.interactive
378
+ : !(nonInteractive === true || json === true),
379
+ logFilePath,
380
+ ls,
381
+ };
367
382
  }
368
- exports.CliError = CliError;
383
+ exports.getEarlyArguments = getEarlyArguments;