backport 7.3.2 → 7.3.5

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 (47) hide show
  1. package/README.md +8 -0
  2. package/dist/backportRun.js +25 -12
  3. package/dist/entrypoint.cli.js +2 -2
  4. package/dist/entrypoint.module.d.ts +3 -0
  5. package/dist/entrypoint.module.js +19 -8
  6. package/dist/entrypoint.module.private.test.d.ts +1 -0
  7. package/dist/entrypoint.module.private.test.js +592 -0
  8. package/dist/options/ConfigOptions.d.ts +1 -0
  9. package/dist/options/cliArgs.d.ts +2 -0
  10. package/dist/options/cliArgs.js +8 -0
  11. package/dist/options/config/config.d.ts +1 -0
  12. package/dist/options/config/readConfigFile.d.ts +1 -0
  13. package/dist/options/options.d.ts +2 -0
  14. package/dist/options/options.js +5 -5
  15. package/dist/options/options.test.js +9 -2
  16. package/dist/services/github/v4/apiRequestV4.d.ts +3 -3
  17. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +2 -2
  18. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +3 -2
  19. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -0
  20. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +1 -1
  21. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +1 -1
  22. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +3 -3
  23. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +10 -4
  24. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  25. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +68 -0
  26. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  27. package/dist/services/github/v4/throwOnInvalidAccessToken.js +1 -1
  28. package/dist/services/prompt.test.js +1 -1
  29. package/dist/services/prompts.js +4 -4
  30. package/dist/services/remoteConfig.js +1 -1
  31. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +1 -1
  32. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +1 -1
  33. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +39 -39
  34. package/dist/services/sourceCommit/parseSourceCommit.test.js +3 -3
  35. package/dist/test/e2e/cli/cli.private.test.js +3 -0
  36. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  37. package/dist/ui/getCommits.js +15 -4
  38. package/dist/ui/getCommitsWithoutBackports.test.js +2 -2
  39. package/dist/ui/getTargetBranches.js +1 -1
  40. package/dist/ui/getTargetBranches.test.js +2 -2
  41. package/dist/utils/filterMissingCommits.d.ts +2 -0
  42. package/dist/utils/filterMissingCommits.js +7 -0
  43. package/dist/utils/filterUnmergedCommits.d.ts +2 -0
  44. package/dist/utils/filterUnmergedCommits.js +7 -0
  45. package/dist/utils/packageVersion.d.ts +1 -1
  46. package/dist/utils/packageVersion.js +1 -1
  47. package/package.json +3 -2
package/README.md CHANGED
@@ -6,6 +6,14 @@
6
6
  <br>
7
7
  </div>
8
8
 
9
+ ## 🎉 New! The Backport Tool as a Github Action 🎉
10
+
11
+ A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) around The Backport Tool now exists. It makes it a breeze to get automatic backports when pull requests are merged.
12
+
13
+ # Backport CLI tool
14
+
15
+ The remaining documentation focuses on the Backport CLI tool (not the Github Action) although all configuration options apply to the Github Action too. The only difference is that the CLI tool is interactive and run manually locally, where the Github Action runs automatically.
16
+
9
17
  ## How it works
10
18
 
11
19
  1. Select a commit to backport
