backport 6.2.0 → 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 (35) hide show
  1. package/README.md +2 -1
  2. package/dist/entrypoint.cli.js +3 -5
  3. package/dist/entrypoint.module.d.ts +2 -2
  4. package/dist/entrypoint.module.js +4 -4
  5. package/dist/options/ConfigOptions.d.ts +3 -1
  6. package/dist/options/cliArgs.d.ts +16 -14
  7. package/dist/options/cliArgs.js +12 -3
  8. package/dist/options/config/config.d.ts +8 -4
  9. package/dist/options/config/config.js +8 -2
  10. package/dist/options/config/config.test.js +27 -1
  11. package/dist/options/config/globalConfig.d.ts +1 -1
  12. package/dist/options/config/globalConfig.js +12 -6
  13. package/dist/options/config/globalConfig.test.js +8 -2
  14. package/dist/options/config/projectConfig.d.ts +3 -1
  15. package/dist/options/config/projectConfig.js +5 -2
  16. package/dist/options/config/projectConfig.test.js +35 -6
  17. package/dist/options/config/readConfigFile.d.ts +25 -23
  18. package/dist/options/options.d.ts +14 -12
  19. package/dist/options/options.js +4 -4
  20. package/dist/options/options.test.js +35 -33
  21. package/dist/runSequentially.test.js +2 -6
  22. package/dist/scripts/postinstall.js +3 -3
  23. package/dist/services/env.d.ts +3 -1
  24. package/dist/services/env.js +4 -1
  25. package/dist/services/github/v3/createPullRequest.js +8 -5
  26. package/dist/services/github/v3/createPullRequest.test.js +57 -7
  27. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  28. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -1
  29. package/dist/services/logger.d.ts +4 -1
  30. package/dist/services/logger.js +28 -29
  31. package/dist/test/backport-e2e.private.test.js +2 -4
  32. package/dist/test/inquirer.private.test.js +3 -1
  33. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +3 -8
  34. package/package.json +9 -9
  35. package/yarn.lock +109 -153
package/README.md CHANGED
@@ -76,6 +76,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
76
76
  | --auto-assign | | Assign current user to the target PR | false |
77
77
  | --branch | -b | Target branch to backport to | |
78
78
  | --ci | | Disable interactive prompts | false |
79
+ | --config-file | | Custom path to project config file (.backportrc.json) | |
79
80
  | --dir | | Clone repository into custom directory | ~/.backport/repositories/ |
80
81
  | --dry-run | | Perform backport without pushing to Github | false |
81
82
  | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
@@ -90,7 +91,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
90
91
  | --no-status-comment | | Do not publish a status comment to Github with the results of the backport | false |
91
92
  | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
92
93
  | --path | -p | Filter commits by path | |
