backport 6.3.0-beta → 6.3.0-beta-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 (118) hide show
  1. package/dist/backportRun.js +3 -2
  2. package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
  3. package/dist/entrypoint.cli.e2e.private.test.js +278 -0
  4. package/dist/entrypoint.cli.js +0 -0
  5. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  6. package/dist/entrypoint.cli.private.test.js +46 -0
  7. package/dist/options/ConfigOptions.d.ts +3 -2
  8. package/dist/options/cliArgs.d.ts +1 -0
  9. package/dist/options/cliArgs.js +24 -4
  10. package/dist/options/cliArgs.test.d.ts +1 -0
  11. package/dist/options/cliArgs.test.js +170 -0
  12. package/dist/options/config/config.d.ts +2 -7
  13. package/dist/options/config/config.test.d.ts +1 -0
  14. package/dist/options/config/config.test.js +32 -0
  15. package/dist/options/config/globalConfig.test.d.ts +1 -0
  16. package/dist/options/config/globalConfig.test.js +61 -0
  17. package/dist/options/config/projectConfig.test.d.ts +1 -0
  18. package/dist/options/config/projectConfig.test.js +109 -0
  19. package/dist/options/config/readConfigFile.d.ts +2 -7
  20. package/dist/options/options.d.ts +2 -7
  21. package/dist/options/options.test.d.ts +1 -0
  22. package/dist/options/options.test.js +369 -0
  23. package/dist/runSequentially.js +1 -0
  24. package/dist/runSequentially.test.d.ts +1 -0
  25. package/dist/runSequentially.test.js +218 -0
  26. package/dist/scripts/postinstall.test.d.ts +1 -0
  27. package/dist/scripts/postinstall.test.js +53 -0
  28. package/dist/services/env.test.d.ts +1 -0
  29. package/dist/services/env.test.js +21 -0
  30. package/dist/services/git.integration.test.d.ts +1 -0
  31. package/dist/services/git.integration.test.js +267 -0
  32. package/dist/services/git.test.d.ts +1 -0
  33. package/dist/services/git.test.js +518 -0
  34. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  35. package/dist/services/github/commitFormatters.test.js +11 -0
  36. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  38. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  39. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  40. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  41. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  42. package/dist/services/github/v3/index.d.ts +1 -0
  43. package/dist/services/github/v3/index.js +61 -0
  44. package/dist/services/github/v4/apiRequestV4.js +10 -2
  45. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  46. package/dist/services/github/v4/apiRequestV4.test.js +82 -0
  47. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  48. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  49. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  51. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
  53. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
  55. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  56. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
  57. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
  59. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  60. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
  61. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  62. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  63. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  64. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  65. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  66. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  67. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -7
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -10
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
  71. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +15 -24
  72. package/dist/services/github/v4/getOptionsFromGithub/query.js +17 -25
  73. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  74. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  75. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  76. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
  77. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  78. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  79. package/dist/services/logger.d.ts +3 -15
  80. package/dist/services/logger.js +10 -50
  81. package/dist/services/prompt.test.d.ts +1 -0
  82. package/dist/services/prompt.test.js +134 -0
  83. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  84. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
  85. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  86. package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
  87. package/dist/test/ExecError.d.ts +16 -0
  88. package/dist/test/ExecError.js +15 -0
  89. package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
  90. package/dist/test/backport-e2e.mutation.test.js +347 -0
  91. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  92. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
  93. package/dist/test/mockConfigFiles.d.ts +5 -0
  94. package/dist/test/mockConfigFiles.js +21 -0
  95. package/dist/test/mocks.d.ts +10 -0
  96. package/dist/test/mocks.js +23 -0
  97. package/dist/test/nockHelpers.d.ts +16 -0
  98. package/dist/test/nockHelpers.js +32 -0
  99. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  100. package/dist/test/private/getDevAccessToken.js +12 -0
  101. package/dist/test/sandbox.d.ts +5 -0
  102. package/dist/test/sandbox.js +43 -0
  103. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  104. package/dist/test/setupFiles/automatic-mocks.js +59 -0
  105. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  106. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -0
  107. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  108. package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
  109. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  110. package/dist/ui/getTargetBranches.test.js +198 -0
  111. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  112. package/dist/ui/maybeSetupRepo.test.js +204 -0
  113. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  114. package/dist/utils/excludeUndefined.test.js +24 -0
  115. package/dist/utils/packageVersion.d.ts +1 -1
  116. package/dist/utils/packageVersion.js +1 -1
  117. package/package.json +5 -3
  118. package/yarn.lock +5 -0
