backport 6.1.5 → 6.2.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 (92) hide show
  1. package/dist/backportRun.d.ts +14 -0
  2. package/dist/backportRun.js +75 -0
  3. package/dist/entrypoint.api.d.ts +22 -0
  4. package/dist/entrypoint.api.js +57 -0
  5. package/dist/entrypoint.api.private.test.d.ts +1 -0
  6. package/dist/entrypoint.api.private.test.js +37 -0
  7. package/dist/options/config/getProjectConfig.d.ts +0 -0
  8. package/dist/options/config/getProjectConfig.js +1 -0
  9. package/dist/options/config/globalConfig.test.js +2 -2
  10. package/dist/options/options.test.js +3 -2
  11. package/dist/react-components/0-loadOptions.d.ts +6 -0
  12. package/dist/react-components/0-loadOptions.js +45 -0
  13. package/dist/react-components/1-loadCommit.d.ts +8 -0
  14. package/dist/react-components/1-loadCommit.js +88 -0
  15. package/dist/react-components/1a-loadCommit.d.ts +5 -0
  16. package/dist/react-components/1a-loadCommit.js +76 -0
  17. package/dist/react-components/1b-commitChoices.d.ts +5 -0
  18. package/dist/react-components/1b-commitChoices.js +98 -0
  19. package/dist/react-components/2-commitChoices.d.ts +8 -0
  20. package/dist/react-components/2-commitChoices.js +96 -0
  21. package/dist/react-components/2-commitsPrompt.d.ts +8 -0
  22. package/dist/react-components/2-commitsPrompt.js +96 -0
  23. package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
  24. package/dist/react-components/2-targetBranchChoices.js +109 -0
  25. package/dist/react-components/3-cherrypick.d.ts +1 -0
  26. package/dist/react-components/3-cherrypick.js +2 -0
  27. package/dist/react-components/App.d.ts +2 -0
  28. package/dist/react-components/App.js +35 -0
  29. package/dist/react-components/BackportStateContext.d.ts +33 -0
  30. package/dist/react-components/BackportStateContext.js +42 -0
  31. package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
  32. package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
  33. package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
  34. package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
  35. package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
  36. package/dist/react-components/CommitPrompt/getCommits.js +27 -0
  37. package/dist/react-components/CommitPrompt.d.ts +8 -0
  38. package/dist/react-components/CommitPrompt.js +96 -0
  39. package/dist/react-components/CustomMultiSelect.d.ts +13 -0
  40. package/dist/react-components/CustomMultiSelect.js +21 -0
  41. package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
  42. package/dist/react-components/CustomMultiSelectItem.js +12 -0
  43. package/dist/react-components/CustomSelect.d.ts +14 -0
  44. package/dist/react-components/CustomSelect.js +34 -0
  45. package/dist/react-components/ErrorBoundary.d.ts +15 -0
  46. package/dist/react-components/ErrorBoundary.js +53 -0
  47. package/dist/react-components/MultiSelect.d.ts +7 -0
  48. package/dist/react-components/MultiSelect.js +16 -0
  49. package/dist/react-components/hooks/useAsync.d.ts +12 -0
  50. package/dist/react-components/hooks/useAsync.js +73 -0
  51. package/dist/runSequentially.test.js +2 -2
  52. package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
  53. package/dist/services/backportRun/backportRun.ci.js +81 -0
  54. package/dist/services/backportRun/backportRun.d.ts +14 -0
  55. package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
  56. package/dist/services/backportRun/backportRun.interactive.js +4 -0
  57. package/dist/services/backportRun/backportRun.js +14 -0
  58. package/dist/services/backportRun/backportState.d.ts +4 -0
  59. package/dist/services/backportRun/backportState.js +28 -0
  60. package/dist/services/backportRun/getCommits.d.ts +2 -0
  61. package/dist/services/backportRun/getCommits.js +20 -0
  62. package/dist/services/backportRun/runSequentially.d.ts +20 -0
  63. package/dist/services/backportRun/runSequentially.js +41 -0
  64. package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
  65. package/dist/services/backportRun/runSequentially.test.js +199 -0
  66. package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
  67. package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
  68. package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  69. package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
  70. package/dist/services/getCommits.d.ts +2 -0
  71. package/dist/services/getCommits.js +38 -0
  72. package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
  73. package/dist/services/getCommitsWithoutBackports.js +68 -0
  74. package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
  75. package/dist/services/getCommitsWithoutBackports.test.js +259 -0
  76. package/dist/services/getTargetBranches.d.ts +5 -0
  77. package/dist/services/getTargetBranches.js +60 -0
  78. package/dist/services/getTargetBranches.test.d.ts +1 -0
  79. package/dist/services/getTargetBranches.test.js +180 -0
  80. package/dist/services/github/v3/createStatusComment.test.js +35 -0
  81. package/dist/services/maybeSetupRepo.d.ts +2 -0
  82. package/dist/services/maybeSetupRepo.js +33 -0
  83. package/dist/services/maybeSetupRepo.test.d.ts +1 -0
  84. package/dist/services/maybeSetupRepo.test.js +78 -0
  85. package/dist/test/backport-e2e.private.test.d.ts +1 -0
  86. package/dist/test/backport-e2e.private.test.js +327 -0
  87. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  88. package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
  89. package/dist/ui/maybeSetupRepo.test.js +8 -4
  90. package/dist/utils/sequentially.d.ts +1 -0
  91. package/dist/utils/sequentially.js +10 -0
  92. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ import { ConfigFileOptions } from './options/ConfigOptions';
