backport 6.3.0-beta → 6.3.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.
- package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.e2e.private.test.js +277 -0
- package/dist/entrypoint.cli.js +0 -0
- package/dist/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +46 -0
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +170 -0
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +371 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +218 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +267 -0
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +518 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +325 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +386 -0
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +82 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +4 -3
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +134 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
- package/dist/test/backport-e2e.mutation.test.js +347 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +32 -0
- package/dist/test/private/getDevAccessToken.d.ts +1 -0
- package/dist/test/private/getDevAccessToken.js +25 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +59 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +198 -0
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +204 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +1 -1
|
@@ -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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,371 @@
|
|
|
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({ refName: 'backport' });
|
|
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', refName, 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
|
+
isFork: false,
|
|
322
|
+
parent: null,
|
|
323
|
+
ref: refName ? { name: refName } : null,
|
|
324
|
+
defaultBranchRef: {
|
|
325
|
+
name: defaultBranchRef,
|
|
326
|
+
target: {
|
|
327
|
+
history: {
|
|
328
|
+
edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
|
|
329
|
+
return {
|
|
330
|
+
remoteConfig: {
|
|
331
|
+
committedDate,
|
|
332
|
+
file: {
|
|
333
|
+
object: {
|
|
334
|
+
text: JSON.stringify({
|
|
335
|
+
branchLabelMapping,
|
|
336
|
+
}),
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}),
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
|
|
351
|
+
return (0, nockHelpers_1.mockGqlRequest)({
|
|
352
|
+
name: 'RepoOwnerAndName',
|
|
353
|
+
statusCode: 200,
|
|
354
|
+
body: {
|
|
355
|
+
data: {
|
|
356
|
+
repository: {
|
|
357
|
+
isFork: true,
|
|
358
|
+
name: repoName,
|
|
359
|
+
owner: {
|
|
360
|
+
login: childRepoOwner,
|
|
361
|
+
},
|
|
362
|
+
parent: {
|
|
363
|
+
owner: {
|
|
364
|
+
login: parentRepoOwner,
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|