93
- | --pr-description | --description | Pull request description suffix | |
94
+ | --pr-description | --description | Description for pull request | |
94
95
  | --pr-filter | | Find PRs using [Github's search syntax][2] | |
95
96
  | --pr-title | --title | Title of pull request | |
96
97
  | --pull-number | --pr | Backport pull request by number | |
@@ -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,11 +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
6
  export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
7
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
8
- export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
8
+ export declare function backportRun(options: ConfigFileOptions, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
9
9
  export declare function getCommits(options: {
10
10
  accessToken: string;
11
11
  repoName: string;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCommits = exports.backportRun = exports.getLocalGlobalConfig = exports.getRemoteProjectConfig = void 0;
4
- const main_1 = require("./main");
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
10
  const excludeUndefined_1 = require("./utils/excludeUndefined");
11
- (0, logger_1.initLogger)();
12
11
  var fetchRemoteProjectConfig_1 = require("./services/github/v4/fetchRemoteProjectConfig");
13
12
  Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
14
13
  var globalConfig_1 = require("./options/config/globalConfig");
@@ -21,11 +20,12 @@ function backportRun(options,
21
20
  // const args = process.argv.slice(2);
22
21
  // backportRun(options, args)
23
22
  //
24
- args = []) {
25
- return (0, main_1.main)(args, (0, excludeUndefined_1.excludeUndefined)(options));
23
+ processArgs = []) {
24
+ return (0, backportRun_1.backportRun)(processArgs, (0, excludeUndefined_1.excludeUndefined)(options));
26
25
  }
27
26
  exports.backportRun = backportRun;
28
27
  async function getCommits(options) {
28
+ (0, logger_1.initLogger)({ ci: true });
29
29
  const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
30
30
  if (options.pullNumber) {
31
31
  return [
@@ -22,13 +22,15 @@ declare type Options = Partial<{
22
22
  cherrypickRef: boolean;
23
23
  ci: boolean;
24
24
  commitPaths: string[];
25
- dir: string;
25
+ configFile: string;
26
26
  details: boolean;
27
+ dir: string;
27
28
  editor: string;
28
29
  fork: boolean;
29
30
  gitHostname: string;
30
31
  githubApiBaseUrlV3: string;
31
32
  githubApiBaseUrlV4: string;
33
+ logFilePath: string;
32
34
  maxNumber: number;
33
35
  multiple: boolean;
34
36
  multipleBranches: boolean;
@@ -1,45 +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
6
  dir?: string | undefined;
7
7
  verbose?: boolean | undefined;
8
- ci?: boolean | undefined;
9
8
  accessToken?: string | undefined;
10
- assignees?: string[] | undefined;
11
9
  author?: string | null | undefined;
12
10
  autoAssign?: boolean | undefined;
11
+ assignees?: string[] | undefined;
13
12
  autoMerge?: boolean | undefined;
14
13
  autoMergeMethod?: string | undefined;
14
+ ci?: boolean | undefined;
15
15
  cherrypickRef?: boolean | undefined;
16
- commitPaths?: string[] | undefined;
16
+ configFile?: string | undefined;
17
17
  details?: boolean | undefined;
18
18
  editor?: string | undefined;
19
+ skipRemoteConfig?: boolean | undefined;
19
20
  gitHostname?: string | undefined;
20
21
  githubApiBaseUrlV3?: string | undefined;
21
22
  githubApiBaseUrlV4?: string | undefined;
23
+ logFilePath?: string | undefined;
24
+ mainline?: number | undefined;
22
25
  maxNumber?: number | undefined;
23
26
  multipleBranches?: boolean | undefined;
24
27
  multipleCommits?: boolean | undefined;
25
28
  noVerify?: boolean | undefined;
26
29
  prDescription?: string | undefined;
27
- prFilter?: string | undefined;
28
30
  prTitle?: string | undefined;
29
- publishStatusComment?: boolean | undefined;
31
+ prFilter?: string | undefined;
30
32
  pullNumber?: number | undefined;
31
- repoName?: string | undefined;
32
- repoOwner?: string | undefined;
33
- resetAuthor?: boolean | undefined;
34
- reviewers?: string[] | undefined;
35
33
  sha?: string | undefined;
36
- skipRemoteConfig?: boolean | undefined;
34
+ resetAuthor?: boolean | undefined;
35
+ repoOwner?: string | undefined;
36
+ repoName?: string | undefined;
37
37
  sourceBranch?: string | undefined;
38
+ dateSince?: string | undefined;
39
+ dateUntil?: string | undefined;
40
+ commitPaths?: string[] | undefined;
41
+ reviewers?: string[] | undefined;
38
42
  sourcePRLabels?: string[] | undefined;
39
43
  targetBranchChoices?: string[] | undefined;
40
44
  targetBranches?: string[] | undefined;
41
45
  targetPRLabels?: string[] | undefined;
42
- mainline?: number | undefined;
43
- dateSince?: string | undefined;
44
- dateUntil?: string | undefined;
46
+ publishStatusComment?: boolean | undefined;
45
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,10 @@ 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',
59
63
  })
60
64
  .option('since', {
61
65
  description: 'ISO-8601 date for filtering commits',
@@ -101,6 +105,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
101
105
  hidden: true,
102
106
  description: `Base url for Github's GraphQL (v4) API`,
103
107
  type: 'string',
108
+ })
109
+ .option('logFilePath', {
110
+ hidden: true,
111
+ description: `Path to log file`,
112
+ type: 'string',
104
113
  })
105
114
  .option('mainline', {
106
115
  description: 'Parent id of merge commit. Defaults to 1 when supplied without arguments',
@@ -109,7 +118,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
109
118
  if (mainline === undefined) {
110
119
  // return 1 if `--mainline` is given without a value
111
120
  // return undefined if --mainline is not supplied at all
112
- return argv.includes('--mainline') ? 1 : undefined;
121
+ return processArgs.includes('--mainline') ? 1 : undefined;
113
122
  }
114
123
  // use specified mainline parent
115
124
  if (Number.isInteger(mainline)) {
@@ -1,8 +1,10 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
+ import { OptionsFromCliArgs } from '../cliArgs';
2
3
  export declare type OptionsFromConfigFiles = Awaited<ReturnType<typeof getOptionsFromConfigFiles>>;
3
- export declare function getOptionsFromConfigFiles({ optionsFromModule, ci, }: {
4
- optionsFromModule?: ConfigFileOptions;
5
- ci: boolean;
4
+ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsFromModule, defaultConfigOptions, }: {
5
+ optionsFromCliArgs: OptionsFromCliArgs;
6
+ optionsFromModule: ConfigFileOptions;
7
+ defaultConfigOptions: ConfigFileOptions;
6
8
  }): Promise<{
7
9
  accessToken?: string | undefined;
8
10
  assignees?: string[] | undefined;
@@ -26,13 +28,15 @@ export declare function getOptionsFromConfigFiles({ optionsFromModule, ci, }: {
26
28
  cherrypickRef?: boolean | undefined;
27
29
  ci?: boolean | undefined;
28
30
  commitPaths?: string[] | undefined;
29
- dir?: string | undefined;
31
+ configFile?: string | undefined;
30
32
  details?: boolean | undefined;
33
+ dir?: string | undefined;
31
34
  editor?: string | undefined;
32
35
  fork?: boolean | undefined;
33
36
  gitHostname?: string | undefined;
34
37
  githubApiBaseUrlV3?: string | undefined;
35
38
  githubApiBaseUrlV4?: string | undefined;
39
+ logFilePath?: string | undefined;
36
40
  maxNumber?: number | undefined;
37
41
  multiple?: boolean | undefined;
38
42
  multipleBranches?: boolean | undefined;
@@ -4,10 +4,16 @@ exports.getOptionsFromConfigFiles = void 0;
4
4
  const getOptionsFromGit_1 = require("./getOptionsFromGit");
5
5
  const globalConfig_1 = require("./globalConfig");
6
6
  const projectConfig_1 = require("./projectConfig");
7
- async function getOptionsFromConfigFiles({ optionsFromModule, ci, }) {
7
+ async function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsFromModule, defaultConfigOptions, }) {
8
+ // ci: cli and module only flag
9
+ const ci = optionsFromCliArgs.ci ?? optionsFromModule.ci ?? defaultConfigOptions.ci;
10
+ // ci: cli and module only flag
11
+ const configFile = optionsFromCliArgs.configFile ??
12
+ optionsFromModule.configFile ??
13
+ defaultConfigOptions.configFile;
8
14
  const [gitConfig, projectConfig, globalConfig] = await Promise.all([
9
15
  (0, getOptionsFromGit_1.getOptionsFromGit)(),
10
- (0, projectConfig_1.getProjectConfig)(),
16
+ (0, projectConfig_1.getProjectConfig)({ configFile }),
11
17
  ci ? undefined : (0, globalConfig_1.getGlobalConfig)(),
12
18
  ]);
13
19
  return {
@@ -1,15 +1,41 @@
1
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ const fs = __importStar(require("../../services/fs-promisified"));
3
23
  const mockConfigFiles_1 = require("../../test/mockConfigFiles");
4
24
  const config_1 = require("./config");
5
25
  describe('getOptionsFromConfigFiles', () => {
6
26
  let res;
7
27
  beforeEach(async () => {
28
+ jest.spyOn(fs, 'writeFile').mockResolvedValueOnce(undefined);
29
+ jest.spyOn(fs, 'chmod').mockResolvedValue();
8
30
  (0, mockConfigFiles_1.mockConfigFiles)({
9
31
  globalConfig: { accessToken: 'abc', editor: 'vim' },
10
32
  projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
11
33
  });
12
- res = await (0, config_1.getOptionsFromConfigFiles)({ ci: false });
34
+ res = await (0, config_1.getOptionsFromConfigFiles)({
35
+ optionsFromCliArgs: {},
36
+ optionsFromModule: {},
37
+ defaultConfigOptions: { ci: false },
38
+ });
13
39
  });
14
40
  it('should return values from config files', () => {
15
41
  expect(res).toEqual({
@@ -1,4 +1,4 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
2
  export declare function getGlobalConfig(): Promise<ConfigFileOptions>;
3
- export declare function createGlobalConfigAndFolderIfNotExist(): Promise<boolean>;
3
+ export declare function createGlobalConfigAndFolderIfNotExist(globalConfigPath: string): Promise<boolean>;
4
4
  export declare function createGlobalConfigIfNotExist(globalConfigPath: string, configTemplate: string): Promise<boolean>;
@@ -5,19 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createGlobalConfigIfNotExist = exports.createGlobalConfigAndFolderIfNotExist = exports.getGlobalConfig = void 0;
7
7
  const make_dir_1 = __importDefault(require("make-dir"));
8
+ const HandledError_1 = require("../../services/HandledError");
8
9
  const env_1 = require("../../services/env");
9
10
  const fs_promisified_1 = require("../../services/fs-promisified");
10
11
  const readConfigFile_1 = require("./readConfigFile");
11
12
  async function getGlobalConfig() {
12
- await createGlobalConfigAndFolderIfNotExist();
13
13
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
14
+ await createGlobalConfigAndFolderIfNotExist(globalConfigPath);
14
15
  return (0, readConfigFile_1.readConfigFile)(globalConfigPath);
15
16
  }
16
17
  exports.getGlobalConfig = getGlobalConfig;
17
- async function createGlobalConfigAndFolderIfNotExist() {
18
+ async function createGlobalConfigAndFolderIfNotExist(globalConfigPath) {
18
19
  // create .backport folder
19
20
  await (0, make_dir_1.default)((0, env_1.getBackportDirPath)());
20
- const globalConfigPath = (0, env_1.getGlobalConfigPath)();
21
21
  const configTemplate = getConfigTemplate();
22
22
  const didCreate = await createGlobalConfigIfNotExist(globalConfigPath, configTemplate);
23
23
  await ensureCorrectPermissions(globalConfigPath);
@@ -36,11 +36,17 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
36
36
  return true;
37
37
  }
38
38
  catch (e) {
39
+ // ignore error if file already exists
39
40
  const FILE_ALREADY_EXISTS = 'EEXIST';
40
- if (e.code !== FILE_ALREADY_EXISTS) {
41
- throw e;
41
+ if (e.code === FILE_ALREADY_EXISTS) {
42
+ return false;
43
+ }
44
+ // handle error if folder does not exist
45
+ const FOLDER_NOT_EXISTS = 'ENOENT';
46
+ if (e.code === FOLDER_NOT_EXISTS) {
47
+ throw new HandledError_1.HandledError(`The .backport folder (${globalConfigPath}) does not exist. `);
42
48
  }
43
- return false;
49
+ throw e;
44
50
  }
45
51
  }
46
52
  exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
@@ -57,7 +57,7 @@ describe('config', () => {
57
57
  });
58
58
  });
59
59
  describe('createGlobalConfigIfNotExist', () => {
60
- it('should create config and succeed', async () => {
60
+ it("should create config if it does't exist", async () => {
61
61
  jest.spyOn(fs, 'writeFile').mockResolvedValueOnce(undefined);
62
62
  const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/globalConfig', 'myConfigTemplate');
63
63
  expect(didCreate).toEqual(true);
@@ -67,8 +67,14 @@ describe('config', () => {
67
67
  const err = new Error();
68
68
  err.code = 'EEXIST';
69
69
  jest.spyOn(fs, 'writeFile').mockRejectedValueOnce(err);
70
- const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('myPath', 'myConfigTemplate');
70
+ const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/global/config.json', 'myConfigTemplate');
71
71
  expect(didCreate).toEqual(false);
72
72
  });
73
+ it("should fail gracefully if .backport folder doesn't exist", async () => {
74
+ const err = new Error();
75
+ err.code = 'ENOENT';
76
+ jest.spyOn(fs, 'writeFile').mockRejectedValueOnce(err);
77
+ await expect(() => (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/global/config.json', 'myConfigTemplate')).rejects.toThrowError('The .backport folder (/path/to/global/config.json) does not exist.');
78
+ });
73
79
  });
74
80
  });
@@ -1,2 +1,4 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
- export declare function getProjectConfig(): Promise<ConfigFileOptions | undefined>;
2
+ export declare function getProjectConfig({ configFile, }: {
3
+ configFile: string | undefined;
4
+ }): Promise<ConfigFileOptions | undefined>;
@@ -4,10 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getProjectConfig = void 0;
7
+ const posix_1 = __importDefault(require("path/posix"));
7
8
  const find_up_1 = __importDefault(require("find-up"));
8
9
  const readConfigFile_1 = require("../config/readConfigFile");
9
- async function getProjectConfig() {
10
- const filepath = await (0, find_up_1.default)('.backportrc.json');
10
+ async function getProjectConfig({ configFile, }) {
11
+ const filepath = configFile
12
+ ? posix_1.default.resolve(configFile)
13
+ : await (0, find_up_1.default)('.backportrc.json');
11
14
  if (!filepath) {
12
15
  return;
13
16
  }
@@ -35,7 +35,7 @@ describe('getProjectConfig', () => {
35
35
  repoOwner: 'elastic',
36
36
  branches: ['6.x'],
37
37
  }));
38
- const projectConfig = await (0, projectConfig_1.getProjectConfig)();
38
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
39
39
  expect(projectConfig?.targetBranchChoices).toEqual(['6.x']);
40
40
  });
41
41
  });
@@ -44,7 +44,7 @@ describe('getProjectConfig', () => {
44
44
  jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
45
45
  labels: ['backport'],
46
46
  }));
47
- const projectConfig = await (0, projectConfig_1.getProjectConfig)();
47
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
48
48
  expect(projectConfig?.targetPRLabels).toEqual(['backport']);
49
49
  });
50
50
  });
@@ -53,7 +53,7 @@ describe('getProjectConfig', () => {
53
53
  jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
54
54
  upstream: 'elastic/kibana',
55
55
  }));
56
- const projectConfig = await (0, projectConfig_1.getProjectConfig)();
56
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
57
57
  expect(projectConfig?.repoOwner).toEqual('elastic');
58
58
  expect(projectConfig?.repoName).toEqual('kibana');
59
59
  });
@@ -67,7 +67,7 @@ describe('getProjectConfig', () => {
67
67
  targetBranchChoices: ['6.x'],
68
68
  targetPRLabels: ['backport'],
69
69
  }));
70
- projectConfig = await (0, projectConfig_1.getProjectConfig)();
70
+ projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
71
71
  });
72
72
  it('should call findUp', () => {
73
73
  expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
@@ -81,18 +81,47 @@ describe('getProjectConfig', () => {
81
81
  });
82
82
  });
83
83
  });
84
+ describe('when specifying a path to project config', () => {
85
+ let projectConfig;
86
+ let spy;
87
+ beforeEach(async () => {
88
+ spy = jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
89
+ repoName: 'kibana',
90
+ repoOwner: 'elastic',
91
+ targetBranchChoices: ['6.x'],
92
+ targetPRLabels: ['backport'],
93
+ }));
94
+ projectConfig = await (0, projectConfig_1.getProjectConfig)({
95
+ configFile: '/custom/path/to/project/.backportrc.json',
96
+ });
97
+ });
98
+ it('should not call findUp', () => {
99
+ expect(find_up_1.default).not.toHaveBeenCalled();
100
+ });
101
+ it('should retrieve config via custom config path', () => {
102
+ expect(spy).toHaveBeenCalledWith('/custom/path/to/project/.backportrc.json', 'utf8');
103
+ });
104
+ it('should return config', () => {
105
+ expect(projectConfig).toEqual({
106
+ repoName: 'kibana',
107
+ repoOwner: 'elastic',
108
+ targetBranchChoices: ['6.x'],
109
+ targetPRLabels: ['backport'],
110
+ });
111
+ });
112
+ });
84
113
  });
85
114
  describe('when projectConfig is empty', () => {
86
115
  it('should return empty config', async () => {
87
116
  jest.spyOn(fs, 'readFile').mockResolvedValueOnce('{}');
88
- const projectConfig = await (0, projectConfig_1.getProjectConfig)();
117
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
89
118
  expect(projectConfig).toEqual({});
90
119
  });
91
120
  });
92
121
  describe('when projectConfig is missing', () => {
93
122
  it('should return empty config', async () => {
94
123
  find_up_1.default.mockReturnValueOnce(undefined);
95
- const projectConfig = await (0, projectConfig_1.getProjectConfig)();
124
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
96
125
  expect(projectConfig).toEqual(undefined);
97
126
  });
98
127
  });
@@ -4,53 +4,55 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
4
4
  fork?: boolean | undefined;
5
5
  dir?: string | undefined;
6
6
  verbose?: boolean | undefined;
7
- ci?: boolean | undefined;
8
7
  accessToken?: string | undefined;
9
- assignees?: string[] | undefined;
10
8
  author?: string | null | undefined;
11
9
  autoAssign?: boolean | undefined;
12
- autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
13
- files: string[];
14
- directory: string;
15
- logger: {
16
- error: (message: string, meta?: unknown) => void;
17
- warn: (message: string, meta?: unknown) => void;
18
- info: (message: string, meta?: unknown) => void;
19
- verbose: (message: string, meta?: unknown) => void;
20
- debug: (message: string, meta?: unknown) => void;
21
- };
22
- targetBranch: string;
23
- }) => boolean | Promise<boolean>) | undefined;
10
+ assignees?: string[] | undefined;
24
11
  autoMerge?: boolean | undefined;
