backport 7.2.0-beta.1 → 7.2.0-beta.2

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 (129) hide show
  1. package/dist/entrypoint.cli.js +0 -0
  2. package/dist/entrypoint.module.d.ts +4 -3
  3. package/dist/entrypoint.module.js +2 -7
  4. package/dist/options/ConfigOptions.d.ts +1 -1
  5. package/dist/options/cliArgs.d.ts +1 -0
  6. package/dist/options/cliArgs.js +4 -0
  7. package/dist/options/config/config.d.ts +1 -1
  8. package/dist/options/config/readConfigFile.d.ts +1 -1
  9. package/dist/options/options.d.ts +2 -1
  10. package/dist/services/github/v3/createStatusComment.js +1 -1
  11. package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
  12. package/dist/services/github/v4/apiRequestV4.js +15 -14
  13. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
  14. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  15. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  16. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
  17. package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  19. package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
  20. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  21. package/dist/services/remoteConfig.js +2 -2
  22. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  23. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  24. package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
  25. package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
  26. package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
  27. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
  28. package/dist/ui/getCommits.js +6 -4
  29. package/dist/ui/maybeSetupRepo.js +7 -14
  30. package/dist/utils/packageVersion.d.ts +1 -1
  31. package/dist/utils/packageVersion.js +1 -1
  32. package/package.json +9 -9
  33. package/yarn.lock +121 -114
  34. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  35. package/dist/entrypoint.cli.e2e.private.test.js +0 -386
  36. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  37. package/dist/entrypoint.cli.private.test.js +0 -46
  38. package/dist/options/cliArgs.test.d.ts +0 -1
  39. package/dist/options/cliArgs.test.js +0 -182
  40. package/dist/options/config/config.test.d.ts +0 -1
  41. package/dist/options/config/config.test.js +0 -32
  42. package/dist/options/config/globalConfig.test.d.ts +0 -1
  43. package/dist/options/config/globalConfig.test.js +0 -61
  44. package/dist/options/config/projectConfig.test.d.ts +0 -1
  45. package/dist/options/config/projectConfig.test.js +0 -109
  46. package/dist/options/options.test.d.ts +0 -1
  47. package/dist/options/options.test.js +0 -384
  48. package/dist/runSequentially.test.d.ts +0 -1
  49. package/dist/runSequentially.test.js +0 -219
  50. package/dist/scripts/postinstall.test.d.ts +0 -1
  51. package/dist/scripts/postinstall.test.js +0 -53
  52. package/dist/services/env.test.d.ts +0 -1
  53. package/dist/services/env.test.js +0 -21
  54. package/dist/services/git.integration.test.d.ts +0 -1
  55. package/dist/services/git.integration.test.js +0 -320
  56. package/dist/services/git.test.d.ts +0 -1
  57. package/dist/services/git.test.js +0 -532
  58. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  59. package/dist/services/github/commitFormatters.test.js +0 -11
  60. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  61. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  62. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  63. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  64. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  65. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  66. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  67. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  68. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  69. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  70. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  71. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  72. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  73. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  74. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  75. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -134
  76. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  77. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -116
  78. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  79. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -195
  80. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  81. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -152
  82. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  83. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  84. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  85. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  86. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  87. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  88. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  89. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -117
  90. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  91. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  92. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  93. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -159
  94. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  95. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  96. package/dist/services/prompt.test.d.ts +0 -1
  97. package/dist/services/prompt.test.js +0 -134
  98. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  99. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  100. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  101. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -225
  102. package/dist/test/ExecError.d.ts +0 -16
  103. package/dist/test/ExecError.js +0 -15
  104. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  105. package/dist/test/backport-e2e.mutation.test.js +0 -347
  106. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  107. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  108. package/dist/test/mockConfigFiles.d.ts +0 -5
  109. package/dist/test/mockConfigFiles.js +0 -21
  110. package/dist/test/mocks.d.ts +0 -10
  111. package/dist/test/mocks.js +0 -23
  112. package/dist/test/nockHelpers.d.ts +0 -16
  113. package/dist/test/nockHelpers.js +0 -36
  114. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  115. package/dist/test/private/getDevAccessToken.js +0 -12
  116. package/dist/test/sandbox.d.ts +0 -5
  117. package/dist/test/sandbox.js +0 -43
  118. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  119. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  120. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  121. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -459
  122. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  123. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  124. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  125. package/dist/ui/getTargetBranches.test.js +0 -198
  126. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  127. package/dist/ui/maybeSetupRepo.test.js +0 -204
  128. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  129. package/dist/utils/excludeUndefined.test.js +0 -24