@@ -0,0 +1,32 @@
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
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const mockConfigFiles_1 = require("../../test/mockConfigFiles");
8
+ const config_1 = require("./config");
9
+ describe('getOptionsFromConfigFiles', () => {
10
+ let res;
11
+ beforeEach(async () => {
12
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce(undefined);
13
+ jest.spyOn(promises_1.default, 'chmod').mockResolvedValue();
14
+ (0, mockConfigFiles_1.mockConfigFiles)({
15
+ globalConfig: { accessToken: 'abc', editor: 'vim' },
16
+ projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
17
+ });
18
+ res = await (0, config_1.getOptionsFromConfigFiles)({
19
+ optionsFromCliArgs: {},
20
+ optionsFromModule: {},
21
+ defaultConfigOptions: { ci: false },
22
+ });
23
+ });
24
+ it('should return values from config files', () => {
25
+ expect(res).toEqual({
26
+ accessToken: 'abc',
27
+ editor: 'vim',
28
+ repoName: 'kibana',
29
+ repoOwner: 'elastic',
30
+ });
31
+ });
32
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
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
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const os_1 = __importDefault(require("os"));
8
+ const make_dir_1 = __importDefault(require("make-dir"));
9
+ const globalConfig_1 = require("./globalConfig");
10
+ describe('config', () => {
11
+ afterEach(() => jest.clearAllMocks());
12
+ beforeEach(() => {
13
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
14
+ });
15
+ describe('getGlobalConfig', () => {
16
+ let res;
17
+ beforeEach(async () => {
18
+ jest.spyOn(promises_1.default, 'chmod').mockResolvedValueOnce();
19
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce();
20
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
21
+ accessToken: 'myAccessToken',
22
+ }));
23
+ res = await (0, globalConfig_1.getGlobalConfig)();
24
+ });
25
+ it("should create config if it doesn't exist", () => {
26
+ expect(promises_1.default.writeFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', expect.any(String), { flag: 'wx', mode: 384 });
27
+ });
28
+ it("should create .backport folder if it doesn't exist", () => {
29
+ expect(make_dir_1.default).toHaveBeenCalledWith('/myHomeDir/.backport');
30
+ });
31
+ it('should load config', () => {
32
+ expect(promises_1.default.readFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', 'utf8');
33
+ });
34
+ it('should return config', () => {
35
+ expect(res).toEqual({
36
+ accessToken: 'myAccessToken',
37
+ });
38
+ });
39
+ });
40
+ describe('createGlobalConfigIfNotExist', () => {
41
+ it("should create config if it does't exist", async () => {
42
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce(undefined);
43
+ const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/globalConfig', 'myConfigTemplate');
44
+ expect(didCreate).toEqual(true);
45
+ expect(promises_1.default.writeFile).toHaveBeenCalledWith('/path/to/globalConfig', expect.stringContaining('myConfigTemplate'), { flag: 'wx', mode: 384 });
46
+ });
47
+ it('should not fail if config already exists', async () => {
48
+ const err = new Error();
49
+ err.code = 'EEXIST';
50
+ jest.spyOn(promises_1.default, 'writeFile').mockRejectedValueOnce(err);
51
+ const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/global/config.json', 'myConfigTemplate');
52
+ expect(didCreate).toEqual(false);
53
+ });
54
+ it("should fail gracefully if .backport folder doesn't exist", async () => {
55
+ const err = new Error();
56
+ err.code = 'ENOENT';
57
+ jest.spyOn(promises_1.default, 'writeFile').mockRejectedValueOnce(err);
58
+ 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.');
59
+ });
60
+ });
61
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
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
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const find_up_1 = __importDefault(require("find-up"));
8
+ const projectConfig_1 = require("./projectConfig");
9
+ describe('getProjectConfig', () => {
10
+ afterEach(() => jest.clearAllMocks());
11
+ describe('deprecations', () => {
12
+ describe('when specifying deprecated `branches`', () => {
13
+ it('is returned as `targetBranchChoices`', async () => {
14
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
15
+ repoName: 'kibana',
16
+ repoOwner: 'elastic',
17
+ branches: ['6.x'],
18
+ }));
19
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
20
+ expect(projectConfig?.targetBranchChoices).toEqual(['6.x']);
21
+ });
22
+ });
23
+ describe('when specifying deprecated `labels`', () => {
24
+ it('is returned as `targetPRLabels`', async () => {
25
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
26
+ labels: ['backport'],
27
+ }));
28
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
29
+ expect(projectConfig?.targetPRLabels).toEqual(['backport']);
30
+ });
31
+ });
32
+ describe('when specifying deprecated `upstream`', () => {
33
+ it('is split into `repoOwner` and `repoName`', async () => {
34
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
35
+ upstream: 'elastic/kibana',
36
+ }));
37
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
38
+ expect(projectConfig?.repoOwner).toEqual('elastic');
39
+ expect(projectConfig?.repoName).toEqual('kibana');
40
+ });
41
+ });
42
+ describe('when projectConfig is valid', () => {
43
+ let projectConfig;
44
+ beforeEach(async () => {
45
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
46
+ repoName: 'kibana',
47
+ repoOwner: 'elastic',
48
+ targetBranchChoices: ['6.x'],
49
+ targetPRLabels: ['backport'],
50
+ }));
51
+ projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
52
+ });
53
+ it('should call findUp', () => {
54
+ expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
55
+ });
56
+ it('should return config', () => {
57
+ expect(projectConfig).toEqual({
58
+ repoName: 'kibana',
59
+ repoOwner: 'elastic',
60
+ targetBranchChoices: ['6.x'],
61
+ targetPRLabels: ['backport'],
62
+ });
63
+ });
64
+ });
65
+ describe('when specifying a path to project config', () => {
66
+ let projectConfig;
67
+ let spy;
68
+ beforeEach(async () => {
69
+ spy = jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
70
+ repoName: 'kibana',
71
+ repoOwner: 'elastic',
72
+ targetBranchChoices: ['6.x'],
73
+ targetPRLabels: ['backport'],
74
+ }));
75
+ projectConfig = await (0, projectConfig_1.getProjectConfig)({
76
+ configFile: '/custom/path/to/project/.backportrc.json',
77
+ });
78
+ });
79
+ it('should not call findUp', () => {
80
+ expect(find_up_1.default).not.toHaveBeenCalled();
81
+ });
82
+ it('should retrieve config via custom config path', () => {
83
+ expect(spy).toHaveBeenCalledWith('/custom/path/to/project/.backportrc.json', 'utf8');
84
+ });
85
+ it('should return config', () => {
86
+ expect(projectConfig).toEqual({
87
+ repoName: 'kibana',
88
+ repoOwner: 'elastic',
89
+ targetBranchChoices: ['6.x'],
90
+ targetPRLabels: ['backport'],
91
+ });
92
+ });
93
+ });
94
+ });
95
+ describe('when projectConfig is empty', () => {
96
+ it('should return empty config', async () => {
97
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce('{}');
98
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
99
+ expect(projectConfig).toEqual({});
100
+ });
101
+ });
102
+ describe('when projectConfig is missing', () => {
103
+ it('should return empty config', async () => {
104
+ find_up_1.default.mockReturnValueOnce(undefined);
105
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
106
+ expect(projectConfig).toEqual(undefined);
107
+ });
108
+ });
109
+ });
@@ -35,6 +35,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
35
35
  repoOwner?: string | undefined;