25
12
  autoMergeMethod?: string | undefined;
26
- backportBinary?: string | undefined;
13
+ ci?: boolean | undefined;
27
14
  cherrypickRef?: boolean | undefined;
28
- commitPaths?: string[] | undefined;
15
+ configFile?: string | undefined;
29
16
  details?: boolean | undefined;
30
17
  editor?: string | undefined;
18
+ skipRemoteConfig?: boolean | undefined;
31
19
  gitHostname?: string | undefined;
32
20
  githubApiBaseUrlV3?: string | undefined;
33
21
  githubApiBaseUrlV4?: string | undefined;
22
+ logFilePath?: string | undefined;
34
23
  maxNumber?: number | undefined;
35
24
  multiple?: boolean | undefined;
36
25
  multipleBranches?: boolean | undefined;
37
26
  multipleCommits?: boolean | undefined;
38
27
  noVerify?: boolean | undefined;
39
28
  prDescription?: string | undefined;
40
- prFilter?: string | undefined;
41
29
  prTitle?: string | undefined;
42
- publishStatusComment?: boolean | undefined;
30
+ prFilter?: string | undefined;
43
31
  pullNumber?: number | undefined;
44
- repoName?: string | undefined;
45
- repoOwner?: string | undefined;
46
- resetAuthor?: boolean | undefined;
47
- reviewers?: string[] | undefined;
48
32
  sha?: string | undefined;
