backport 6.1.3 → 6.2.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 (169) hide show
  1. package/README.md +40 -37
  2. package/dist/backportRun.d.ts +14 -0
  3. package/dist/backportRun.js +75 -0
  4. package/dist/entrypoint.api.d.ts +22 -0
  5. package/dist/entrypoint.api.js +57 -0
  6. package/dist/entrypoint.api.private.test.d.ts +1 -0
  7. package/dist/entrypoint.api.private.test.js +37 -0
  8. package/dist/entrypoint.cli.js +3 -5
  9. package/dist/entrypoint.module.d.ts +6 -3
  10. package/dist/entrypoint.module.js +13 -7
  11. package/dist/entrypoint.module.private.test.js +4 -1
  12. package/dist/main.js +5 -1
  13. package/dist/options/ConfigOptions.d.ts +4 -0
  14. package/dist/options/cliArgs.d.ts +17 -11
  15. package/dist/options/cliArgs.js +36 -5
  16. package/dist/options/config/config.d.ts +10 -1
  17. package/dist/options/config/config.js +9 -3
  18. package/dist/options/config/config.test.js +27 -1
  19. package/dist/options/config/getProjectConfig.d.ts +0 -0
  20. package/dist/options/config/getProjectConfig.js +1 -0
  21. package/dist/options/config/globalConfig.d.ts +2 -2
  22. package/dist/options/config/globalConfig.js +16 -14
  23. package/dist/options/config/globalConfig.test.js +10 -4
  24. package/dist/options/config/projectConfig.d.ts +3 -1
  25. package/dist/options/config/projectConfig.js +5 -2
  26. package/dist/options/config/projectConfig.test.js +35 -6
  27. package/dist/options/config/readConfigFile.d.ts +26 -22
  28. package/dist/options/options.d.ts +18 -9
  29. package/dist/options/options.js +11 -4
  30. package/dist/options/options.test.js +40 -35
  31. package/dist/react-components/0-loadOptions.d.ts +6 -0
  32. package/dist/react-components/0-loadOptions.js +45 -0
  33. package/dist/react-components/1-loadCommit.d.ts +8 -0
  34. package/dist/react-components/1-loadCommit.js +88 -0
  35. package/dist/react-components/1a-loadCommit.d.ts +5 -0
  36. package/dist/react-components/1a-loadCommit.js +76 -0
  37. package/dist/react-components/1b-commitChoices.d.ts +5 -0
  38. package/dist/react-components/1b-commitChoices.js +98 -0
  39. package/dist/react-components/2-commitChoices.d.ts +8 -0
  40. package/dist/react-components/2-commitChoices.js +96 -0
  41. package/dist/react-components/2-commitsPrompt.d.ts +8 -0
  42. package/dist/react-components/2-commitsPrompt.js +96 -0
  43. package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
  44. package/dist/react-components/2-targetBranchChoices.js +109 -0
  45. package/dist/react-components/3-cherrypick.d.ts +1 -0
  46. package/dist/react-components/3-cherrypick.js +2 -0
  47. package/dist/react-components/App.d.ts +2 -0
  48. package/dist/react-components/App.js +35 -0
  49. package/dist/react-components/BackportStateContext.d.ts +33 -0
  50. package/dist/react-components/BackportStateContext.js +42 -0
  51. package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
  52. package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
  53. package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
  54. package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
  55. package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
  56. package/dist/react-components/CommitPrompt/getCommits.js +27 -0
  57. package/dist/react-components/CommitPrompt.d.ts +8 -0
  58. package/dist/react-components/CommitPrompt.js +96 -0
  59. package/dist/react-components/CustomMultiSelect.d.ts +13 -0
  60. package/dist/react-components/CustomMultiSelect.js +21 -0
  61. package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
  62. package/dist/react-components/CustomMultiSelectItem.js +12 -0
  63. package/dist/react-components/CustomSelect.d.ts +14 -0
  64. package/dist/react-components/CustomSelect.js +34 -0
  65. package/dist/react-components/ErrorBoundary.d.ts +15 -0
  66. package/dist/react-components/ErrorBoundary.js +53 -0
  67. package/dist/react-components/MultiSelect.d.ts +7 -0
  68. package/dist/react-components/MultiSelect.js +16 -0
  69. package/dist/react-components/hooks/useAsync.d.ts +12 -0
  70. package/dist/react-components/hooks/useAsync.js +73 -0
  71. package/dist/runSequentially.test.js +11 -13
  72. package/dist/scripts/postinstall.js +3 -3
  73. package/dist/services/HandledError.d.ts +1 -1
  74. package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
  75. package/dist/services/backportRun/backportRun.ci.js +81 -0
  76. package/dist/services/backportRun/backportRun.d.ts +14 -0
  77. package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
  78. package/dist/services/backportRun/backportRun.interactive.js +4 -0
  79. package/dist/services/backportRun/backportRun.js +14 -0
  80. package/dist/services/backportRun/backportState.d.ts +4 -0
  81. package/dist/services/backportRun/backportState.js +28 -0
  82. package/dist/services/backportRun/getCommits.d.ts +2 -0
  83. package/dist/services/backportRun/getCommits.js +20 -0
  84. package/dist/services/backportRun/runSequentially.d.ts +20 -0
  85. package/dist/services/backportRun/runSequentially.js +41 -0
  86. package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
  87. package/dist/services/backportRun/runSequentially.test.js +199 -0
  88. package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
  89. package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
  90. package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  91. package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
  92. package/dist/services/env.d.ts +5 -4
  93. package/dist/services/env.js +13 -11
  94. package/dist/services/env.test.js +0 -6
  95. package/dist/services/getCommits.d.ts +2 -0
  96. package/dist/services/getCommits.js +38 -0
  97. package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
  98. package/dist/services/getCommitsWithoutBackports.js +68 -0
  99. package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
  100. package/dist/services/getCommitsWithoutBackports.test.js +259 -0
  101. package/dist/services/getTargetBranches.d.ts +5 -0
  102. package/dist/services/getTargetBranches.js +60 -0
  103. package/dist/services/getTargetBranches.test.d.ts +1 -0
  104. package/dist/services/getTargetBranches.test.js +180 -0
  105. package/dist/services/git.d.ts +2 -1
  106. package/dist/services/git.js +5 -3
  107. package/dist/services/github/v3/createPullRequest.js +8 -5
  108. package/dist/services/github/v3/createPullRequest.test.js +60 -10
  109. package/dist/services/github/v3/createStatusComment.d.ts +2 -2
  110. package/dist/services/github/v3/createStatusComment.js +40 -15
  111. package/dist/services/github/v3/createStatusComment.test.js +174 -86
  112. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  113. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  114. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  116. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  117. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  124. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  125. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  126. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  127. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  128. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  129. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  130. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  131. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -0
  132. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  134. package/dist/services/logger.d.ts +4 -2
  135. package/dist/services/logger.js +31 -32
  136. package/dist/services/maybeSetupRepo.d.ts +2 -0
  137. package/dist/services/maybeSetupRepo.js +33 -0
  138. package/dist/services/maybeSetupRepo.test.d.ts +1 -0
  139. package/dist/services/maybeSetupRepo.test.js +78 -0
  140. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  141. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  142. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  143. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  144. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  145. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  146. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  147. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  148. package/dist/test/backport-e2e.private.test.d.ts +1 -0
  149. package/dist/test/backport-e2e.private.test.js +325 -0
  150. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  151. package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
  152. package/dist/test/inquirer.private.test.js +3 -1
  153. package/dist/test/integration/integration.private.test.js +2 -2
  154. package/dist/test/nockHelpers.js +1 -3
  155. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  156. package/dist/todo-delete.d.ts +1 -0
  157. package/dist/todo-delete.js +17 -0
  158. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
  159. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +9 -12
  160. package/dist/ui/getCommits.js +1 -1
  161. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  162. package/dist/ui/maybeSetupRepo.js +0 -6
  163. package/dist/ui/maybeSetupRepo.test.js +8 -4
  164. package/dist/utils/redact.d.ts +1 -0
  165. package/dist/utils/redact.js +7 -0
  166. package/dist/utils/sequentially.d.ts +1 -0
  167. package/dist/utils/sequentially.js +10 -0
  168. package/package.json +11 -11
  169. package/yarn.lock +570 -436
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.CommitPrompt = void 0;
26
+ const ink_multi_select_1 = __importDefault(require("ink-multi-select"));
27
+ const react_1 = __importStar(require("react"));
28
+ const fetchCommitByPullNumber_1 = require("../../services/github/v4/fetchCommits/fetchCommitByPullNumber");
29
+ const fetchCommitBySha_1 = require("../../services/github/v4/fetchCommits/fetchCommitBySha");
30
+ const fetchCommitsByAuthor_1 = require("../../services/github/v4/fetchCommits/fetchCommitsByAuthor");
31
+ const fetchPullRequestBySearchQuery_1 = require("../../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
32
+ const logger_1 = require("../../services/logger");
33
+ const BackportStateContext_1 = require("../BackportStateContext");
34
+ const useAsync_1 = require("../hooks/useAsync");
35
+ function CommitPrompt({ options, optionsStatus, optionsError, }) {
36
+ const { setBackportState } = (0, BackportStateContext_1.useBackportStateContext)();
37
+ const [choices, setChoices] = (0, react_1.useState)([]);
38
+ const [loadingStatus, setLoadingStatus] = (0, react_1.useState)('loading');
39
+ const [error, setError] = (0, react_1.useState)(null);
40
+ (0, react_1.useEffect)(() => {
41
+ async function fetch() {
42
+ if (!options) {
43
+ return;
44
+ }
45
+ const commit = await getCommit(options);
46
+ if (commit) {
47
+ setBackportState({
48
+ view: 'target-branches-prompt',
49
+ commits: [commit],
50
+ });
51
+ }
52
+ else {
53
+ const commitChoices = options.prFilter
54
+ ? await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)
55
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
56
+ setChoices(commitChoices);
57
+ }
58
+ }
59
+ fetch()
60
+ .then(() => {
61
+ setLoadingStatus('success');
62
+ })
63
+ .catch((e) => {
64
+ setLoadingStatus('failure');
65
+ setError(e);
66
+ });
67
+ }, [options]);
68
+ // console.log({ optionsStatus, loadingStatus });
69
+ if (optionsStatus !== 'success') {
70
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Initializing", status: optionsStatus, error: optionsError }));
71
+ }
72
+ if (loadingStatus !== 'success') {
73
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Loading commits", status: loadingStatus, error: error }));
74
+ }
75
+ logger_1.logger.info(`tester: ${optionsStatus}, ${loadingStatus}, ${choices.length}`);
76
+ const handleSubmit = (items) => {
77
+ console.log(items);
78
+ };
79
+ const items = choices.map((c) => ({
80
+ label: c.originalMessage,
81
+ value: c.originalMessage,
82
+ }));
83
+ return react_1.default.createElement(ink_multi_select_1.default, { items: items, onSubmit: handleSubmit });
84
+ }
85
+ exports.CommitPrompt = CommitPrompt;
86
+ function getCommit(options) {
87
+ if (options.sha) {
88
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
89
+ }
90
+ if (options.pullNumber) {
91
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
92
+ ...options,
93
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ValidConfigOptions } from '../../options/options';
3
+ import { AsyncStatus } from '../hooks/useAsync';
4
+ export declare function CommitPrompt({ options, optionsStatus, optionsError, }: {
5
+ options?: ValidConfigOptions;
6
+ optionsStatus: AsyncStatus;
7
+ optionsError: Error | null;
8
+ }): JSX.Element;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.CommitPrompt = void 0;
26
+ const ink_multi_select_1 = __importDefault(require("ink-multi-select"));
27
+ const react_1 = __importStar(require("react"));
28
+ const fetchCommitByPullNumber_1 = require("../../services/github/v4/fetchCommits/fetchCommitByPullNumber");
29
+ const fetchCommitBySha_1 = require("../../services/github/v4/fetchCommits/fetchCommitBySha");
30
+ const fetchCommitsByAuthor_1 = require("../../services/github/v4/fetchCommits/fetchCommitsByAuthor");
31
+ const fetchPullRequestBySearchQuery_1 = require("../../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
32
+ const logger_1 = require("../../services/logger");
33
+ const BackportStateContext_1 = require("../BackportStateContext");
34
+ const useAsync_1 = require("../hooks/useAsync");
35
+ function CommitPrompt({ options, optionsStatus, optionsError, }) {
36
+ const { setBackportState } = (0, BackportStateContext_1.useBackportStateContext)();
37
+ const [choices, setChoices] = (0, react_1.useState)([]);
38
+ const [loadingStatus, setLoadingStatus] = (0, react_1.useState)('loading');
39
+ const [error, setError] = (0, react_1.useState)(null);
40
+ (0, react_1.useEffect)(() => {
41
+ async function fetch() {
42
+ if (!options) {
43
+ return;
44
+ }
45
+ const commit = await getCommit(options);
46
+ if (commit) {
47
+ setBackportState({
48
+ view: 'target-branches-prompt',
49
+ commits: [commit],
50
+ });
51
+ }
52
+ else {
53
+ const commitChoices = options.prFilter
54
+ ? await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)
55
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
56
+ setChoices(commitChoices);
57
+ }
58
+ }
59
+ fetch()
60
+ .then(() => {
61
+ setLoadingStatus('success');
62
+ })
63
+ .catch((e) => {
64
+ setLoadingStatus('failure');
65
+ setError(e);
66
+ });
67
+ }, [options]);
68
+ // console.log({ optionsStatus, loadingStatus });
69
+ if (optionsStatus !== 'success') {
70
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Initializing", status: optionsStatus, error: optionsError }));
71
+ }
72
+ if (loadingStatus !== 'success') {
73
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Loading commits", status: loadingStatus, error: error }));
74
+ }
75
+ logger_1.logger.info(`tester: ${optionsStatus}, ${loadingStatus}, ${choices.length}`);
76
+ const handleSubmit = (items) => {
77
+ console.log(items);
78
+ };
79
+ const items = choices.map((c) => ({
80
+ label: c.originalMessage,
81
+ value: c.originalMessage,
82
+ }));
83
+ return react_1.default.createElement(ink_multi_select_1.default, { items: items, onSubmit: handleSubmit });
84
+ }
85
+ exports.CommitPrompt = CommitPrompt;
86
+ function getCommit(options) {
87
+ if (options.sha) {
88
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
89
+ }
90
+ if (options.pullNumber) {
91
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
92
+ ...options,
93
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Commit } from '../entrypoint.api';
3
+ import { TargetBranchChoice } from '../options/ConfigOptions';
4
+ import { ValidConfigOptions } from '../options/options';
5
+ export declare function TargetBranchChoices({ options, commits, }: {
6
+ options: ValidConfigOptions;
7
+ commits: Commit[];
8
+ }): JSX.Element | null;
9
+ export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getTargetBranchChoices = exports.TargetBranchChoices = void 0;
23
+ const lodash_1 = require("lodash");
24
+ const react_1 = __importStar(require("react"));
25
+ const HandledError_1 = require("../services/HandledError");
26
+ const BackportStateContext_1 = require("./BackportStateContext");
27
+ const CustomSelect_1 = require("./CustomSelect");
28
+ function TargetBranchChoices({ options, commits, }) {
29
+ const { setBackportView } = (0, BackportStateContext_1.useBackportStateContext)();
30
+ (0, react_1.useEffect)(() => {
31
+ throw new Error('woops');
32
+ // // target branches already specified programatically (in contrast to letting the user choose from a list)
33
+ // if (!isEmpty(options.targetBranches)) {
34
+ // setBackportView({
35
+ // viewName: '3-cherrypick',
36
+ // options,
37
+ // commits,
38
+ // targetBranches: options.targetBranches,
39
+ // });
40
+ // }
41
+ }, [commits, options, setBackportView]);
42
+ if (!(0, lodash_1.isEmpty)(options.targetBranches)) {
43
+ return null;
44
+ }
45
+ // target branches from the first commit
46
+ const missingTargetBranches = commits.length === 1
47
+ ? commits[0].expectedTargetPullRequests
48
+ .filter((pr) => pr.state === 'MISSING')
49
+ .map((pr) => pr.branch)
50
+ : [];
51
+ const { sourceBranch } = commits[0];
52
+ const choices = getTargetBranchChoices(options, missingTargetBranches, sourceBranch);
53
+ // TODO: handle initial selections
54
+ const items = choices.map((c) => ({
55
+ label: c.name,
56
+ value: c.name,
57
+ checked: c.checked,
58
+ }));
59
+ function onMultiSubmit(selectedItems) {
60
+ setBackportView({
61
+ viewName: '3-cherrypick',
62
+ options,
63
+ commits,
64
+ targetBranches: selectedItems.map((item) => item.value),
65
+ });
66
+ }
67
+ function onSingleSelect(selectedItems) {
68
+ setBackportView({
69
+ viewName: '3-cherrypick',
70
+ options,
71
+ commits,
72
+ targetBranches: [selectedItems.value],
73
+ });
74
+ }
75
+ return (react_1.default.createElement(CustomSelect_1.CustomSelect, { isMultiSelect: options.multipleBranches, items: items, onMultiSubmit: onMultiSubmit, onSingleSelect: onSingleSelect }));
76
+ }
77
+ exports.TargetBranchChoices = TargetBranchChoices;
78
+ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
79
+ // exclude sourceBranch from targetBranchChoices
80
+ const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
81
+ if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
82
+ throw new HandledError_1.HandledError('Missing target branch choices');
83
+ }
84
+ if (!options.branchLabelMapping) {
85
+ return targetBranchesChoices;
86
+ }
87
+ // select missing target branches (based on pull request labels)
88
+ return targetBranchesChoices.map((choice) => {
89
+ const isChecked = missingTargetBranches.includes(choice.name);
90
+ return { ...choice, checked: isChecked };
91
+ });
92
+ }
93
+ exports.getTargetBranchChoices = getTargetBranchChoices;
94
+ // `targetBranchChoices` can either be a string or an object.
95
+ // It must be transformed so it is always treated as an object troughout the application
96
+ function getTargetBranchChoicesAsObject(targetBranchChoices) {
97
+ if (!targetBranchChoices) {
98
+ return [];
99
+ }
100
+ return targetBranchChoices.map((choice) => {
101
+ if ((0, lodash_1.isString)(choice)) {
102
+ return {
103
+ name: choice,
104
+ checked: false,
105
+ };
106
+ }
107
+ return choice;
108
+ });
109
+ }
@@ -0,0 +1 @@
1
+ declare function cherrypick(): void;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ function cherrypick() { }
@@ -0,0 +1,2 @@
1
+ import { ConfigFileOptions } from '../options/ConfigOptions';
2
+ export declare function renderApp(argv: string[], optionsFromModule?: ConfigFileOptions): import("ink").Instance;
@@ -0,0 +1,35 @@
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.renderApp = void 0;
7
+ const ink_1 = require("ink");
8
+ const react_1 = __importDefault(require("react"));
9
+ const _0_loadOptions_1 = require("./0-loadOptions");
10
+ const _1a_loadCommit_1 = require("./1a-loadCommit");
11
+ const _1b_commitChoices_1 = require("./1b-commitChoices");
12
+ const _2_targetBranchChoices_1 = require("./2-targetBranchChoices");
13
+ const BackportStateContext_1 = require("./BackportStateContext");
14
+ const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
15
+ function App({ argv, optionsFromModule, }) {
16
+ const { backportView } = (0, BackportStateContext_1.useBackportStateContext)();
17
+ switch (backportView.viewName) {
18
+ case '0-load-options':
19
+ return react_1.default.createElement(_0_loadOptions_1.LoadOptions, { argv: argv, optionsFromModule: optionsFromModule });
20
+ case '1a-load-single-commit':
21
+ return react_1.default.createElement(_1a_loadCommit_1.LoadCommit, { options: backportView.options });
22
+ case '1b-display-commit-choices':
23
+ return react_1.default.createElement(_1b_commitChoices_1.CommitChoices, { options: backportView.options });
24
+ case '2-target-branches-prompt':
25
+ return (react_1.default.createElement(_2_targetBranchChoices_1.TargetBranchChoices, { options: backportView.options, commits: backportView.commits }));
26
+ case '3-cherrypick':
27
+ return null;
28
+ }
29
+ }
30
+ function renderApp(argv, optionsFromModule) {
31
+ return (0, ink_1.render)(react_1.default.createElement(ErrorBoundary_1.default, null,
32
+ react_1.default.createElement(BackportStateContext_1.BackportStateContextProvider, null,
33
+ react_1.default.createElement(App, { argv: argv, optionsFromModule: optionsFromModule }))));
34
+ }
35
+ exports.renderApp = renderApp;
@@ -0,0 +1,33 @@
1
+ import React, { Dispatch, ReactNode, SetStateAction } from 'react';
2
+ import { ValidConfigOptions } from '../options/options';
3
+ import { Commit } from '../services/sourceCommit/parseSourceCommit';
4
+ declare type BackportView = {
5
+ viewName: '0-load-options';
6
+ } | {
7
+ viewName: '1a-load-single-commit';
8
+ options: ValidConfigOptions;
9
+ } | {
10
+ viewName: '1b-display-commit-choices';
11
+ options: ValidConfigOptions;
12
+ } | {
13
+ viewName: '2-target-branches-prompt';
14
+ options: ValidConfigOptions;
15
+ commits: Commit[];
16
+ } | {
17
+ viewName: '3-cherrypick';
18
+ options: ValidConfigOptions;
19
+ commits: Commit[];
20
+ targetBranches: string[];
21
+ };
22
+ export declare const BackportStateContext: React.Context<{
23
+ backportView: BackportView;
24
+ setBackportView: Dispatch<SetStateAction<BackportView>>;
25
+ } | null>;
26
+ export declare function BackportStateContextProvider({ children, }: {
27
+ children: ReactNode;
28
+ }): JSX.Element;
29
+ export declare function useBackportStateContext(): {
30
+ backportView: BackportView;
31
+ setBackportView: React.Dispatch<React.SetStateAction<BackportView>>;
32
+ };
33
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.useBackportStateContext = exports.BackportStateContextProvider = exports.BackportStateContext = void 0;
23
+ const react_1 = __importStar(require("react"));
24
+ exports.BackportStateContext = (0, react_1.createContext)(null);
25
+ function BackportStateContextProvider({ children, }) {
26
+ const [backportView, setBackportView] = (0, react_1.useState)({
27
+ viewName: '0-load-options',
28
+ });
29
+ return (react_1.default.createElement(exports.BackportStateContext.Provider, { value: {
30
+ backportView,
31
+ setBackportView,
32
+ }, children: children }));
33
+ }
34
+ exports.BackportStateContextProvider = BackportStateContextProvider;
35
+ function useBackportStateContext() {
36
+ const context = (0, react_1.useContext)(exports.BackportStateContext);
37
+ if (!context) {
38
+ throw new Error('Missing BackportStateContext provider');
39
+ }
40
+ return context;
41
+ }
42
+ exports.useBackportStateContext = useBackportStateContext;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ValidConfigOptions } from '../../options/options';
3
+ import { AsyncStatus } from '../hooks/useAsync';
4
+ export declare function CommitPrompt({ options, optionsStatus, optionsError, }: {
5
+ options?: ValidConfigOptions;
6
+ optionsStatus: AsyncStatus;
7
+ optionsError: Error | null;
8
+ }): JSX.Element;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.CommitPrompt = void 0;
26
+ const ink_multi_select_1 = __importDefault(require("ink-multi-select"));
27
+ const react_1 = __importStar(require("react"));
28
+ const fetchCommitByPullNumber_1 = require("../../services/github/v4/fetchCommits/fetchCommitByPullNumber");
29
+ const fetchCommitBySha_1 = require("../../services/github/v4/fetchCommits/fetchCommitBySha");
30
+ const fetchCommitsByAuthor_1 = require("../../services/github/v4/fetchCommits/fetchCommitsByAuthor");
31
+ const fetchPullRequestBySearchQuery_1 = require("../../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
32
+ const logger_1 = require("../../services/logger");
33
+ const BackportStateContext_1 = require("../BackportStateContext");
34
+ const useAsync_1 = require("../hooks/useAsync");
35
+ function CommitPrompt({ options, optionsStatus, optionsError, }) {
36
+ const { setBackportState } = (0, BackportStateContext_1.useBackportStateContext)();
37
+ const [choices, setChoices] = (0, react_1.useState)([]);
38
+ const [loadingStatus, setLoadingStatus] = (0, react_1.useState)('loading');
39
+ const [error, setError] = (0, react_1.useState)(null);
40
+ (0, react_1.useEffect)(() => {
41
+ async function fetch() {
42
+ if (!options) {
43
+ return;
44
+ }
45
+ const commit = await getCommit(options);
46
+ if (commit) {
47
+ setBackportState({
48
+ view: 'target-branches-prompt',
49
+ commits: [commit],
50
+ });
51
+ }
52
+ else {
53
+ const commitChoices = options.prFilter
54
+ ? await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)
55
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
56
+ setChoices(commitChoices);
57
+ }
58
+ }
59
+ fetch()
60
+ .then(() => {
61
+ setLoadingStatus('success');
62
+ })
63
+ .catch((e) => {
64
+ setLoadingStatus('failure');
65
+ setError(e);
66
+ });
67
+ }, [options]);
68
+ // console.log({ optionsStatus, loadingStatus });
69
+ if (optionsStatus !== 'success') {
70
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Initializing", status: optionsStatus, error: optionsError }));
71
+ }
72
+ if (loadingStatus !== 'success') {
73
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Loading commits", status: loadingStatus, error: error }));
74
+ }
75
+ logger_1.logger.info(`tester: ${optionsStatus}, ${loadingStatus}, ${choices.length}`);
76
+ const handleSubmit = (items) => {
77
+ console.log(items);
78
+ };
79
+ const items = choices.map((c) => ({
80
+ label: c.originalMessage,
81
+ value: c.originalMessage,
82
+ }));
83
+ return react_1.default.createElement(ink_multi_select_1.default, { items: items, onSubmit: handleSubmit });
84
+ }
85
+ exports.CommitPrompt = CommitPrompt;
86
+ function getCommit(options) {
87
+ if (options.sha) {
88
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
89
+ }
90
+ if (options.pullNumber) {
91
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
92
+ ...options,
93
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { ValidConfigOptions } from '../../options/options';
3
+ import { AsyncStatus } from '../hooks/useAsync';
4
+ export declare function CommitPrompt({ options, optionsStatus, optionsError, }: {
5
+ options?: ValidConfigOptions;
6
+ optionsStatus: AsyncStatus;
7
+ optionsError: Error | null;
8
+ }): JSX.Element;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.CommitPrompt = void 0;
26
+ const ink_multi_select_1 = __importDefault(require("ink-multi-select"));
27
+ const react_1 = __importStar(require("react"));
28
+ const fetchCommitByPullNumber_1 = require("../../services/github/v4/fetchCommits/fetchCommitByPullNumber");
29
+ const fetchCommitBySha_1 = require("../../services/github/v4/fetchCommits/fetchCommitBySha");
30
+ const fetchCommitsByAuthor_1 = require("../../services/github/v4/fetchCommits/fetchCommitsByAuthor");
31
+ const fetchPullRequestBySearchQuery_1 = require("../../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
32
+ const logger_1 = require("../../services/logger");
33
+ const BackportStateContext_1 = require("../BackportStateContext");
34
+ const useAsync_1 = require("../hooks/useAsync");
35
+ function CommitPrompt({ options, optionsStatus, optionsError, }) {
36
+ const { setBackportState } = (0, BackportStateContext_1.useBackportStateContext)();
37
+ const [choices, setChoices] = (0, react_1.useState)([]);
38
+ const [loadingStatus, setLoadingStatus] = (0, react_1.useState)('loading');
39
+ const [error, setError] = (0, react_1.useState)(null);
40
+ (0, react_1.useEffect)(() => {
41
+ async function fetch() {
42
+ if (!options) {
43
+ return;
44
+ }
45
+ const commit = await getCommit(options);
46
+ if (commit) {
47
+ setBackportState({
48
+ view: 'target-branches-prompt',
49
+ commits: [commit],
50
+ });
51
+ }
52
+ else {
53
+ const commitChoices = options.prFilter
54
+ ? await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)
55
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
56
+ setChoices(commitChoices);
57
+ }
58
+ }
59
+ fetch()
60
+ .then(() => {
61
+ setLoadingStatus('success');
62
+ })
63
+ .catch((e) => {
64
+ setLoadingStatus('failure');
65
+ setError(e);
66
+ });
67
+ }, [options]);
68
+ // console.log({ optionsStatus, loadingStatus });
69
+ if (optionsStatus !== 'success') {
70
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Initializing", status: optionsStatus, error: optionsError }));
71
+ }
72
+ if (loadingStatus !== 'success') {
73
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Loading commits", status: loadingStatus, error: error }));
74
+ }
75
+ logger_1.logger.info(`tester: ${optionsStatus}, ${loadingStatus}, ${choices.length}`);
76
+ const handleSubmit = (items) => {
77
+ console.log(items);
78
+ };
79
+ const items = choices.map((c) => ({
80
+ label: c.originalMessage,
81
+ value: c.originalMessage,
82
+ }));
83
+ return react_1.default.createElement(ink_multi_select_1.default, { items: items, onSubmit: handleSubmit });
84
+ }
85
+ exports.CommitPrompt = CommitPrompt;
86
+ function getCommit(options) {
87
+ if (options.sha) {
88
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
89
+ }
90
+ if (options.pullNumber) {
91
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
92
+ ...options,
93
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../../options/options';
2
+ export declare function getCommits(options: ValidConfigOptions): Promise<any>;