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.
- package/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.js +12 -1
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +2 -1
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -6
- package/dist/runSequentially.js +1 -0
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +2 -0
- package/dist/services/git.js +47 -10
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
- package/dist/services/github/v3/createPullRequest.js +2 -5
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
- package/dist/services/github/v4/apiRequestV4.js +22 -21
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
- package/dist/services/github/v4/fetchAuthorId.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
- package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +20 -0
- package/dist/services/remoteConfig.js +52 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
- package/dist/ui/getCommits.js +8 -6
- package/dist/ui/maybeSetupRepo.js +7 -14
- package/dist/ui/ora.d.ts +9 -0
- package/dist/ui/ora.js +21 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +10 -10
- package/yarn.lock +121 -114
- package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
- package/dist/entrypoint.cli.e2e.private.test.js +0 -319
- package/dist/entrypoint.cli.private.test.d.ts +0 -1
- package/dist/entrypoint.cli.private.test.js +0 -46
- package/dist/options/cliArgs.test.d.ts +0 -1
- package/dist/options/cliArgs.test.js +0 -182
- package/dist/options/config/config.test.d.ts +0 -1
- package/dist/options/config/config.test.js +0 -32
- package/dist/options/config/globalConfig.test.d.ts +0 -1
- package/dist/options/config/globalConfig.test.js +0 -61
- package/dist/options/config/projectConfig.test.d.ts +0 -1
- package/dist/options/config/projectConfig.test.js +0 -109
- package/dist/options/options.test.d.ts +0 -1
- package/dist/options/options.test.js +0 -386
- package/dist/runSequentially.test.d.ts +0 -1
- package/dist/runSequentially.test.js +0 -218
- package/dist/scripts/postinstall.test.d.ts +0 -1
- package/dist/scripts/postinstall.test.js +0 -53
- package/dist/services/env.test.d.ts +0 -1
- package/dist/services/env.test.js +0 -21
- package/dist/services/git.integration.test.d.ts +0 -1
- package/dist/services/git.integration.test.js +0 -267
- package/dist/services/git.test.d.ts +0 -1
- package/dist/services/git.test.js +0 -518
- package/dist/services/github/commitFormatters.test.d.ts +0 -1
- package/dist/services/github/commitFormatters.test.js +0 -11
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
- package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/createPullRequest.test.js +0 -325
- package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
- package/dist/services/github/v3/createStatusComment.test.js +0 -386
- package/dist/services/github/v3/index.d.ts +0 -1
- package/dist/services/github/v3/index.js +0 -61
- package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
- package/dist/services/github/v4/apiRequestV4.test.js +0 -82
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -96
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -143
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -124
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -200
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -153
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -136
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -154
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
- package/dist/services/prompt.test.d.ts +0 -1
- package/dist/services/prompt.test.js +0 -134
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -235
- package/dist/test/ExecError.d.ts +0 -16
- package/dist/test/ExecError.js +0 -15
- package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
- package/dist/test/backport-e2e.mutation.test.js +0 -347
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
- package/dist/test/mockConfigFiles.d.ts +0 -5
- package/dist/test/mockConfigFiles.js +0 -21
- package/dist/test/mocks.d.ts +0 -10
- package/dist/test/mocks.js +0 -23
- package/dist/test/nockHelpers.d.ts +0 -16
- package/dist/test/nockHelpers.js +0 -32
- package/dist/test/private/getDevAccessToken.d.ts +0 -2
- package/dist/test/private/getDevAccessToken.js +0 -12
- package/dist/test/sandbox.d.ts +0 -5
- package/dist/test/sandbox.js +0 -43
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -63
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -455
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
- package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
- package/dist/ui/getTargetBranches.test.d.ts +0 -1
- package/dist/ui/getTargetBranches.test.js +0 -198
- package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
- package/dist/ui/maybeSetupRepo.test.js +0 -204
- package/dist/utils/excludeUndefined.test.d.ts +0 -1
- 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 {};
|