36
36
  repoName?: string | undefined;
37
37
  sourceBranch?: string | undefined;
38
+ username?: string | undefined;
38
39
  version?: boolean | undefined;
39
40
  commitPaths?: string[] | undefined;
40
41
  reviewers?: string[] | undefined;
@@ -46,13 +47,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
46
47
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
47
48
  files: string[];
48
49
  directory: string;
49
- logger: {
50
- error: (message: string, meta?: unknown) => void;
51
- warn: (message: string, meta?: unknown) => void;
52
- info: (message: string, meta?: unknown) => void;
53
- verbose: (message: string, meta?: unknown) => void;
54
- debug: (message: string, meta?: unknown) => void;
55
- };
50
+ logger: import("winston").Logger;
56
51
  targetBranch: string;
57
52
  }) => boolean | Promise<boolean>) | undefined;
58
53
  backportBinary?: string | undefined;
@@ -34,6 +34,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
34
34
  sha?: string | undefined;
35
35
  resetAuthor: boolean;
36
36
  sourceBranch: string;
37
+ username?: string | undefined;
37
38
  dateSince: string | null;
38
39
  dateUntil: string | null;
39
40
  commitPaths: string[];
@@ -50,13 +51,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
50
51
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
51
52
  files: string[];
52
53
  directory: string;