49
- skipRemoteConfig?: boolean | undefined;
33
+ resetAuthor?: boolean | undefined;
34
+ repoOwner?: string | undefined;
35
+ repoName?: string | undefined;
50
36
  sourceBranch?: string | undefined;
37
+ commitPaths?: string[] | undefined;
38
+ reviewers?: string[] | undefined;
51
39
  sourcePRLabels?: string[] | undefined;
52
40
  targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
53
41
  targetBranches?: string[] | undefined;
54
42
  targetPRLabels?: string[] | undefined;
43
+ publishStatusComment?: boolean | undefined;
44
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
45
+ files: string[];
46
+ directory: string;
47
+ logger: {
48
+ error: (message: string, meta?: unknown) => void;
49
+ warn: (message: string, meta?: unknown) => void;
50
+ info: (message: string, meta?: unknown) => void;
51
+ verbose: (message: string, meta?: unknown) => void;
52
+ debug: (message: string, meta?: unknown) => void;
53
+ };
54
+ targetBranch: string;
55
+ }) => boolean | Promise<boolean>) | undefined;
56
+ backportBinary?: string | undefined;
55
57
  branchLabelMapping?: Record<string, string> | undefined;
56
58
  };
@@ -26,47 +26,49 @@ export declare const defaultConfigOptions: {
26
26
  targetPRLabels: string[];
27
27
  verbose: boolean;
28
28
  };