@@ -36,6 +36,13 @@ async function backportRun(processArgs, optionsFromModule = {}) {
36
36
  spinner.stop();
37
37
  commits = await (0, getCommits_1.getCommits)(options);
38
38
  logger_1.logger.info('Commits', commits);
39
+ if (options.ls) {
40
+ return {
41
+ status: 'success',
42
+ commits,
43
+ results: [],
44
+ };
45
+ }
39
46
  const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
40
47
  logger_1.logger.info('Target branches', targetBranches);
41
48
  const [gitConfigAuthor] = await Promise.all([
@@ -74,18 +81,8 @@ async function backportRun(processArgs, optionsFromModule = {}) {
74
81
  backportResponse,
75
82
  });
76
83
  }
77
- if (e instanceof HandledError_1.HandledError || e instanceof apiRequestV4_1.GithubV4Exception) {
78
- (0, logger_1.consoleLog)(e.message);
79
- }
80
- else if (e instanceof Error) {
81
- // output
82
- (0, logger_1.consoleLog)('\n');
83
- (0, logger_1.consoleLog)(chalk_1.default.bold('⚠️ Ouch! An unhandled error occured 😿'));
84
- (0, logger_1.consoleLog)(e.stack ? e.stack : e.message);
85
- (0, logger_1.consoleLog)('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
86
- (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)({
87
- logFilePath,
88
- })}`));
84
+ if (!options?.ls) {
85
+ outputError({ e, logFilePath });
89
86
  }
90
87
  logger_1.logger.error('Unhandled exception', e);
91
88
  process.exitCode = 1;
@@ -93,3 +90,19 @@ async function backportRun(processArgs, optionsFromModule = {}) {
93
90
  }
94
91
  }
95
92
  exports.backportRun = backportRun;
93
+ function outputError({ e, logFilePath, }) {
94
+ if (e instanceof HandledError_1.HandledError || e instanceof apiRequestV4_1.GithubV4Exception) {
95
+ (0, logger_1.consoleLog)(e.message);
96
+ return;
97
+ }
98
+ if (e instanceof Error) {
99
+ // output
100
+ (0, logger_1.consoleLog)('\n');
101
+ (0, logger_1.consoleLog)(chalk_1.default.bold('⚠️ Ouch! An unhandled error occured 😿'));
102
+ (0, logger_1.consoleLog)(e.stack ? e.stack : e.message);
103
+ (0, logger_1.consoleLog)('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
104
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)({
105
+ logFilePath,
106
+ })}`));
107
+ }
108
+ }
@@ -9,8 +9,8 @@ const processArgs = process.argv.slice(2);
9
9
  // this is the entrypoint when running from command line
10
10
  (0, backportRun_1.backportRun)(processArgs).then((backportResponse) => {
11
11
  const argv = (0, yargs_parser_1.default)(processArgs);
12
- const ci = argv.ci;
13
- if (ci) {
12
+ const { ci, ls } = argv;
13
+ if (ci || ls) {
14
14
  // eslint-disable-next-line no-console
15
15
  console.log(JSON.stringify(backportResponse));
16
16
  }
@@ -14,6 +14,9 @@ export declare function getCommits(options: {
14
14
  author?: string;
15
15
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
16
16
  githubApiBaseUrlV4?: string;
17
+ maxNumber?: number;
18
+ onlyMissing?: boolean;
19
+ prFilter?: string;
17
20
  pullNumber?: number;
18
21
  sha?: string | string[];
19
22
  skipRemoteConfig?: boolean;
@@ -5,6 +5,7 @@ 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
+ const fetchPullRequestsBySearchQuery_1 = require("./services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery");
8
9
  const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
10
  const logger_1 = require("./services/logger");
10
11
  const excludeUndefined_1 = require("./utils/excludeUndefined");
@@ -40,13 +41,23 @@ async function getCommits(options) {
40
41
  const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
41
42
  return Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...optionsFromGithub, ...options, sha })));
42
43
  }
43
- return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
44
- ...optionsFromGithub,
45
- ...options,
46
- // filters
47
- author: options.author ?? null,
48
- dateSince: options.dateSince ?? null,
49
- dateUntil: options.dateUntil ?? null,
50
- });
44
+ if (options.prFilter) {
45
+ return (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
46
+ ...optionsFromGithub,
47
+ ...options,
48
+ prFilter: options.prFilter,
49
+ author: options.author ?? null,
50
+ });
51
+ }
52
+ if (options.author) {
53
+ return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
54
+ ...optionsFromGithub,
55
+ ...options,
56
+ author: options.author,
57
+ dateSince: options.dateSince ?? null,
58
+ dateUntil: options.dateUntil ?? null,
59
+ });
60
+ }
61
+ throw new Error('Must supply one of: `pullNumber`, `sha`, `prFilter` or `author`');
51
62
  }
52
63
  exports.getCommits = getCommits;
@@ -0,0 +1 @@
1
+ export {};