2
+ import { Result } from './runSequentially';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
4
+ export declare type BackportResponse = {
5
+ status: 'success';
6
+ commits: Commit[];
7
+ results: Result[];
8
+ } | {
9
+ status: 'failure';
10
+ commits: Commit[];
11
+ errorMessage: string;
12
+ error: Error;
13
+ };
14
+ export declare function backportRun(processArgs: string[], optionsFromModule?: ConfigFileOptions): Promise<BackportResponse>;
@@ -0,0 +1,75 @@
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.backportRun = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const ora_1 = __importDefault(require("ora"));
9
+ const yargs_1 = __importDefault(require("yargs"));
10
+ const options_1 = require("./options/options");
11
+ const runSequentially_1 = require("./runSequentially");
12
+ const HandledError_1 = require("./services/HandledError");
13
+ const env_1 = require("./services/env");
14
+ const createStatusComment_1 = require("./services/github/v3/createStatusComment");
15
+ const logger_1 = require("./services/logger");
16
+ const getCommits_1 = require("./ui/getCommits");
17
+ const getTargetBranches_1 = require("./ui/getTargetBranches");
18
+ async function backportRun(processArgs, optionsFromModule = {}) {
19
+ const argv = (0, yargs_1.default)(processArgs).argv;
20
+ const ci = argv.ci ?? optionsFromModule.ci;
21
+ const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
22
+ (0, logger_1.initLogger)({ ci, logFilePath });
23
+ const spinner = (0, ora_1.default)().start('Initializing...');
24
+ let options = null;
25
+ let commits = [];
26
+ try {
27
+ options = await (0, options_1.getOptions)(processArgs, optionsFromModule);
28
+ spinner.stop();
29
+ commits = await (0, getCommits_1.getCommits)(options);
30
+ const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
31
+ const results = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
32
+ const backportResponse = {
33
+ status: 'success',
34
+ commits,
35
+ results,
36
+ };
37
+ await (0, createStatusComment_1.createStatusComment)({
38
+ options,
39
+ backportResponse,
40
+ });
41
+ return backportResponse;
42
+ }
43
+ catch (e) {
44
+ spinner.stop();
45
+ const backportResponse = {
46
+ status: 'failure',
47
+ commits,
48
+ errorMessage: e.message,
49
+ error: e,
50
+ };
51
+ if (options) {
52
+ await (0, createStatusComment_1.createStatusComment)({
53
+ options,
54
+ backportResponse,
55
+ });
56
+ }
57
+ if (e instanceof HandledError_1.HandledError) {
58
+ (0, logger_1.consoleLog)(e.message);
59
+ }
60
+ else if (e instanceof Error) {
61
+ // output
62
+ (0, logger_1.consoleLog)('\n');
63
+ (0, logger_1.consoleLog)(chalk_1.default.bold('⚠️ Ouch! An unhandled error occured 😿'));
64
+ (0, logger_1.consoleLog)(`Error message: ${e.message}`);
65
+ (0, logger_1.consoleLog)('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
66
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)({
67
+ logFilePath,
68
+ })}`));
69
+ // log file
70
+ logger_1.logger.info('Unknown error:', e);
71
+ }
72
+ return backportResponse;
73
+ }
74
+ }
75
+ exports.backportRun = backportRun;
@@ -0,0 +1,22 @@
1
+ import { ConfigFileOptions } from './options/ConfigOptions';
2
+ import { ValidConfigOptions } from './options/options';
3
+ export { BackportResponse } from './services/backportRun/backportRun';
4
+ export { ConfigFileOptions } from './options/ConfigOptions';
5
+ export { Commit } from './services/sourceCommit/parseSourceCommit';
6
+ export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
+ export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
8
+ export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./services/backportRun/backportRun").BackportResponse | undefined>;
9
+ export declare function getCommits(options: {
10
+ accessToken: string;
11
+ repoName: string;
12
+ repoOwner: string;
13
+ author?: string;
14
+ branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
15
+ githubApiBaseUrlV4?: string;
16
+ pullNumber?: number;
17
+ sha?: string;
18
+ skipRemoteConfig?: boolean;
19
+ sourceBranch?: string;
20
+ dateUntil?: string;
21
+ dateSince?: string;
22
+ }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommits = exports.backportRun = exports.getLocalGlobalConfig = exports.getRemoteProjectConfig = void 0;
4
+ const backportRun_1 = require("./services/backportRun/backportRun");
5
+ const fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
6
+ const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
7
+ const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
8
+ const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
+ const logger_1 = require("./services/logger");
10
+ const excludeUndefined_1 = require("./utils/excludeUndefined");
11
+ (0, logger_1.initLogger)();
12
+ var fetchRemoteProjectConfig_1 = require("./services/github/v4/fetchRemoteProjectConfig");
13
+ Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
14
+ var globalConfig_1 = require("./options/config/globalConfig");
15
+ Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
16
+ function backportRun(options,
17
+ // cli args will not automatically be forwarded when it is consumed as a module
18
+ // It is simple to forward args manually via `process.argv`:
19
+ //
20
+ // import { backportRun } from `backport
21
+ // const args = process.argv.slice(2);
22
+ // backportRun(options, args)
23
+ //
24
+ args = []) {
25
+ return (0, backportRun_1.backportRun)(args, (0, excludeUndefined_1.excludeUndefined)(options));
26
+ }
27
+ exports.backportRun = backportRun;
28
+ async function getCommits(options) {
29
+ const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
30
+ if (options.pullNumber) {
31
+ return [
32
+ await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
33
+ ...optionsFromGithub,
34
+ ...options,
35
+ pullNumber: options.pullNumber,
36
+ }),
37
+ ];
38
+ }
39
+ if (options.sha) {
40
+ return [
41
+ await (0, fetchCommitBySha_1.fetchCommitBySha)({
42
+ ...optionsFromGithub,
43
+ ...options,
44
+ sha: options.sha,
45
+ }),
46
+ ];
47
+ }
48
+ return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
49
+ ...optionsFromGithub,
50
+ ...options,
51
+ // filters
52
+ author: options.author ?? null,
53
+ dateSince: options.dateSince ?? null,
54
+ dateUntil: options.dateUntil ?? null,
55
+ });
56
+ }
57
+ exports.getCommits = getCommits;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const entrypoint_api_1 = require("./entrypoint.api");
4
+ const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
5
+ describe('entrypoint.api', () => {
6
+ it('getCommits', async () => {
7
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
8
+ const commits = await (0, entrypoint_api_1.getCommits)({
9
+ accessToken: accessToken,
10
+ repoName: 'backport-e2e',
11
+ repoOwner: 'backport-org',
12
+ pullNumber: 2,
13
+ });
14
+ expect(commits).toEqual([
15
+ {
16
+ committedDate: '2020-08-15T10:44:04Z',
17
+ expectedTargetPullRequests: [
18
+ {
19
+ branch: '7.x',
20
+ number: 4,
21
+ state: 'MERGED',
22
+ url: 'https://github.com/backport-org/backport-e2e/pull/4',
23
+ mergeCommit: {
24
+ message: 'Add family emoji (#2) (#4)',
25
+ sha: 'f8b4f6ae7ffaf2732fa5e33e98b3ea772bdfff1d',
26
+ },
27
+ },
28
+ ],
29
+ originalMessage: 'Add family emoji (#2)',
30
+ pullNumber: 2,
31
+ pullUrl: 'https://github.com/backport-org/backport-e2e/pull/2',
32
+ sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
33
+ sourceBranch: 'master',
34
+ },
35
+ ]);
36
+ });
37
+ });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -44,8 +44,8 @@ describe('config', () => {
44
44
  it("should create config if it doesn't exist", () => {
45
45
  expect(fs.writeFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', expect.any(String), { flag: 'wx', mode: 384 });
46
46
  });
47
- it("should create config folders if it they don't exist", () => {
48
- expect(make_dir_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories');
47
+ it("should create .backport folder if it doesn't exist", () => {
48
+ expect(make_dir_1.default).toHaveBeenCalledWith('/myHomeDir/.backport');
49
49
  });
50
50
  it('should load config', () => {
51
51
  expect(fs.readFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', 'utf8');
@@ -125,8 +125,9 @@ describe('getOptions', () => {
125
125
  expect(options).toEqual({
126
126
  accessToken: 'abc',
127
127
  assignees: [],
128
- autoAssign: false,
129
128
  authenticatedUsername: 'john.diller',
129
+ author: 'john.diller',
130
+ autoAssign: false,
130
131
  autoMerge: false,
131
132
  autoMergeMethod: 'merge',
132
133
  backportBinary: 'backport',
@@ -152,6 +153,7 @@ describe('getOptions', () => {
152
153
  multipleBranches: true,
153
154
  multipleCommits: false,
154
155
  noVerify: true,
156
+ publishStatusComment: true,
155
157
  repoName: 'kibana',
156
158
  repoOwner: 'elastic',
157
159
  resetAuthor: false,
@@ -161,7 +163,6 @@ describe('getOptions', () => {
161
163
  targetBranchChoices: ['7.9', '8.0'],
162
164
  targetBranches: [],
163
165
  targetPRLabels: [],
164
- author: 'john.diller',
165
166
  verbose: false,
166
167
  });
167
168
  });
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { ConfigFileOptions } from '../options/ConfigOptions';
3
+ export declare function LoadOptions({ argv, optionsFromModule, }: {
4
+ argv: string[];
5
+ optionsFromModule?: ConfigFileOptions;
6
+ }): JSX.Element;
@@ -0,0 +1,45 @@
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.LoadOptions = void 0;
26
+ const ink_1 = require("ink");
27
+ const ink_spinner_1 = __importDefault(require("ink-spinner"));
28
+ const react_1 = __importStar(require("react"));
29
+ const options_1 = require("../options/options");
30
+ const BackportStateContext_1 = require("./BackportStateContext");
31
+ function LoadOptions({ argv, optionsFromModule, }) {
32
+ const { setBackportView } = (0, BackportStateContext_1.useBackportStateContext)();
33
+ (0, react_1.useEffect)(() => {
34
+ (0, options_1.getOptions)(argv, optionsFromModule).then((options) => {
35
+ setBackportView({
36
+ viewName: '1a-load-single-commit',
37
+ options,
38
+ });
39
+ });
40
+ }, [argv, optionsFromModule, setBackportView]);
41
+ return (react_1.default.createElement(ink_1.Text, null,
42
+ react_1.default.createElement(ink_spinner_1.default, { type: "dots" }),
43
+ "\u00A0Initializing..."));
44
+ }
45
+ exports.LoadOptions = LoadOptions;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { AsyncStatus } from '../hooks/useAsync';
3
+ import { ValidConfigOptions } from '../options/options';
4
+ export declare function CommitPrompt({ options, optionsStatus, optionsError, }: {
5
+ options?: ValidConfigOptions;
6
+ optionsStatus: AsyncStatus;
7
+ optionsError: Error | null;
8
+ }): JSX.Element;
@@ -0,0 +1,88 @@
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 useAsync_1 = require("../hooks/useAsync");
29
+ const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
30
+ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
31
+ const logger_1 = require("../services/logger");
32
+ const BackportStateContext_1 = require("./BackportStateContext");
33
+ function CommitPrompt({ options, optionsStatus, optionsError, }) {
34
+ const { setBackportState } = (0, BackportStateContext_1.useBackportStateContext)();
35
+ const [choices, setChoices] = (0, react_1.useState)([]);
36
+ const [loadingStatus, setLoadingStatus] = (0, react_1.useState)('loading');
37
+ const [error, setError] = (0, react_1.useState)(null);
38
+ (0, react_1.useEffect)(() => {
39
+ async function fetch() {
40
+ if (!options) {
41
+ return;
42
+ }
43
+ const commit = await getCommit(options);
44
+ if (commit) {
45
+ setBackportState({
46
+ view: '3-target-branches-prompt',
47
+ commits: [commit],
48
+ });
49
+ }
50
+ }
51
+ fetch()
52
+ .then(() => {
53
+ setLoadingStatus('success');
54
+ })
55
+ .catch((e) => {
56
+ setLoadingStatus('failure');
57
+ setError(e);
58
+ });
59
+ }, [options]);
60
+ // console.log({ optionsStatus, loadingStatus });
61
+ if (optionsStatus !== 'success') {
62
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Initializing", status: optionsStatus, error: optionsError }));
63
+ }
64
+ if (loadingStatus !== 'success') {
65
+ return (react_1.default.createElement(useAsync_1.ShowAsyncStatus, { text: "Loading commits", status: loadingStatus, error: error }));
66
+ }
67
+ logger_1.logger.info(`tester: ${optionsStatus}, ${loadingStatus}, ${choices.length}`);
68
+ const handleSubmit = (items) => {
69
+ console.log(items);
70
+ };
71
+ const items = choices.map((c) => ({
72
+ label: c.originalMessage,
73
+ value: c.originalMessage,
74
+ }));
75
+ return react_1.default.createElement(ink_multi_select_1.default, { items: items, onSubmit: handleSubmit });
76
+ }
77
+ exports.CommitPrompt = CommitPrompt;
78
+ function getCommit(options) {
79
+ if (options.sha) {
80
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
81
+ }
82
+ if (options.pullNumber) {
83
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
84
+ ...options,
85
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
86
+ });
87
+ }
88
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ValidConfigOptions } from '../options/options';
3
+ export declare function LoadCommit({ options }: {
4
+ options: ValidConfigOptions;
5
+ }): JSX.Element;
@@ -0,0 +1,76 @@
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.LoadCommit = void 0;
26
+ const ink_1 = require("ink");
27
+ const ink_spinner_1 = __importDefault(require("ink-spinner"));
28
+ const react_1 = __importStar(require("react"));
29
+ const commitFormatters_1 = require("../services/github/commitFormatters");
30
+ const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
31
+ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
32
+ const BackportStateContext_1 = require("./BackportStateContext");
33
+ function LoadCommit({ options }) {
34
+ const [fetchError, setFetchError] = (0, react_1.useState)(null);
35
+ const { setBackportView } = (0, BackportStateContext_1.useBackportStateContext)();
36
+ (0, react_1.useEffect)(() => {
37
+ getCommit(options)
38
+ .then((commit) => {
39
+ if (commit) {
40
+ setBackportView({
41
+ viewName: '2-target-branches-prompt',
42
+ options,
43
+ commits: [commit],
44
+ });
45
+ }
46
+ else {
47
+ setBackportView({
48
+ viewName: '1b-display-commit-choices',
49
+ options,
50
+ });
51
+ }
52
+ })
53
+ .catch((e) => setFetchError(e));
54
+ }, [options, setBackportView]);
55
+ if (fetchError) {
56
+ return react_1.default.createElement(ink_1.Text, null, fetchError.message);
57
+ }
58
+ return (react_1.default.createElement(ink_1.Text, null,
59
+ react_1.default.createElement(ink_spinner_1.default, { type: "dots" }),
60
+ "\u00A0",
61
+ options.sha
62
+ ? `Loading commit ${(0, commitFormatters_1.getShortSha)(options.sha)}`
63
+ : `Loading pull request #${options.pullNumber}`));
64
+ }
65
+ exports.LoadCommit = LoadCommit;
66
+ async function getCommit(options) {
67
+ if (options.sha) {
68
+ return (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
69
+ }
70
+ if (options.pullNumber) {
71
+ return (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
72
+ ...options,
73
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
74
+ });
75
+ }
76
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ValidConfigOptions } from '../options/options';
3
+ export declare function CommitChoices({ options }: {
4
+ options: ValidConfigOptions;
5
+ }): JSX.Element;
@@ -0,0 +1,98 @@
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.CommitChoices = void 0;
26
+ const ink_1 = require("ink");
27
+ const ink_spinner_1 = __importDefault(require("ink-spinner"));
28
+ const react_1 = __importStar(require("react"));
29
+ const commitFormatters_1 = require("../services/github/commitFormatters");
30
+ const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
31
+ const fetchPullRequestBySearchQuery_1 = require("../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
32
+ const BackportStateContext_1 = require("./BackportStateContext");
33
+ const CustomSelect_1 = require("./CustomSelect");
34
+ function CommitChoices({ options }) {
35
+ const { setBackportView } = (0, BackportStateContext_1.useBackportStateContext)();
36
+ const [choices, setChoices] = (0, react_1.useState)([]);
37
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
38
+ const [fetchError, setFetchError] = (0, react_1.useState)(null);
39
+ const [showHint, setShowHint] = (0, react_1.useState)(false);
40
+ (0, react_1.useEffect)(() => {
41
+ async function fetch() {
42
+ try {
43
+ setIsLoading(true);
44
+ const commitChoices = options.prFilter
45
+ ? await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)
46
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
47
+ setChoices(commitChoices);
48
+ }
49
+ catch (e) {
50
+ setFetchError(e);
51
+ }
52
+ finally {
53
+ setIsLoading(false);
54
+ }
55
+ }
56
+ fetch();
57
+ }, [options]);
58
+ if (isLoading) {
59
+ return (react_1.default.createElement(ink_1.Text, null,
60
+ react_1.default.createElement(ink_spinner_1.default, { type: "dots" }),
61
+ "\u00A0",
62
+ options.prFilter
63
+ ? 'Loading pull requests matching filter'
64
+ : `Loading commits from branch "${options.sourceBranch}"...`));
65
+ }
66
+ if (fetchError) {
67
+ return react_1.default.createElement(ink_1.Text, null, fetchError.message);
68
+ }
69
+ const onMultiSubmit = (selectedItems) => {
70
+ if (selectedItems.length === 0) {
71
+ setShowHint(true);
72
+ return;
73
+ }
74
+ const commits = selectedItems.map((item) => item.value);
75
+ setBackportView({
76
+ viewName: '2-target-branches-prompt',
77
+ options,
78
+ commits,
79
+ });
80
+ };
81
+ const onSingleSelect = (selectedItem) => {
82
+ const commit = selectedItem.value;
83
+ setBackportView({
84
+ viewName: '2-target-branches-prompt',
85
+ options,
86
+ commits: [commit],
87
+ });
88
+ };
89
+ const items = choices.map((c) => ({
90
+ label: (0, commitFormatters_1.getFirstLine)(c.originalMessage),
91
+ value: c,
92
+ key: c.originalMessage,
93
+ }));
94
+ return (react_1.default.createElement(react_1.default.Fragment, null,
95
+ showHint ? react_1.default.createElement(ink_1.Text, null, "Please use space to select an item") : null,
96
+ react_1.default.createElement(CustomSelect_1.CustomSelect, { isMultiSelect: options.multipleCommits, items: items, onMultiSubmit: onMultiSubmit, onSingleSelect: onSingleSelect })));
97
+ }
98
+ exports.CommitChoices = CommitChoices;
@@ -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;