backport 7.3.5 → 8.0.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 (87) hide show
  1. package/README.md +13 -18
  2. package/dist/backportRun.d.ts +14 -3
  3. package/dist/backportRun.js +59 -37
  4. package/dist/entrypoint.cli.js +1 -1
  5. package/dist/entrypoint.module.d.ts +8 -3
  6. package/dist/entrypoint.module.js +6 -10
  7. package/dist/entrypoint.module.private.test.js +129 -330
  8. package/dist/options/ConfigOptions.d.ts +2 -2
  9. package/dist/options/cliArgs.d.ts +10 -6
  10. package/dist/options/cliArgs.js +32 -21
  11. package/dist/options/cliArgs.test.js +3 -3
  12. package/dist/options/config/config.d.ts +2 -2
  13. package/dist/options/config/config.js +2 -2
  14. package/dist/options/config/globalConfig.d.ts +2 -2
  15. package/dist/options/config/globalConfig.js +13 -10
  16. package/dist/options/config/projectConfig.d.ts +2 -2
  17. package/dist/options/config/projectConfig.js +3 -3
  18. package/dist/options/config/projectConfig.test.js +19 -7
  19. package/dist/options/config/readConfigFile.d.ts +4 -4
  20. package/dist/options/options.d.ts +4 -5
  21. package/dist/options/options.js +2 -3
  22. package/dist/options/options.test.js +7 -4
  23. package/dist/runSequentially.d.ts +5 -1
  24. package/dist/runSequentially.js +23 -8
  25. package/dist/scripts/postinstall.js +1 -0
  26. package/dist/scripts/postinstall.test.js +5 -1
  27. package/dist/services/HandledError.d.ts +6 -2
  28. package/dist/services/HandledError.js +8 -8
  29. package/dist/services/child-process-promisified.d.ts +19 -3
  30. package/dist/services/child-process-promisified.js +46 -17
  31. package/dist/services/git.d.ts +6 -7
  32. package/dist/services/git.integration.test.js +381 -65
  33. package/dist/services/git.js +188 -126
  34. package/dist/services/git.private.test.d.ts +1 -0
  35. package/dist/services/git.private.test.js +618 -0
  36. package/dist/services/git.test.js +167 -158
  37. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  38. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  39. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  40. package/dist/services/github/v3/createPullRequest.js +3 -1
  41. package/dist/services/github/v3/createStatusComment.js +16 -16
  42. package/dist/services/github/v3/createStatusComment.test.js +17 -5
  43. package/dist/services/github/v4/apiRequestV4.js +6 -9
  44. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  45. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  46. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  53. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  54. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
  55. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  56. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  60. package/dist/services/logger.d.ts +1 -4
  61. package/dist/services/logger.js +14 -19
  62. package/dist/services/test.d.ts +1 -0
  63. package/dist/services/test.js +23 -0
  64. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  65. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
  66. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
  67. package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
  68. package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
  69. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  70. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  71. package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
  72. package/dist/test/sandbox.js +5 -1
  73. package/dist/test/setupFiles/automatic-mocks.js +16 -12
  74. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
  75. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  76. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  77. package/dist/ui/getGitConfigAuthor.js +1 -1
  78. package/dist/ui/getTargetBranches.test.js +5 -1
  79. package/dist/ui/ora.d.ts +1 -8
  80. package/dist/ui/setupRepo.js +1 -1
  81. package/dist/ui/setupRepo.test.js +98 -61
  82. package/dist/utils/isErrnoError.d.ts +2 -0
  83. package/dist/utils/isErrnoError.js +7 -0
  84. package/dist/utils/packageVersion.d.ts +1 -1
  85. package/dist/utils/packageVersion.js +1 -1
  86. package/package.json +13 -13
  87. package/yarn.lock +414 -695
