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
package/README.md CHANGED
@@ -67,42 +67,45 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
67
67
 
68
68
  ### CLI options
69
69
 
70
- | Option | Shorthand notation | Description | Default |
71
- | ------------------- | ------------------ | ------------------------------------------------------------- | -------------- |
72
- | --access-token | | Github access token | |
73
- | --all | -a | Show commits from any author | false |
74
- | --assignee | --assign | Assign users to the target PR | |
75
- | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
76
- | --auto-assign | | Assign current user to the target PR | false |
77
- | --branch | -b | Target branch to backport to | |
78
- | --ci | | Disable interactive prompts | false |
79
- | --dry-run | | Perform backport without pushing to Github | false |
80
- | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
81
- | --fork | | Create backports in fork repo | true |
82
- | --git-hostname | | Hostname for Git | github.com |
83
- | --mainline | | Parent id of merge commit | 1 |
84
- | --max-number | --number, -n | Number of commits to choose from | 10 |
85
- | --multiple | | Multi-select for commits and branches | false |
86
- | --multiple-branches | | Multi-select for branches | true |
87
- | --multiple-commits | | Multi-select for commits | false |
88
- | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
89
- | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
90
- | --path | -p | Filter commits by path | |
91
- | --pr-description | --description | Pull request description suffix | |
92
- | --pr-filter | | Find PRs using [Github's search syntax][2] | |
93
- | --pr-title | --title | Title of pull request | |
94
- | --pull-number | --pr | Backport pull request by number | |
95
- | --repo-name | | Name of repository | |
96
- | --repo-owner | | Owner of repository | |
97
- | --reset-author | | Set yourself as commit author | |
98
- | --reviewer | | Add reviewer to the target PR | |
99
- | --sha | | Sha of commit to backport | |
100
- | --source-branch | | Specify a non-default branch to backport from | |
101
- | --source-pr-label | | Labels added to the source PR | |
102
- | --target-branch | -b | Target branch(es) to backport to | |
103
- | --target-pr-label | --label, -l | Labels added to the target PR | |
104
- | --help | | Show help | |
105
- | -v, --version | | Show version number | |
70
+ | Option | Shorthand notation | Description | Default |
71
+ | ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
72
+ | --access-token | | Github access token | |
73
+ | --all | -a | Show commits from any author | false |
74
+ | --assignee | --assign | Assign users to the target PR | |
75
+ | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
76
+ | --auto-assign | | Assign current user to the target PR | false |
77
+ | --branch | -b | Target branch to backport to | |
78
+ | --ci | | Disable interactive prompts | false |
79
+ | --config-file | | Custom path to project config file (.backportrc.json) | |
80
+ | --dir | | Clone repository into custom directory | ~/.backport/repositories/ |
81
+ | --dry-run | | Perform backport without pushing to Github | false |
82
+ | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
83
+ | --fork | | Create backports in fork repo | true |
84
+ | --git-hostname | | Hostname for Git | github.com |
85
+ | --mainline | | Parent id of merge commit | 1 |
86
+ | --max-number | --number, -n | Number of commits to choose from | 10 |
87
+ | --multiple | | Multi-select for commits and branches | false |
88
+ | --multiple-branches | | Multi-select for branches | true |
89
+ | --multiple-commits | | Multi-select for commits | false |
90
+ | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
91
+ | --no-status-comment | | Do not publish a status comment to Github with the results of the backport | false |
92
+ | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
93
+ | --path | -p | Filter commits by path | |
94
+ | --pr-description | --description | Description for pull request | |
95
+ | --pr-filter | | Find PRs using [Github's search syntax][2] | |
96
+ | --pr-title | --title | Title of pull request | |
97
+ | --pull-number | --pr | Backport pull request by number | |
98
+ | --repo-name | | Name of repository | |
99
+ | --repo-owner | | Owner of repository | |
100
+ | --reset-author | | Set yourself as commit author | |
101
+ | --reviewer | | Add reviewer to the target PR | |
102
+ | --sha | | Sha of commit to backport | |
103
+ | --source-branch | | Specify a non-default branch to backport from | |
104
+ | --source-pr-label | | Labels added to the source PR | |
105
+ | --target-branch | -b | Target branch(es) to backport to | |
106
+ | --target-pr-label | --label, -l | Labels added to the target PR | |
107
+ | --help | | Show help | |
108
+ | -v, --version | | Show version number | |
106
109
 
107
110
  The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).
108
111
 
@@ -238,7 +241,7 @@ This tools is for anybody who is working on a codebase where they have to mainta
238
241
  - ability to see which commits have been backported and to which branches
239
242
  - ability to customize the title, description and labels of the created backport PRs
240
243
  - all git operations are handled in a separate directory to not interfere with unstaged files
241
- - Conflicts are handled gracefully, and hints are provided to help the user understand the source of the conflict
244
+ - Conflicts are handled gracefully, and hints are provided to help the user understand the source of the conflict
242
245
  - backport a commit by specifying a PR: `backport --pr 1337`
243
246
  - list and backport commits by a particular user: `backport --author john`
244
247
  - list and backport commits by a particular path: `backport --path src/plugins/chatbot`
@@ -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
+ });
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const main_1 = require("./main");
5
- const logger_1 = require("./services/logger");
6
- const args = process.argv.slice(2);
7
- (0, logger_1.initLogger)();
4
+ const backportRun_1 = require("./backportRun");
5
+ const processArgs = process.argv.slice(2);
8
6
  // this is the entrypoint when running from command line