29
- export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
29
+ export declare function getOptions(processArgs: string[], optionsFromModule: ConfigFileOptions): Promise<{
30
30
  accessToken: string;
31
31
  repoName: string;
32
32
  repoOwner: string;
33
33
  fork: boolean;
34
34
  dir?: string | undefined;
35
35
  verbose: boolean;
36
- ci: boolean;
37
- assignees: string[];
38
36
  author: string | null;
39
37
  autoAssign: boolean;
38
+ assignees: string[];
40
39
  autoMerge: boolean;
41
40
  autoMergeMethod: string;
41
+ ci: boolean;
42
42
  cherrypickRef: boolean;
43
- commitPaths: string[];
43
+ configFile?: string | undefined;
44
44
  details: boolean;
45
45
  editor?: string | undefined;
46
+ skipRemoteConfig?: boolean | undefined;
46
47
  gitHostname?: string | undefined;
47
48
  githubApiBaseUrlV3?: string | undefined;
48
49
  githubApiBaseUrlV4?: string | undefined;
50
+ logFilePath?: string | undefined;
51
+ mainline?: number | undefined;
49
52
  maxNumber: number;
50
53
  multipleBranches: boolean;
51
54
  multipleCommits: boolean;
52
55
  noVerify: boolean;
53
56
  prDescription?: string | undefined;
54
- prFilter?: string | undefined;
55
57
  prTitle?: string | undefined;
56
- publishStatusComment: boolean;
58
+ prFilter?: string | undefined;
57
59
  pullNumber?: number | undefined;
58
- resetAuthor: boolean;
59
- reviewers: string[];
60
60
  sha?: string | undefined;
61
- skipRemoteConfig?: boolean | undefined;
61
+ resetAuthor: boolean;
62
62
  sourceBranch: string;
63
+ dateSince: string | null;
64
+ dateUntil: string | null;
65
+ commitPaths: string[];
66
+ reviewers: string[];
63
67
  sourcePRLabels: string[];
64
68
  targetBranchChoices: string[] | TargetBranchChoiceOrString[];
65
69
  targetBranches: string[];
66
70
  targetPRLabels: string[];
67
- mainline?: number | undefined;
68
- dateSince: string | null;
69
- dateUntil: string | null;
71
+ publishStatusComment: boolean;
70
72
  historicalBranchLabelMappings: {
71
73
  branchLabelMapping: Record<string, string>;
72
74
  committedDate: string;
@@ -36,12 +36,12 @@ exports.defaultConfigOptions = {
36
36
  targetPRLabels: [],
37
37
  verbose: false,
38
38
  };
39
- async function getOptions(argv, optionsFromModule) {
40
- const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
41
- const ci = optionsFromCliArgs.ci ?? optionsFromModule?.ci ?? exports.defaultConfigOptions.ci;
39
+ async function getOptions(processArgs, optionsFromModule) {
40
+ const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(processArgs);
42
41
  const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)({
42
+ optionsFromCliArgs,
43
43
  optionsFromModule,
44
- ci,
44
+ defaultConfigOptions: exports.defaultConfigOptions,
45
45
  });
46
46
  // combined options from cli and config files
47
47
  const combined = getCombinedOptions({