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