9
- (0, main_1.main)(args);
7
+ (0, backportRun_1.backportRun)(processArgs);
@@ -1,10 +1,11 @@
1
1
  import { ConfigFileOptions } from './options/ConfigOptions';
2
2
  import { ValidConfigOptions } from './options/options';
3
- export { BackportResponse } from './main';
3
+ export { BackportResponse } from './backportRun';
4
4
  export { ConfigFileOptions } from './options/ConfigOptions';
5
5
  export { Commit } from './services/sourceCommit/parseSourceCommit';
6
- export { fetchProjectConfig } from './services/github/v4/fetchProjectConfig';
7
- export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
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, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
8
9
  export declare function getCommits(options: {
9
10
  accessToken: string;
10
11
  repoName: string;
@@ -16,4 +17,6 @@ export declare function getCommits(options: {
16
17
  sha?: string;
17
18
  skipRemoteConfig?: boolean;
18
19
  sourceBranch?: string;
20
+ dateUntil?: string;
21
+ dateSince?: string;
19
22
  }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommits = exports.backportRun = exports.fetchProjectConfig = void 0;
4
- const main_1 = require("./main");
3
+ exports.getCommits = exports.backportRun = exports.getLocalGlobalConfig = exports.getRemoteProjectConfig = void 0;
4
+ const backportRun_1 = require("./backportRun");
5
5
  const fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
6
6
  const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
7
7
  const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
8
8
  const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
9
  const logger_1 = require("./services/logger");
10
- (0, logger_1.initLogger)();
11
- var fetchProjectConfig_1 = require("./services/github/v4/fetchProjectConfig");
12
- Object.defineProperty(exports, "fetchProjectConfig", { enumerable: true, get: function () { return fetchProjectConfig_1.fetchProjectConfig; } });
10
+ const excludeUndefined_1 = require("./utils/excludeUndefined");
11
+ var fetchRemoteProjectConfig_1 = require("./services/github/v4/fetchRemoteProjectConfig");
12
+ Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
13
+ var globalConfig_1 = require("./options/config/globalConfig");
14
+ Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
13
15
  function backportRun(options,
14
16
  // cli args will not automatically be forwarded when it is consumed as a module
15
17
  // It is simple to forward args manually via `process.argv`:
@@ -18,11 +20,12 @@ function backportRun(options,
18
20
  // const args = process.argv.slice(2);
19
21
  // backportRun(options, args)
20
22
  //
21
- args = []) {
22
- return (0, main_1.main)(args, options);
23
+ processArgs = []) {
24
+ return (0, backportRun_1.backportRun)(processArgs, (0, excludeUndefined_1.excludeUndefined)(options));
23
25
  }
24
26
  exports.backportRun = backportRun;
25
27
  async function getCommits(options) {
28
+ (0, logger_1.initLogger)({ ci: true });
26
29
  const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
27
30
  if (options.pullNumber) {
28
31
  return [
@@ -45,7 +48,10 @@ async function getCommits(options) {
45
48
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
46
49
  ...optionsFromGithub,
47
50
  ...options,
51
+ // filters
48
52
  author: options.author ?? null,
53
+ dateSince: options.dateSince ?? null,
54
+ dateUntil: options.dateUntil ?? null,
49
55
  });
50
56
  }
51
57
  exports.getCommits = getCommits;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.unmock('./services/logger');
4
3
  const entrypoint_module_1 = require("./entrypoint.module");
5
4
  const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
6
5
  describe('entrypoint.module', () => {
@@ -21,6 +20,10 @@ describe('entrypoint.module', () => {
21
20
  number: 4,
22
21
  state: 'MERGED',
23
22
  url: 'https://github.com/backport-org/backport-e2e/pull/4',
23
+ mergeCommit: {
24
+ message: 'Add family emoji (#2) (#4)',
25
+ sha: 'f8b4f6ae7ffaf2732fa5e33e98b3ea772bdfff1d',
26
+ },
24
27
  },
25
28
  ],
26
29
  originalMessage: 'Add family emoji (#2)',
package/dist/main.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.main = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const ora_1 = __importDefault(require("ora"));
8
9
  const options_1 = require("./options/options");
9
10
  const runSequentially_1 = require("./runSequentially");
10
11
  const HandledError_1 = require("./services/HandledError");
@@ -14,10 +15,12 @@ const logger_1 = require("./services/logger");
14
15
  const getCommits_1 = require("./ui/getCommits");
15
16
  const getTargetBranches_1 = require("./ui/getTargetBranches");
16
17
  async function main(argv, optionsFromModule) {
18
+ const spinner = (0, ora_1.default)().start('Initializing...');
17
19
  let options = null;
18
20
  let commits = [];
19
21
  try {
20
22
  options = await (0, options_1.getOptions)(argv, optionsFromModule);
23
+ spinner.stop();
21
24
  commits = await (0, getCommits_1.getCommits)(options);
22
25
  const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
23
26
  const results = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
@@ -33,13 +36,14 @@ async function main(argv, optionsFromModule) {
33
36
  return backportResponse;
34
37
  }
35
38
  catch (e) {
39
+ spinner.stop();
36
40
  const backportResponse = {
37
41
  status: 'failure',
38
42
  commits,
39
43
  errorMessage: e.message,
40
44
  error: e,
41
45
  };
42
- if (options?.ci) {
46
+ if (options) {
43
47
  await (0, createStatusComment_1.createStatusComment)({
44
48
  options,
45
49
  backportResponse,
@@ -22,12 +22,15 @@ declare type Options = Partial<{
22
22
  cherrypickRef: boolean;
23
23
  ci: boolean;
24
24
  commitPaths: string[];
25
+ configFile: string;
25
26
  details: boolean;
27
+ dir: string;
26
28
  editor: string;
27
29
  fork: boolean;
28
30
  gitHostname: string;
29
31
  githubApiBaseUrlV3: string;
30
32
  githubApiBaseUrlV4: string;
33
+ logFilePath: string;
31
34
  maxNumber: number;
32
35
  multiple: boolean;
33
36
  multipleBranches: boolean;
@@ -36,6 +39,7 @@ declare type Options = Partial<{
36
39
  prDescription: string;
37
40
  prFilter: string;
38
41
  prTitle: string;
42
+ publishStatusComment: boolean;
39
43
  pullNumber: number;
40
44
  repoName: string;
41
45
  repoOwner: string;
@@ -1,41 +1,47 @@
1
1
  export declare type OptionsFromCliArgs = ReturnType<typeof getOptionsFromCliArgs>;
2
- export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnError }?: {
2
+ export declare function getOptionsFromCliArgs(processArgs: readonly string[], { exitOnError }?: {
3
3
  exitOnError?: boolean;
4
4
  }): {
5
5
  fork?: boolean | undefined;
6
+ dir?: string | undefined;
6
7
  verbose?: boolean | undefined;
7
8
  accessToken?: string | undefined;
8
- assignees?: string[] | undefined;
9
9
  author?: string | null | undefined;
10
10
  autoAssign?: boolean | undefined;
11
+ assignees?: string[] | undefined;
11
12
  autoMerge?: boolean | undefined;
12
13
  autoMergeMethod?: string | undefined;
13
- cherrypickRef?: boolean | undefined;
14
14
  ci?: boolean | undefined;
15
- commitPaths?: string[] | undefined;
15
+ cherrypickRef?: boolean | undefined;
16
+ configFile?: string | undefined;
16
17
  details?: boolean | undefined;
17
18
  editor?: string | undefined;
19
+ skipRemoteConfig?: boolean | undefined;
18
20
  gitHostname?: string | undefined;
19
21
  githubApiBaseUrlV3?: string | undefined;
20
22
  githubApiBaseUrlV4?: string | undefined;
23
+ logFilePath?: string | undefined;
24
+ mainline?: number | undefined;
21
25
  maxNumber?: number | undefined;
22
26
  multipleBranches?: boolean | undefined;
23
27
  multipleCommits?: boolean | undefined;
24
28
  noVerify?: boolean | undefined;
25
29
  prDescription?: string | undefined;
26
- prFilter?: string | undefined;
27
30
  prTitle?: string | undefined;
31
+ prFilter?: string | undefined;
28
32
  pullNumber?: number | undefined;
29
- repoName?: string | undefined;
30
- repoOwner?: string | undefined;
31
- resetAuthor?: boolean | undefined;
32
- reviewers?: string[] | undefined;
33
33
  sha?: string | undefined;
34
- skipRemoteConfig?: boolean | undefined;
34
+ resetAuthor?: boolean | undefined;
35
+ repoOwner?: string | undefined;
36
+ repoName?: string | undefined;
35
37
  sourceBranch?: string | undefined;
38
+ dateSince?: string | undefined;
39
+ dateUntil?: string | undefined;
40
+ commitPaths?: string[] | undefined;
41
+ reviewers?: string[] | undefined;
36
42
  sourcePRLabels?: string[] | undefined;
37
43
  targetBranchChoices?: string[] | undefined;
38
44
  targetBranches?: string[] | undefined;
39
45
  targetPRLabels?: string[] | undefined;
40
- mainline?: number | undefined;
46
+ publishStatusComment?: boolean | undefined;
41
47
  };
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionsFromCliArgs = void 0;
7
7
  const yargs_1 = __importDefault(require("yargs"));
8
8
  const excludeUndefined_1 = require("../utils/excludeUndefined");
9
- function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
10
- const yargsInstance = (0, yargs_1.default)(argv)
9
+ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
10
+ const yargsInstance = (0, yargs_1.default)(processArgs)
11
11
  .parserConfiguration({
12
12
  'strip-dashed': true,
13
13
  'strip-aliased': true,
@@ -56,6 +56,22 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
56
56
  description: 'Append commit message with "(cherry picked from commit...)',
57
57
  type: 'boolean',
58
58
  conflicts: ['noCherrypickRef'],
59
+ })
60
+ .option('configFile', {
61
+ description: 'Path to project config',
62
+ type: 'string',
63
+ })
64
+ .option('since', {
65
+ description: 'ISO-8601 date for filtering commits',
66
+ type: 'string',
67
+ })
68
+ .option('until', {
69
+ description: 'ISO-8601 date for filtering commits',
70
+ type: 'string',
71
+ })
72
+ .option('dir', {
73
+ description: 'Location where the temporary repository will be stored',
74
+ type: 'string',
59
75
  })
60
76
  .option('details', {
61
77
  description: 'Show details about each commit',
@@ -89,6 +105,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
89
105
  hidden: true,
90
106
  description: `Base url for Github's GraphQL (v4) API`,
91
107
  type: 'string',
108
+ })
109
+ .option('logFilePath', {
110
+ hidden: true,
111
+ description: `Path to log file`,
112
+ type: 'string',
92
113
  })
93
114
  .option('mainline', {
94
115
  description: 'Parent id of merge commit. Defaults to 1 when supplied without arguments',
@@ -97,7 +118,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
97
118
  if (mainline === undefined) {
98
119
  // return 1 if `--mainline` is given without a value
99
120
  // return undefined if --mainline is not supplied at all
100
- return argv.includes('--mainline') ? 1 : undefined;
121
+ return processArgs.includes('--mainline') ? 1 : undefined;
101
122
  }
102
123
  // use specified mainline parent
103
124
  if (Number.isInteger(mainline)) {
@@ -135,6 +156,10 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
135
156
  description: 'Do not append commit message with "(cherry picked from commit...)"',
136
157
  type: 'boolean',
137
158
  conflicts: ['cherrypickRef'],
159
+ })
160
+ .option('noStatusComment', {
161
+ description: "Don't publish status comment to Github",
162
+ type: 'boolean',
138
163
  })
139
164
  .option('noVerify', {
140
165
  description: 'Bypass the pre-commit and commit-msg hooks',
@@ -256,14 +281,19 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
256
281
  /* eslint-disable @typescript-eslint/no-unused-vars */
257
282
  $0, _,
258
283
  /* eslint-enable @typescript-eslint/no-unused-vars */
259
- multiple, multipleBranches, multipleCommits, all, author,
284
+ multiple, multipleBranches, multipleCommits, all,
285
+ // filters
286
+ author, since, until,
260
287
  // negations
261
- verify, noVerify, noCherrypickRef, noFork,
288
+ noCherrypickRef, noFork, noStatusComment, noVerify, verify,
262
289
  // array types (should be renamed to plural form)
263
290
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
264
291
  return (0, excludeUndefined_1.excludeUndefined)({
265
292
  ...restOptions,
293
+ // filters
266
294
  author: all ? null : author,
295
+ dateSince: since,
296
+ dateUntil: until,
267
297
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
268
298
  multipleBranches: multiple ?? multipleBranches,
269
299
  multipleCommits: multiple ?? multipleCommits,
@@ -279,6 +309,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
279
309
  cherrypickRef: noCherrypickRef === true ? false : restOptions.cherrypickRef,
280
310
  fork: noFork === true ? false : restOptions.fork,
281
311
  noVerify: verify ?? noVerify,
312
+ publishStatusComment: noStatusComment === true ? false : undefined,
282
313
  });
283
314
  }
284
315
  exports.getOptionsFromCliArgs = getOptionsFromCliArgs;