@@ -1,61 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,109 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,384 +0,0 @@
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('whe option is an empty string', () => {
85
- it('throws for "username"', async () => {
86
- await expect(() => (0, options_1.getOptions)([], { username: '', author: 'sqren' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"username\\" cannot be empty!"`);
87
- });
88
- it('throws for "author"', async () => {
89
- await expect(() => (0, options_1.getOptions)([], { author: '' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"author\\" cannot be empty!"`);
90
- });
91
- it('throws for "accessToken"', async () => {
92
- await expect(() => (0, options_1.getOptions)([], { accessToken: '' })).rejects
93
- .toThrowErrorMatchingInlineSnapshot(`
94
- "Please update your config file: \\"/myHomeDir/.backport/config.json\\".
95
- It must contain a valid \\"accessToken\\".
96
-
97
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
98
- `);
99
- });
100
- });
101
- describe('when repoName and repoOwner are missing', () => {
102
- beforeEach(() => {
103
- mockProjectConfig({ repoName: undefined, repoOwner: undefined });
104
- });
105
- it('should throw if there are no remotes', async () => {
106
- jest.spyOn(git, 'getRepoInfoFromGitRemotes').mockResolvedValue([]);
107
- await expect(() => (0, options_1.getOptions)([], {})).rejects
108
- .toThrowErrorMatchingInlineSnapshot(`
109
- "Please specify a repo name: \\"--repo-name kibana\\".
110
-
111
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
112
- `);
113
- });
114
- it('should get repoName from the remote', async () => {
115
- mockRepoOwnerAndName({
116
- childRepoOwner: 'sqren',
117
- parentRepoOwner: 'elastic',
118
- repoName: 'kibana',
119
- });
120
- jest
121
- .spyOn(git, 'getRepoInfoFromGitRemotes')
122
- .mockResolvedValue([{ repoName: 'kibana', repoOwner: 'sqren' }]);
123
- const options = await (0, options_1.getOptions)([], {});
124
- expect(options.repoName).toBe('kibana');
125
- expect(options.repoOwner).toBe('elastic');
126
- });
127
- });
128
- });
129
- it('reads options from remote config', async () => {
130
- mockGithubConfigOptions({ hasRemoteConfig: true });
131
- const options = await (0, options_1.getOptions)([], {});
132
- expect(options.branchLabelMapping).toEqual({
133
- '^v8.2.0$': 'option-from-remote',
134
- });
135
- expect(options.autoMergeMethod).toEqual('rebase');
136
- });
137
- it('should ensure that "backport" branch does not exist', async () => {
138
- mockGithubConfigOptions({ hasBackportBranch: true });
139
- 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');
140
- });
141
- it('should merge config options and module options', async () => {
142
- mockGithubConfigOptions({});
143
- const myFn = async () => true;
144
- const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
145
- expect(options.autoFixConflicts).toBe(myFn);
146
- });
147
- it('should call updateLogger', async () => {
148
- mockGithubConfigOptions({});
149
- await (0, options_1.getOptions)([], {});
150
- expect(logger.updateLogger).toHaveBeenCalledTimes(1);
151
- });
152
- it('should return options', async () => {
153
- mockGithubConfigOptions({
154
- viewerLogin: 'john.diller',
155
- defaultBranchRef: 'default-branch-from-github',
156
- });
157
- const options = await (0, options_1.getOptions)([], {});
158
- expect(options).toEqual({
159
- accessToken: 'abc',
160
- assignees: [],
161
- authenticatedUsername: 'john.diller',
162
- author: 'john.diller',
163
- autoAssign: false,
164
- autoMerge: false,
165
- autoMergeMethod: 'merge',
166
- backportBinary: 'backport',
167
- cherrypickRef: true,
168
- ci: false,
169
- commitPaths: [],
170
- cwd: expect.any(String),
171
- dateSince: null,
172
- dateUntil: null,
173
- details: false,
174
- editor: 'code',
175
- fork: true,
176
- gitHostname: 'github.com',
177
- githubApiBaseUrlV4: 'http://localhost/graphql',
178
- maxNumber: 10,
179
- multipleBranches: true,
180
- multipleCommits: false,
181
- noVerify: true,
182
- publishStatusComment: true,
183
- repoName: 'kibana',
184
- repoOwner: 'elastic',
185
- resetAuthor: false,
186
- reviewers: [],
187
- sourceBranch: 'default-branch-from-github',
188
- sourcePRLabels: [],
189
- targetBranchChoices: ['7.9', '8.0'],
190
- targetBranches: [],
191
- targetPRLabels: [],
192
- verbose: false,
193
- });
194
- });
195
- describe('sourceBranch', () => {
196
- beforeEach(() => {
197
- mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
198
- });
199
- it('uses the `defaultBranchRef` as default', async () => {
200
- const options = await (0, options_1.getOptions)([], {});
201
- expect(options.sourceBranch).toBe('some-default-branch');
202
- });
203
- it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
204
- const options = await (0, options_1.getOptions)(['--source-branch', 'cli-source-branch'], {});
205
- expect(options.sourceBranch).toBe('cli-source-branch');
206
- });
207
- });
208
- describe('fork', () => {
209
- beforeEach(() => {
210
- mockGithubConfigOptions({});
211
- });
212
- it('is enabled by default', async () => {
213
- const { fork } = await (0, options_1.getOptions)([], {});
214
- expect(fork).toBe(true);
215
- });
216
- it('can be disabled via `--no-fork` flag', async () => {
217
- const { fork } = await (0, options_1.getOptions)(['--no-fork'], {});
218
- expect(fork).toBe(false);
219
- });
220
- it('can be disabled via config file', async () => {
221
- mockProjectConfig({ fork: false });
222
- const { fork } = await (0, options_1.getOptions)([], {});
223
- expect(fork).toBe(false);
224
- });
225
- });
226
- describe('reviewers', () => {
227
- beforeEach(() => {
228
- mockGithubConfigOptions({});
229
- });
230
- it('can be set via `--reviewer` flag', async () => {
231
- const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter'], {});
232
- expect(reviewers).toEqual(['peter']);
233
- });
234
- it('can be set via config file', async () => {
235
- mockProjectConfig({ reviewers: ['john'] });
236
- const { reviewers } = await (0, options_1.getOptions)([], {});
237
- expect(reviewers).toEqual(['john']);
238
- });
239
- });
240
- describe('mainline', () => {
241
- beforeEach(() => {
242
- mockGithubConfigOptions({});
243
- });
244
- it('is not enabled by default', async () => {
245
- const { mainline } = await (0, options_1.getOptions)([], {});
246
- expect(mainline).toBe(undefined);
247
- });
248
- it('can be set via `--mainline` flag', async () => {
249
- const { mainline } = await (0, options_1.getOptions)(['--mainline'], {});
250
- expect(mainline).toBe(1);
251
- });
252
- it('accepts numeric values', async () => {
253
- const { mainline } = await (0, options_1.getOptions)(['--mainline', '2'], {});
254
- expect(mainline).toBe(2);
255
- });
256
- });
257
- describe('author', () => {
258
- beforeEach(() => {
259
- mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
260
- });
261
- it('defaults to authenticated user', async () => {
262
- const { author } = await (0, options_1.getOptions)([], {});
263
- expect(author).toBe('billy.bob');
264
- });
265
- it('can be overridden via `--author` flag', async () => {
266
- const { author } = await (0, options_1.getOptions)(['--author', 'john.doe'], {});
267
- expect(author).toBe('john.doe');
268
- });
269
- it('can be reset via `--all` flag', async () => {
270
- const { author } = await (0, options_1.getOptions)(['--all'], {});
271
- expect(author).toBe(null);
272
- });
273
- it('can be reset via config file (similar to `--all` flag)', async () => {
274
- mockProjectConfig({ author: null });
275
- const { author } = await (0, options_1.getOptions)([], {});
276
- expect(author).toBe(null);
277
- });
278
- it('can be overridden via config file', async () => {
279
- mockProjectConfig({ author: 'jane.doe' });
280
- const { author } = await (0, options_1.getOptions)([], {});
281
- expect(author).toBe('jane.doe');
282
- });
283
- });
284
- describe('cherrypickRef', () => {
285
- beforeEach(() => {
286
- mockGithubConfigOptions({});
287
- });
288
- it('should default to true', async () => {
289
- const { cherrypickRef } = await (0, options_1.getOptions)([], {});
290
- expect(cherrypickRef).toBe(true);
291
- });
292
- it('should negate with `noCherrypickRef` cli arg', async () => {
293
- const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref'], {});
294
- expect(cherrypickRef).toBe(false);
295
- });
296
- it('should be settable via config file', async () => {
297
- mockProjectConfig({ cherrypickRef: false });
298
- const { cherrypickRef } = await (0, options_1.getOptions)([], {});
299
- expect(cherrypickRef).toBe(false);
300
- });
301
- it('cli args overwrites config', async () => {
302
- mockProjectConfig({ cherrypickRef: false });
303
- const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref'], {});
304
- expect(cherrypickRef).toBe(true);
305
- });
306
- });
307
- });
308
- function mockProjectConfig(projectConfig) {
309
- return (0, mockConfigFiles_1.mockConfigFiles)({
310
- globalConfig: { accessToken: 'abc' },
311
- projectConfig: {
312
- // use localhost to avoid CORS issues with nock
313
- githubApiBaseUrlV4: 'http://localhost/graphql',
314
- repoOwner: 'elastic',
315
- repoName: 'kibana',
316
- targetBranchChoices: ['7.9', '8.0'],
317
- ...projectConfig,
318
- },
319
- });
320
- }
321
- function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, hasRemoteConfig, }) {
322
- return (0, nockHelpers_1.mockGqlRequest)({
323
- name: 'GithubConfigOptions',
324
- statusCode: 200,
325
- body: {
326
- data: {
327
- viewer: {
328
- login: viewerLogin,
329
- },
330
- repository: {
331
- illegalBackportBranch: hasBackportBranch ? { id: 'foo' } : null,
332
- defaultBranchRef: {
333
- name: defaultBranchRef,
334
- target: {
335
- remoteConfigHistory: {
336
- edges: hasRemoteConfig
337
- ? [
338
- {
339
- remoteConfig: {
340
- committedDate: '2020-08-15T00:00:00.000Z',
341
- file: {
342
- object: {
343
- text: JSON.stringify({
344
- autoMergeMethod: 'rebase',
345
- branchLabelMapping: {
346
- '^v8.2.0$': 'option-from-remote',
347
- },
348
- }),
349
- },
350
- },
351
- },
352
- },
353
- ]
354
- : [],
355
- },
356
- },
357
- },
358
- },
359
- },
360
- },
361
- });
362
- }
363
- function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
364
- return (0, nockHelpers_1.mockGqlRequest)({
365
- name: 'RepoOwnerAndName',
366
- statusCode: 200,
367
- body: {
368
- data: {
369
- repository: {
370
- isFork: true,
371
- name: repoName,
372
- owner: {
373
- login: childRepoOwner,
374
- },
375
- parent: {
376
- owner: {
377
- login: parentRepoOwner,
378
- },
379
- },
380
- },
381
- },
382
- },
383
- });
384
- }
@@ -1 +0,0 @@
1
- export {};