53
- logger: {
54
- error: (message: string, meta?: unknown) => void;
55
- warn: (message: string, meta?: unknown) => void;
56
- info: (message: string, meta?: unknown) => void;
57
- verbose: (message: string, meta?: unknown) => void;
58
- debug: (message: string, meta?: unknown) => void;
59
- };
54
+ logger: import("winston").Logger;
60
55
  targetBranch: string;
61
56
  }) => boolean | Promise<boolean>) | undefined;
62
57
  backportBinary: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const promises_1 = __importDefault(require("fs/promises"));
26
+ const os_1 = __importDefault(require("os"));
27
+ const nock_1 = __importDefault(require("nock"));
28
+ const git = __importStar(require("../services/git"));
29
+ const logger = __importStar(require("../services/logger"));
30
+ const mockConfigFiles_1 = require("../test/mockConfigFiles");
31
+ const nockHelpers_1 = require("../test/nockHelpers");
32
+ const options_1 = require("./options");
33
+ const defaultConfigs = {
34
+ projectConfig: {
35
+ // use localhost to avoid CORS issues with nock
36
+ githubApiBaseUrlV4: 'http://localhost/graphql',
37
+ repoOwner: 'elastic',
38
+ repoName: 'kibana',
39
+ targetBranchChoices: ['7.9', '8.0'],
40
+ },
41
+ globalConfig: { accessToken: 'abc', editor: 'code' },
42
+ };
43
+ describe('getOptions', () => {
44
+ afterEach(() => {
45
+ jest.clearAllMocks();
46
+ nock_1.default.cleanAll();
47
+ });
48
+ beforeEach(() => {
49
+ (0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
50
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
51
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValue();
52
+ jest.spyOn(promises_1.default, 'chmod').mockResolvedValue();
53
+ });
54
+ describe('should throw', () => {
55
+ beforeEach(() => {
56
+ mockGithubConfigOptions({});
57
+ });
58
+ it('when accessToken is missing', async () => {
59
+ (0, mockConfigFiles_1.mockConfigFiles)({
60
+ projectConfig: defaultConfigs.projectConfig,
61
+ globalConfig: { accessToken: undefined },
62
+ });
63
+ await expect(() => (0, options_1.getOptions)([], { ci: true })).rejects
64
+ .toThrowErrorMatchingInlineSnapshot(`
65
+ "Please update your config file: \\"/myHomeDir/.backport/config.json\\".
66
+ It must contain a valid \\"accessToken\\".
67
+
68
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
69
+ `);
70
+ });
71
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
72
+ mockProjectConfig({
73
+ targetBranches: undefined,
74
+ targetBranchChoices: undefined,
75
+ branchLabelMapping: undefined,
76
+ });
77
+ await expect(() => (0, options_1.getOptions)([], {})).rejects
78
+ .toThrowErrorMatchingInlineSnapshot(`
79
+ "Please specify a target branch: \\"--branch 6.1\\".
80
+
81
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
82
+ `);
83
+ });
84
+ describe('when repoName and repoOwner are missing', () => {
85
+ beforeEach(() => {
86
+ mockProjectConfig({ repoName: undefined, repoOwner: undefined });
87
+ });
88
+ it('should throw if there are no remotes', async () => {
89
+ jest.spyOn(git, 'getRepoInfoFromGitRemotes').mockResolvedValue([]);
90
+ await expect(() => (0, options_1.getOptions)([], {})).rejects
91
+ .toThrowErrorMatchingInlineSnapshot(`
92
+ "Please specify a repo name: \\"--repo-name kibana\\".
93
+
94
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
95
+ `);
96
+ });
97
+ it('should get repoName from the remote', async () => {
98
+ mockRepoOwnerAndName({
99
+ childRepoOwner: 'sqren',
100
+ parentRepoOwner: 'elastic',
101
+ repoName: 'kibana',
102
+ });
103
+ jest
104
+ .spyOn(git, 'getRepoInfoFromGitRemotes')
105
+ .mockResolvedValue([{ repoName: 'kibana', repoOwner: 'sqren' }]);
106
+ const options = await (0, options_1.getOptions)([], {});
107
+ expect(options.repoName).toBe('kibana');
108
+ expect(options.repoOwner).toBe('elastic');
109
+ });
110
+ });
111
+ });
112
+ it('should ensure that "backport" branch does not exist', async () => {
113
+ mockGithubConfigOptions({ hasBackportBranch: true });
114
+ await expect((0, options_1.getOptions)([], {})).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
115
+ });
116
+ it('should merge config options and module options', async () => {
117
+ mockGithubConfigOptions({});
118
+ const myFn = async () => true;
119
+ const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
120
+ expect(options.autoFixConflicts).toBe(myFn);
121
+ });
122
+ it('should call updateLogger', async () => {
123
+ mockGithubConfigOptions({});
124
+ await (0, options_1.getOptions)([], {});
125
+ expect(logger.updateLogger).toHaveBeenCalledTimes(1);
126
+ });
127
+ it('should return options', async () => {
128
+ mockGithubConfigOptions({
129
+ viewerLogin: 'john.diller',
130
+ defaultBranchRef: 'default-branch-from-github',
131
+ historicalMappings: [
132
+ {
133
+ committedDate: '2022-01-02T20:52:45.173Z',
134
+ branchLabelMapping: { foo: 'bar' },
135
+ },
136
+ ],
137
+ });
138
+ const options = await (0, options_1.getOptions)([], {});
139
+ expect(options).toEqual({
140
+ accessToken: 'abc',
141
+ assignees: [],
142
+ authenticatedUsername: 'john.diller',
143
+ author: 'john.diller',
144
+ autoAssign: false,
145
+ autoMerge: false,
146
+ autoMergeMethod: 'merge',
147
+ backportBinary: 'backport',
148
+ branchLabelMapping: {
149
+ foo: 'bar',
150
+ },
151
+ cherrypickRef: true,
152
+ ci: false,
153
+ commitPaths: [],
154
+ cwd: expect.any(String),
155
+ dateSince: null,
156
+ dateUntil: null,
157
+ details: false,
158
+ editor: 'code',
159
+ fork: true,
160
+ gitHostname: 'github.com',
161
+ githubApiBaseUrlV4: 'http://localhost/graphql',
162
+ historicalBranchLabelMappings: [
163
+ {
164
+ branchLabelMapping: { foo: 'bar' },
165
+ committedDate: '2022-01-02T20:52:45.173Z',
166
+ },
167
+ ],
168
+ maxNumber: 10,
169
+ multipleBranches: true,
170
+ multipleCommits: false,
171
+ noVerify: true,
172
+ publishStatusComment: true,
173
+ repoName: 'kibana',
174
+ repoOwner: 'elastic',
175
+ resetAuthor: false,
176
+ reviewers: [],
177
+ sourceBranch: 'default-branch-from-github',
178
+ sourcePRLabels: [],
179
+ targetBranchChoices: ['7.9', '8.0'],
180
+ targetBranches: [],
181
+ targetPRLabels: [],
182
+ verbose: false,
183
+ });
184
+ });
185
+ describe('sourceBranch', () => {
186
+ beforeEach(() => {
187
+ mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
188
+ });
189
+ it('uses the `defaultBranchRef` as default', async () => {
190
+ const options = await (0, options_1.getOptions)([], {});
191
+ expect(options.sourceBranch).toBe('some-default-branch');
192
+ });
193
+ it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
194
+ const options = await (0, options_1.getOptions)(['--source-branch', 'cli-source-branch'], {});
195
+ expect(options.sourceBranch).toBe('cli-source-branch');
196
+ });
197
+ });
198
+ describe('fork', () => {
199
+ beforeEach(() => {
200
+ mockGithubConfigOptions({});
201
+ });
202
+ it('is enabled by default', async () => {
203
+ const { fork } = await (0, options_1.getOptions)([], {});
204
+ expect(fork).toBe(true);
205
+ });
206
+ it('can be disabled via `--no-fork` flag', async () => {
207
+ const { fork } = await (0, options_1.getOptions)(['--no-fork'], {});
208
+ expect(fork).toBe(false);
209
+ });
210
+ it('can be disabled via config file', async () => {
211
+ mockProjectConfig({ fork: false });
212
+ const { fork } = await (0, options_1.getOptions)([], {});
213
+ expect(fork).toBe(false);
214
+ });
215
+ });
216
+ describe('reviewers', () => {
217
+ beforeEach(() => {
218
+ mockGithubConfigOptions({});
219
+ });
220
+ it('can be set via `--reviewer` flag', async () => {
221
+ const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter'], {});
222
+ expect(reviewers).toEqual(['peter']);
223
+ });
224
+ it('can be set via config file', async () => {
225
+ mockProjectConfig({ reviewers: ['john'] });
226
+ const { reviewers } = await (0, options_1.getOptions)([], {});
227
+ expect(reviewers).toEqual(['john']);
228
+ });
229
+ });
230
+ describe('mainline', () => {
231
+ beforeEach(() => {
232
+ mockGithubConfigOptions({});
233
+ });
234
+ it('is not enabled by default', async () => {
235
+ const { mainline } = await (0, options_1.getOptions)([], {});
236
+ expect(mainline).toBe(undefined);
237
+ });
238
+ it('can be set via `--mainline` flag', async () => {
239
+ const { mainline } = await (0, options_1.getOptions)(['--mainline'], {});
240
+ expect(mainline).toBe(1);
241
+ });
242
+ it('accepts numeric values', async () => {
243
+ const { mainline } = await (0, options_1.getOptions)(['--mainline', '2'], {});
244
+ expect(mainline).toBe(2);
245
+ });
246
+ });
247
+ describe('author', () => {
248
+ beforeEach(() => {
249
+ mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
250
+ });
251
+ it('defaults to authenticated user', async () => {
252
+ const { author } = await (0, options_1.getOptions)([], {});
253
+ expect(author).toBe('billy.bob');
254
+ });
255
+ it('can be overridden via `--author` flag', async () => {
256
+ const { author } = await (0, options_1.getOptions)(['--author', 'john.doe'], {});
257
+ expect(author).toBe('john.doe');
258
+ });
259
+ it('can be reset via `--all` flag', async () => {
260
+ const { author } = await (0, options_1.getOptions)(['--all'], {});
261
+ expect(author).toBe(null);
262
+ });
263
+ it('can be reset via config file (similar to `--all` flag)', async () => {
264
+ mockProjectConfig({ author: null });
265
+ const { author } = await (0, options_1.getOptions)([], {});
266
+ expect(author).toBe(null);
267
+ });
268
+ it('can be overridden via config file', async () => {
269
+ mockProjectConfig({ author: 'jane.doe' });
270
+ const { author } = await (0, options_1.getOptions)([], {});
271
+ expect(author).toBe('jane.doe');
272
+ });
273
+ });
274
+ describe('cherrypickRef', () => {
275
+ beforeEach(() => {
276
+ mockGithubConfigOptions({});
277
+ });
278
+ it('should default to true', async () => {
279
+ const { cherrypickRef } = await (0, options_1.getOptions)([], {});
280
+ expect(cherrypickRef).toBe(true);
281
+ });
282
+ it('should negate with `noCherrypickRef` cli arg', async () => {
283
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref'], {});
284
+ expect(cherrypickRef).toBe(false);
285
+ });
286
+ it('should be settable via config file', async () => {
287
+ mockProjectConfig({ cherrypickRef: false });
288
+ const { cherrypickRef } = await (0, options_1.getOptions)([], {});
289
+ expect(cherrypickRef).toBe(false);
290
+ });
291
+ it('cli args overwrites config', async () => {
292
+ mockProjectConfig({ cherrypickRef: false });
293
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref'], {});
294
+ expect(cherrypickRef).toBe(true);
295
+ });
296
+ });
297
+ });
298
+ function mockProjectConfig(projectConfig) {
299
+ return (0, mockConfigFiles_1.mockConfigFiles)({
300
+ globalConfig: { accessToken: 'abc' },
301
+ projectConfig: {
302
+ // use localhost to avoid CORS issues with nock
303
+ githubApiBaseUrlV4: 'http://localhost/graphql',
304
+ repoOwner: 'elastic',
305
+ repoName: 'kibana',
306
+ targetBranchChoices: ['7.9', '8.0'],
307
+ ...projectConfig,
308
+ },
309
+ });
310
+ }
311
+ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, historicalMappings = [], }) {
312
+ return (0, nockHelpers_1.mockGqlRequest)({
313
+ name: 'GithubConfigOptions',
314
+ statusCode: 200,
315
+ body: {
316
+ data: {
317
+ viewer: {
318
+ login: viewerLogin,
319
+ },
320
+ repository: {
321
+ illegalBackportBranch: hasBackportBranch ? { id: 'foo' } : null,
322
+ defaultBranchRef: {
323
+ name: defaultBranchRef,
324
+ target: {
325
+ history: {
326
+ edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
327
+ return {
328
+ remoteConfig: {
329
+ committedDate,
330
+ file: {
331
+ object: {
332
+ text: JSON.stringify({
333
+ branchLabelMapping,
334
+ }),
335
+ },
336
+ },
337
+ },
338
+ };
339
+ }),
340
+ },
341
+ },
342
+ },
343
+ },
344
+ },
345
+ },
346
+ });
347
+ }
348
+ function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
349
+ return (0, nockHelpers_1.mockGqlRequest)({
350
+ name: 'RepoOwnerAndName',
351
+ statusCode: 200,
352
+ body: {
353
+ data: {
354
+ repository: {
355
+ isFork: true,
356
+ name: repoName,
357
+ owner: {
358
+ login: childRepoOwner,
359
+ },
360
+ parent: {
361
+ owner: {
362
+ login: parentRepoOwner,
363
+ },
364
+ },
365
+ },
366
+ },
367
+ },
368
+ });
369
+ }
@@ -32,6 +32,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
32
32
  error: e,
33
33
  });
34
34
  (0, logger_1.consoleLog)(e.message);
35
+ logger_1.logger.error('Could not backport commit', e);
35
36
  }
36
37
  });
37
38
  // return the results for consumers to programatically read
@@ -0,0 +1 @@
1
+ export {};