@@ -23,9 +23,9 @@ export declare function getOptionsFromGithub(options: {
23
23
  cherrypickRef?: boolean | undefined;
24
24
  ci?: boolean | undefined;
25
25
  commitPaths?: string[] | undefined;
26
- configFile?: string | undefined;
27
26
  details?: boolean | undefined;
28
27
  dir?: string | undefined;
28
+ dryRun?: boolean | undefined;
29
29
  editor?: string | undefined;
30
30
  fork?: boolean | undefined;
31
31
  gitAuthorEmail?: string | undefined;
@@ -42,6 +42,7 @@ export declare function getOptionsFromGithub(options: {
42
42
  noVerify?: boolean | undefined;
43
43
  prDescription?: string | undefined;
44
44
  prFilter?: string | undefined;
45
+ projectConfigFile?: string | undefined;
45
46
  prTitle?: string | undefined;
46
47
  publishStatusComment?: boolean | undefined;
47
48
  pullNumber?: number | undefined;
@@ -57,7 +58,6 @@ export declare function getOptionsFromGithub(options: {
57
58
  targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
58
59
  targetBranches?: string[] | undefined;
59
60
  targetPRLabels?: string[] | undefined;
60
- verbose?: boolean | undefined;
61
61
  help?: boolean | undefined;
62
62
  version?: boolean | undefined;
63
63
  v?: boolean | undefined;
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const os_1 = __importDefault(require("os"));
7
7
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
8
8
  const getOptionsFromGithub_1 = require("./getOptionsFromGithub");
9
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
9
10
  describe('getOptionsFromGithub', () => {
10
- let devAccessToken;
11
11
  beforeAll(async () => {
12
- devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
13
12
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
14
13
  });
15
14
  describe('access token', () => {
@@ -29,7 +28,7 @@ describe('getOptionsFromGithub', () => {
29
28
  it('returns the options', async () => {
30
29
  const combinedOptions = {
31
30
  author: 'sqren',
32
- accessToken: devAccessToken,
31
+ accessToken,
33
32
  repoOwner: 'backport-org',
34
33
  repoName: 'backport-e2e',
35
34
  cwd: process.cwd(),
@@ -58,7 +57,7 @@ describe('getOptionsFromGithub', () => {
58
57
  it('returns original repoOwner', async () => {
59
58
  const combinedOptions = {
60
59
  author: 'sqren',
61
- accessToken: devAccessToken,
60
+ accessToken,
62
61
  repoOwner: 'sqren',
63
62
  repoName: 'backport-e2e',
64
63
  cwd: process.cwd(),
@@ -72,7 +71,7 @@ describe('getOptionsFromGithub', () => {
72
71
  it('uses the default branch of the repo', async () => {
73
72
  const combinedOptions = {
74
73
  author: 'sqren',
75
- accessToken: devAccessToken,
74
+ accessToken,
76
75
  repoOwner: 'backport-org',
77
76
  repoName: 'repo-with-non-standard-main-branch',
78
77
  cwd: process.cwd(),
@@ -87,7 +86,7 @@ describe('getOptionsFromGithub', () => {
87
86
  it('shows a warning', async () => {
88
87
  const combinedOptions = {
89
88
  author: 'sqren',
90
- accessToken: devAccessToken,
89
+ accessToken,
91
90
  repoOwner: 'backport-org',
92
91
  repoName: 'repo-with-branch-named-backport',
93
92
  cwd: process.cwd(),
@@ -102,7 +101,7 @@ describe('getOptionsFromGithub', () => {
102
101
  it('does not throw', async () => {
103
102
  const combinedOptions = {
104
103
  author: 'sqren',
105
- accessToken: devAccessToken,
104
+ accessToken,
106
105
  repoOwner: 'backport-org',
107
106
  repoName: 'repo-with-backportrc-removed',
108
107
  cwd: process.cwd(),
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -24,11 +28,8 @@ const sandbox_1 = require("../../../test/sandbox");
24
28
  const childProcess = __importStar(require("../../child-process-promisified"));
25
29
  const getRepoOwnerAndNameFromGitRemotes_1 = require("./getRepoOwnerAndNameFromGitRemotes");
26
30
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
31
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
27
32
  describe('fetchRemoteProjectConfig', () => {
28
- let devAccessToken;
29
- beforeEach(() => {
30
- devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
- });
32
33
  describe('when the remote is a fork', () => {
33
34
  it('retrives the original owner from github', async () => {
34
35
  await (0, sandbox_1.resetSandbox)(sandboxPath);
@@ -36,7 +37,7 @@ describe('fetchRemoteProjectConfig', () => {
36
37
  await childProcess.exec(`git init`, execOpts);
37
38
  await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
38
39
  expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
39
- accessToken: devAccessToken,
40
+ accessToken,
40
41
  cwd: sandboxPath,
41
42
  })).toEqual({
42
43
  repoName: 'kibana',
@@ -52,7 +53,7 @@ describe('fetchRemoteProjectConfig', () => {
52
53
  await childProcess.exec(`git remote add foo git@github.com:foo/kibana.git`, execOpts);
53
54
  await childProcess.exec(`git remote add bar git@github.com:bar/kibana.git`, execOpts);
54
55
  expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
55
- accessToken: devAccessToken,
56
+ accessToken,
56
57
  cwd: sandboxPath,
57
58
  })).toEqual({});
58
59
  });
@@ -63,7 +64,7 @@ describe('fetchRemoteProjectConfig', () => {
63
64
  const execOpts = { cwd: sandboxPath };
64
65
  await childProcess.exec(`git init`, execOpts);
65
66
  expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
66
- accessToken: devAccessToken,
67
+ accessToken,
67
68
  cwd: sandboxPath,
68
69
  })).toEqual({});
69
70
  });
@@ -6,7 +6,4 @@ export declare function initLogger({ ci, accessToken, logFilePath, }: {
6
6
  logFilePath?: string;
7
7
  }): winston.Logger;
8
8
  export declare function consoleLog(message: string): void;
9
- export declare function updateLogger({ accessToken, verbose, }: {
10
- accessToken: string;
11
- verbose?: boolean;
12
- }): void;
9
+ export declare function setAccessToken(accessToken: string): void;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,17 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.updateLogger = exports.consoleLog = exports.initLogger = exports.logger = void 0;
26
+ exports.setAccessToken = exports.consoleLog = exports.initLogger = exports.logger = void 0;
23
27
  const winston_1 = __importStar(require("winston"));
24
28
  const redact_1 = require("../utils/redact");
25
29
  const env_1 = require("./env");
26
30
  let _accessToken;
27
31
  let _ci;
28
32
  function initLogger({ ci, accessToken, logFilePath, }) {
29
- const fileTransport = getFileTransport({ logFilePath });
30
- if (accessToken) {
31
- _accessToken = accessToken;
32
- }
33
+ _accessToken = accessToken;
33
34
  _ci = ci;
34
35
  exports.logger = winston_1.default.createLogger({
35
36
  format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
@@ -37,7 +38,11 @@ function initLogger({ ci, accessToken, logFilePath, }) {
37
38
  winston_1.format.metadata({
38
39
  fillExcept: ['message', 'level', 'timestamp', 'label'],
39
40
  })),
40
- transports: fileTransport,
41
+ transports: new winston_1.default.transports.File({
42
+ filename: (0, env_1.getLogfilePath)({ logFilePath }),
43
+ level: 'debug',
44
+ format: winston_1.format.combine(winston_1.format.json()),
45
+ }),
41
46
  });
42
47
  return exports.logger;
43
48
  }
@@ -50,13 +55,10 @@ function consoleLog(message) {
50
55
  }
51
56
  }
52
57
  exports.consoleLog = consoleLog;
53
- function updateLogger({ accessToken, verbose, }) {
54
- // set access token
58
+ function setAccessToken(accessToken) {
55
59
  _accessToken = accessToken;
56
- // set log level
57
- exports.logger.level = verbose ? 'debug' : 'info';
58
60
  }
59
- exports.updateLogger = updateLogger;
61
+ exports.setAccessToken = setAccessToken;
60
62
  function redactAccessToken(str) {
61
63
  // `redactAccessToken` might be called before access token is set
62
64
  if (_accessToken) {
@@ -64,13 +66,6 @@ function redactAccessToken(str) {
64
66
  }
65
67
  return str;
66
68
  }
67
- function getFileTransport({ logFilePath }) {
68
- return new winston_1.default.transports.File({
69
- filename: (0, env_1.getLogfilePath)({ logFilePath }),
70
- level: 'debug',
71
- format: winston_1.format.combine(winston_1.format.json()),
72
- });
73
- }
74
69
  // log levels:
75
70
  // - error
76
71
  // - warn
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ async function init() {
5
+ try {
6
+ await (0, promises_1.writeFile)('foo.txt', 'foo', {
7
+ flag: 'wx',
8
+ mode: 0o600, // give the owner read-write privleges, no access for others
9
+ });
10
+ }
11
+ catch (e) {
12
+ const a = e instanceof Error;
13
+ console.log(a);
14
+ console.log(e.constructor.name);
15
+ if (isErrnoError(e)) {
16
+ console.log(e.path);
17
+ }
18
+ }
19
+ }
20
+ init();
21
+ function isErrnoError(error) {
22
+ return error instanceof Error && 'code' in error;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
27
+ const env_1 = require("../../../services/env");
28
+ const packageVersion = __importStar(require("../../../utils/packageVersion"));
29
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
30
+ const sandbox_1 = require("../../sandbox");
31
+ const runBackportViaCli_1 = require("./runBackportViaCli");
32
+ const TIMEOUT_IN_SECONDS = 15;
33
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
34
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
35
+ describe('entrypoint cli', () => {
36
+ it('--version', async () => {
37
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
38
+ showOra: true,
39
+ });
40
+ expect(res).toEqual(process.env.npm_package_version);
41
+ });
42
+ it('-v', async () => {
43
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
44
+ showOra: true,
45
+ });
46
+ expect(res).toEqual(process.env.npm_package_version);
47
+ });
48
+ it('PACKAGE_VERSION should match', async () => {
49
+ // @ts-expect-error
50
+ expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
51
+ });
52
+ it('--help', async () => {
53
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
54
+ expect(res).toMatchInlineSnapshot(`
55
+ "entrypoint.cli.ts [args]
56
+ Options:
57
+ -v, --version Show version number [boolean]
58
+ --accessToken, --accesstoken Github access token [string]
59
+ -a, --all List all commits [boolean]
60
+ --assignee, --assign Add assignees to the target pull request [array]
61
+ --autoAssign Auto assign the target pull request to yourself [boolean]
62
+ --autoMerge Enable auto-merge for created pull requests [boolean]
63
+ --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
64
+ merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
65
+ --ci Disable interactive prompts [boolean]
66
+ --cherrypickRef Append commit message with \\"(cherry picked from commit...)
67
+ [boolean]
68
+ --projectConfigFile, --config Path to project config [string]
69
+ --since ISO-8601 date for filtering commits [string]
70
+ --until ISO-8601 date for filtering commits [string]
71
+ --dir Path to temporary backport repo [string]
72
+ --details Show details about each commit [boolean]
73
+ --dryRun Run backport locally without pushing to Github [boolean]
74
+ --editor Editor to be opened during conflict resolution [string]
75
+ --skipRemoteConfig Use local .backportrc.json config instead of loading from
76
+ Github [boolean]
77
+ --fork Create backports in fork or origin repo. Defaults to true
78
+ [boolean]
79
+ --gitAuthorName Set commit author name [string]
80
+ --gitAuthorEmail Set commit author email [string]
81
+ --ls List commits instead of backporting them [boolean]
82
+ --mainline Parent id of merge commit. Defaults to 1 when supplied
83
+ without arguments [number]
84
+ -n, --maxNumber, --number Number of commits to choose from [number]
85
+ --multiple Select multiple branches/commits [boolean]
86
+ --multipleBranches Backport to multiple branches [boolean]
87
+ --multipleCommits Backport multiple commits [boolean]
88
+ --noCherrypickRef Do not append commit message with \\"(cherry picked from
89
+ commit...)\\" [boolean]
90
+ --noStatusComment Don't publish status comment to Github [boolean]
91
+ --noVerify Bypass the pre-commit and commit-msg hooks [boolean]
92
+ --noFork Create backports in the origin repo [boolean]
93
+ --onlyMissing Only list commits with missing or unmerged backports
94
+ [boolean]
95
+ -p, --path Only list commits touching files under the specified path
96
+ [array]
97
+ --prDescription, --description Description to be added to pull request [string]
98
+ --prTitle, --title Title of pull request [string]
99
+ --prFilter Filter source pull requests by a query [string]
100
+ --pullNumber, --pr Pull request to backport [number]
101
+ --resetAuthor Set yourself as commit author [boolean]
102
+ --reviewer Add reviewer to the target PR [array]
103
+ --repoForkOwner The owner of the fork where the backport branch is pushed.
104
+ Defaults to the currently authenticated user [string]
105
+ --repo Repo owner and name [string]
106
+ --sha, --commit Commit sha to backport [string]
107
+ --sourceBranch Specify a non-default branch (normally \\"master\\") to backport
108
+ from [string]
109
+ --sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
110
+ -b, --targetBranch, --branch Branch(es) to backport to [array]
111
+ --targetBranchChoice List branches to backport to [array]
112
+ -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
113
+ --verify Opposite of no-verify [boolean]
114
+ --help Show help [boolean]
115
+ For bugs, feature requests or questions: https://github.com/sqren/backport/issues
116
+ Or contact me directly: https://twitter.com/sorenlouv"
117
+ `);
118
+ });
119
+ it('should output error when branch is missing', async () => {
120
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
121
+ '--skip-remote-config',
122
+ '--repo=backport-org/backport-e2e',
123
+ `--accessToken=${accessToken}`,
124
+ ]);
125
+ expect(res).toMatchInlineSnapshot(`
126
+ "Please specify a target branch: \\"--branch 6.1\\".
127
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
128
+ `);
129
+ });
130
+ it('should output error when access token is invalid', async () => {
131
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
132
+ '--branch=foo',
133
+ '--repo=foo/bar',
134
+ '--accessToken=some-token',
135
+ ]);
136
+ expect(res).toContain('Please check your access token and make sure it is valid');
137
+ });
138
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
139
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
140
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
141
+ await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
142
+ await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
143
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
144
+ cwd: sandboxPath,
145
+ waitForString: 'Select commit',
146
+ });
147
+ expect(res).toMatchInlineSnapshot(`
148
+ "? Select commit (Use arrow keys)
149
+ ❯ 1. Add sheep emoji (#9) 7.8
150
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
151
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
152
+ 4. Add family emoji (#2) 7.x
153
+ 5. Add \`backport\` dep
154
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
155
+ 7. Add ❤️ emoji
156
+ 8. Update .backportrc.json
157
+ 9. Bump to 8.0.0
158
+ 10.Add package.json"
159
+ `);
160
+ });
161
+ it(`should output error when repo doesn't exist`, async () => {
162
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
163
+ '--branch=foo',
164
+ '--repo=foo/bar',
165
+ '--author=sqren',
166
+ `--accessToken=${accessToken}`,
167
+ ]);
168
+ expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
169
+ });
170
+ it(`should output error when given branch is invalid`, async () => {
171
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
172
+ '--branch=foo',
173
+ '--repo=backport-org/backport-e2e',
174
+ '--pr=9',
175
+ `--accessToken=${accessToken}`,
176
+ ], { waitForString: "is invalid or doesn't exist" });
177
+ expect(res).toMatchInlineSnapshot(`
178
+ "
179
+ Backporting to foo:
180
+ The branch \\"foo\\" is invalid or doesn't exist"
181
+ `);
182
+ });
183
+ it(`should output merge conflict`, async () => {
184
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
185
+ '--repo=backport-org/repo-with-conflicts',
186
+ '--pr=12',
187
+ '--branch=7.x',
188
+ `--accessToken=${accessToken}`,
189
+ '--dry-run',
190
+ ], {
191
+ waitForString: 'Press ENTER when the conflicts',
192
+ });
193
+ const backportDir = (0, env_1.getBackportDirPath)();
194
+ expect(res.replaceAll(backportDir, '<HOMEDIR>')).toMatchInlineSnapshot(`
195
+ "
196
+ Backporting to 7.x:
197
+ The commit could not be backported due to conflicts
198
+ Please fix the conflicts in <HOMEDIR>/repositories/backport-org/repo-with-conflicts
199
+ Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\":
200
+ - Change Barca to Braithwaite (#8) (backport missing)
201
+ https://github.com/backport-org/repo-with-conflicts/pull/8
202
+ ? Fix the following conflicts manually:
203
+ Conflicting files:
204
+ - <HOMEDIR>/repositories/backport-org/repo-with-conflicts/la-liga.
205
+ md
206
+ Press ENTER when the conflicts are resolved and files are staged (Y/n)"
207
+ `);
208
+ });
209
+ it(`should list commits from master`, async () => {
210
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
211
+ '--branch=foo',
212
+ '--repo=backport-org/backport-e2e',
213
+ '--author=sqren',
214
+ `--accessToken=${accessToken}`,
215
+ '--max-number=6',
216
+ ], { waitForString: 'Select commit' });
217
+ expect(output).toMatchInlineSnapshot(`
218
+ "? Select commit (Use arrow keys)
219
+ ❯ 1. Add sheep emoji (#9) 7.8
220
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
221
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
222
+ 4. Add family emoji (#2) 7.x
223
+ 5. Add \`backport\` dep
224
+ 6. Merge pull request #1 from backport-org/add-heart-emoji"
225
+ `);
226
+ });
227
+ it(`should filter commits by "since" and "until"`, async () => {
228
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
229
+ '--branch=foo',
230
+ '--repo=backport-org/backport-e2e',
231
+ `--accessToken=${accessToken}`,
232
+ '--since=2020-08-15T10:00:00.000Z',
233
+ '--until=2020-08-15T10:30:00.000Z',
234
+ ], { waitForString: 'Select commit' });
235
+ expect(output).toMatchInlineSnapshot(`
236
+ "? Select commit (Use arrow keys)
237
+ ❯ 1. Bump to 8.0.0
238
+ 2. Add package.json
239
+ 3. Update .backportrc.json
240
+ 4. Create .backportrc.json"
241
+ `);
242
+ });
243
+ it(`should list commits from 7.x`, async () => {
244
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
245
+ '--branch=foo',
246
+ '--repo=backport-org/backport-e2e',
247
+ '--author=sqren',
248
+ `--accessToken=${accessToken}`,
249
+ '--max-number=6',
250
+ '--source-branch=7.x',
251
+ ], { waitForString: 'Select commit' });
252
+ expect(output).toMatchInlineSnapshot(`
253
+ "? Select commit (Use arrow keys)
254
+ ❯ 1. Add 🍏 emoji (#5) (#6)
255
+ 2. Change Ulysses to Carol
256
+ 3. Add family emoji (#2) (#4)
257
+ 4. Update .backportrc.json
258
+ 5. Branch off: 7.9.0 (7.x)
259
+ 6. Bump to 8.0.0"
260
+ `);
261
+ });
262
+ describe('ci failure cases', () => {
263
+ it(`when access token is missing`, async () => {
264
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci']);
265
+ const backportResult = JSON.parse(output);
266
+ expect(backportResult.status).toBe('failure');
267
+ expect(backportResult.errorMessage).toEqual('Access token missing. It must be explicitly supplied when using "--ci" option. Example: --access-token very-secret');
268
+ });
269
+ it(`when argument is invalid`, async () => {
270
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci', '--foo']);
271
+ const backportResult = JSON.parse(output);
272
+ expect(backportResult.status).toBe('failure');
273
+ expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
274
+ });
275
+ it('when `--repo` is invalid', async () => {
276
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
277
+ '--repo=backport-org/backport-e2e-foo',
278
+ '--ci',
279
+ `--accessToken=${accessToken}`,
280
+ ]);
281
+ const backportResult = JSON.parse(output);
282
+ expect(backportResult.status).toBe('failure');
283
+ expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
284
+ });
285
+ it('when `--sha` is invalid', async () => {
286
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
287
+ '--repo=backport-org/backport-e2e',
288
+ '--sha=abcdefg',
289
+ '--ci',
290
+ `--accessToken=${accessToken}`,
291
+ ]);
292
+ const backportResult = JSON.parse(output);
293
+ expect(backportResult.status).toBe('failure');
294
+ expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
295
+ });
296
+ it('when `--branch` is invalid', async () => {
297
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
298
+ '--repo=backport-org/backport-e2e',
299
+ '--pr=9',
300
+ '--branch=foobar',
301
+ '--ci',
302
+ `--accessToken=${accessToken}`,
303
+ ]);
304
+ const backportResult = JSON.parse(output);
305
+ expect(backportResult.status).toBe('success');
306
+ expect(backportResult.results[0]).toEqual({
307
+ error: {
308
+ errorContext: {
309
+ code: 'message-only-exception',
310
+ message: 'The branch "foobar" is invalid or doesn\'t exist',
311
+ },
312
+ name: 'HandledError',
313
+ },
314
+ status: 'handled-error',
315
+ targetBranch: 'foobar',
316
+ });
317
+ });
318
+ it('when `--pr` is invalid', async () => {
319
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
320
+ '--repo=backport-org/backport-e2e',
321
+ '--pr=900',
322
+ '--branch=foobar',
323
+ '--ci',
324
+ `--accessToken=${accessToken}`,
325
+ ]);
326
+ const backportResult = JSON.parse(output);
327
+ expect(backportResult.status).toEqual('failure');
328
+ expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
329
+ });
330
+ it('when having conflicts', async () => {
331
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
332
+ '--repo=backport-org/repo-with-conflicts',
333
+ '--pr=12',
334
+ '--branch=7.x',
335
+ '--ci',
336
+ `--accessToken=${accessToken}`,
337
+ ]);
338
+ const backportResult = JSON.parse(output);
339
+ expect(backportResult.status).toEqual('success');
340
+ expect(
341
+ //@ts-expect-error
342
+ backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
343
+ });
344
+ it('when `--source-branch` is invalid', async () => {
345
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
346
+ '--repo=backport-org/backport-e2e',
347
+ '--pr=9',
348
+ '--branch=7.x',
349
+ '--source-branch=foo',
350
+ '--ci',
351
+ `--accessToken=${accessToken}`,
352
+ ]);
353
+ const backportResult = JSON.parse(output);
354
+ expect(backportResult.status).toBe('success');
355
+ expect(backportResult.results[0]).toEqual({
356
+ error: {
357
+ context: {
358
+ cmdArgs: ['checkout', 'foo'],
359
+ code: 1,
360
+ stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
361
+ stdout: '',
362
+ },
363
+ name: 'SpawnError',
364
+ },
365
+ status: 'unhandled-error',
366
+ targetBranch: '7.x',
367
+ });
368
+ });
369
+ it('when PR is not merged', async () => {
370
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
371
+ '--repo=backport-org/backport-e2e',
372
+ '--pr=12',
373
+ '--ci',
374
+ `--accessToken=${accessToken}`,
375
+ ]);
376
+ const backportResult = JSON.parse(output);
377
+ expect(backportResult.status).toBe('failure');
378
+ expect(backportResult.error).toEqual({
379
+ errorContext: {
380
+ code: 'message-only-exception',
381
+ message: 'The PR #12 is not merged',
382
+ },
383
+ name: 'HandledError',
384
+ });
385
+ });
386
+ it('when target branch is missing', async () => {
387
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
388
+ '--repo=backport-org/backport-e2e',
389
+ '--pr=9',
390
+ '--ci',
391
+ `--accessToken=${accessToken}`,
392
+ ]);
393
+ const backportResult = JSON.parse(output);
394
+ expect(backportResult.status).toBe('aborted');
395
+ expect(backportResult.error).toEqual({
396
+ errorContext: { code: 'no-branches-exception' },
397
+ name: 'HandledError',
398
+ });
399
+ });
400
+ });
401
+ });