backport 7.2.0-beta.2 → 7.2.0-beta.3
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.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 +182 -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 +384 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +243 -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.d.ts +1 -3
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +320 -0
- package/dist/services/git.js +5 -3
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +532 -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 +109 -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 +93 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -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.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -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 +156 -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 +467 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/cli.e2e.private.test.js +433 -0
- package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -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 +36 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -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 +63 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -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.js +7 -3
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +238 -0
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,384 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,243 @@
|
|
|
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 os_1 = __importDefault(require("os"));
|
|
26
|
+
const lodash_1 = require("lodash");
|
|
27
|
+
const nock_1 = __importDefault(require("nock"));
|
|
28
|
+
const runSequentially_1 = require("./runSequentially");
|
|
29
|
+
const childProcess = __importStar(require("./services/child-process-promisified"));
|
|
30
|
+
const nockHelpers_1 = require("./test/nockHelpers");
|
|
31
|
+
jest.mock('./services/child-process-promisified', () => {
|
|
32
|
+
return {
|
|
33
|
+
exec: jest.fn(async (cmd) => {
|
|
34
|
+
throw new Error(`Mock required for exec with cmd: "${cmd}"`);
|
|
35
|
+
}),
|
|
36
|
+
execAsCallback: jest.fn((...args) => {
|
|
37
|
+
(0, lodash_1.last)(args)();
|
|
38
|
+
return {
|
|
39
|
+
stderr: {
|
|
40
|
+
on: () => null,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
describe('runSequentially', () => {
|
|
47
|
+
let rpcExecMock;
|
|
48
|
+
let rpcExecOriginalMock;
|
|
49
|
+
let res;
|
|
50
|
+
let createPullRequestCalls;
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
jest.clearAllMocks();
|
|
53
|
+
nock_1.default.cleanAll();
|
|
54
|
+
});
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
57
|
+
const options = {
|
|
58
|
+
accessToken: 'myAccessToken',
|
|
59
|
+
assignees: [],
|
|
60
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
61
|
+
author: 'sqren',
|
|
62
|
+
autoAssign: false,
|
|
63
|
+
autoFixConflicts: undefined,
|
|
64
|
+
autoMerge: false,
|
|
65
|
+
autoMergeMethod: 'merge',
|
|
66
|
+
backportBinary: 'node scripts/backport',
|
|
67
|
+
branchLabelMapping: undefined,
|
|
68
|
+
cherrypickRef: true,
|
|
69
|
+
ci: false,
|
|
70
|
+
commitPaths: [],
|
|
71
|
+
cwd: '/path/to/source/repo',
|
|
72
|
+
dateSince: null,
|
|
73
|
+
dateUntil: null,
|
|
74
|
+
details: false,
|
|
75
|
+
editor: 'code',
|
|
76
|
+
fork: true,
|
|
77
|
+
gitHostname: 'github.com',
|
|
78
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
79
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
80
|
+
mainline: undefined,
|
|
81
|
+
maxNumber: 10,
|
|
82
|
+
multipleBranches: false,
|
|
83
|
+
multipleCommits: false,
|
|
84
|
+
noVerify: true,
|
|
85
|
+
prFilter: undefined,
|
|
86
|
+
publishStatusComment: true,
|
|
87
|
+
pullNumber: undefined,
|
|
88
|
+
repoName: 'kibana',
|
|
89
|
+
repoOwner: 'elastic',
|
|
90
|
+
resetAuthor: false,
|
|
91
|
+
reviewers: [],
|
|
92
|
+
sha: undefined,
|
|
93
|
+
skipRemoteConfig: undefined,
|
|
94
|
+
sourceBranch: 'my-source-branch-from-options',
|
|
95
|
+
sourcePRLabels: [],
|
|
96
|
+
targetBranches: [],
|
|
97
|
+
targetBranchChoices: [
|
|
98
|
+
{ name: '6.x' },
|
|
99
|
+
{ name: '6.0' },
|
|
100
|
+
{ name: '5.6' },
|
|
101
|
+
{ name: '5.5' },
|
|
102
|
+
{ name: '5.4' },
|
|
103
|
+
],
|
|
104
|
+
targetPRLabels: [],
|
|
105
|
+
verbose: false,
|
|
106
|
+
};
|
|
107
|
+
rpcExecMock = jest
|
|
108
|
+
.spyOn(childProcess, 'exec')
|
|
109
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
110
|
+
rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
|
|
111
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
112
|
+
.post('/repos/elastic/kibana/pulls')
|
|
113
|
+
.reply(200, {
|
|
114
|
+
number: 1337,
|
|
115
|
+
html_url: 'myHtmlUrl',
|
|
116
|
+
});
|
|
117
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
118
|
+
const commits = [
|
|
119
|
+
{
|
|
120
|
+
sourceCommit: {
|
|
121
|
+
committedDate: '1',
|
|
122
|
+
message: 'My commit message',
|
|
123
|
+
sha: 'abcd',
|
|
124
|
+
},
|
|
125
|
+
sourcePullRequest: {
|
|
126
|
+
url: 'foo',
|
|
127
|
+
number: 55,
|
|
128
|
+
mergeCommit: {
|
|
129
|
+
message: 'My commit message',
|
|
130
|
+
sha: 'abcd',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
sourceBranch: 'master',
|
|
134
|
+
expectedTargetPullRequests: [],
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
const targetBranches = ['7.x'];
|
|
138
|
+
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
139
|
+
scope.done();
|
|
140
|
+
});
|
|
141
|
+
it('returns pull request', () => {
|
|
142
|
+
expect(res).toEqual([
|
|
143
|
+
{
|
|
144
|
+
didUpdate: false,
|
|
145
|
+
pullRequestNumber: 1337,
|
|
146
|
+
pullRequestUrl: 'myHtmlUrl',
|
|
147
|
+
status: 'success',
|
|
148
|
+
targetBranch: '7.x',
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
it('creates pull request', () => {
|
|
153
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
154
|
+
Array [
|
|
155
|
+
Object {
|
|
156
|
+
"base": "7.x",
|
|
157
|
+
"body": "# Backport
|
|
158
|
+
|
|
159
|
+
This will backport the following commits from \`master\` to \`7.x\`:
|
|
160
|
+
- [My commit message](foo)
|
|
161
|
+
|
|
162
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
163
|
+
|
|
164
|
+
### Questions ?
|
|
165
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
166
|
+
"head": "sqren_authenticated:backport/7.x/pr-55",
|
|
167
|
+
"title": "[7.x] My commit message",
|
|
168
|
+
},
|
|
169
|
+
]
|
|
170
|
+
`);
|
|
171
|
+
});
|
|
172
|
+
it('should run commands in correct folders', () => {
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
174
|
+
expect(rpcExecMock.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
|
|
175
|
+
{
|
|
176
|
+
cmd: 'git rev-parse --show-toplevel',
|
|
177
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
cmd: 'git remote --verbose',
|
|
181
|
+
cwd: '/path/to/source/repo',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
cmd: 'git remote rm origin',
|
|
185
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
cmd: 'git remote rm sqren_authenticated',
|
|
189
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
|
|
193
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
cmd: 'git remote rm elastic',
|
|
197
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
201
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
cmd: 'git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track',
|
|
205
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
cmd: 'git fetch elastic master:master --force',
|
|
209
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
cmd: 'git rev-list -1 --merges abcd~1..abcd',
|
|
213
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
cmd: 'git cherry-pick -x abcd',
|
|
217
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
cmd: 'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
|
|
221
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
cmd: 'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
|
|
225
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
226
|
+
},
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
it('git clone should be called with correct args', () => {
|
|
230
|
+
expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
|
|
231
|
+
expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
|
|
232
|
+
Array [
|
|
233
|
+
Array [
|
|
234
|
+
"git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress",
|
|
235
|
+
Object {
|
|
236
|
+
"maxBuffer": 104857600,
|
|
237
|
+
},
|
|
238
|
+
[Function],
|
|
239
|
+
],
|
|
240
|
+
]
|
|
241
|
+
`);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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 os_1 = __importDefault(require("os"));
|
|
26
|
+
const globalConfig = __importStar(require("../options/config/globalConfig"));
|
|
27
|
+
const logger = __importStar(require("../services/logger"));
|
|
28
|
+
const postinstall_1 = require("./postinstall");
|
|
29
|
+
describe('postinstall', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
});
|
|
36
|
+
it("should create global config if it doesn't exist", async () => {
|
|
37
|
+
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
38
|
+
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
39
|
+
.mockResolvedValueOnce(true);
|
|
40
|
+
await (0, postinstall_1.postinstall)();
|
|
41
|
+
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
42
|
+
expect(logger.consoleLog).toBeCalledWith('Global config successfully created in /myHomeDir/.backport/config.json');
|
|
43
|
+
});
|
|
44
|
+
it('should not create global config if it already exists', async () => {
|
|
45
|
+
const consoleSpy = jest.spyOn(console, 'log');
|
|
46
|
+
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
47
|
+
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
48
|
+
.mockResolvedValueOnce(false);
|
|
49
|
+
await (0, postinstall_1.postinstall)();
|
|
50
|
+
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
51
|
+
expect(consoleSpy).toBeCalledTimes(0);
|
|
52
|
+
});
|
|
53
|
+
});
|