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,518 @@
|
|
|
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 childProcess = __importStar(require("../services/child-process-promisified"));
|
|
27
|
+
const ExecError_1 = require("../test/ExecError");
|
|
28
|
+
const git_1 = require("./git");
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
31
|
+
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
jest.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
describe('getUnstagedFiles', () => {
|
|
36
|
+
it('should split lines and remove empty', async () => {
|
|
37
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
|
|
38
|
+
stdout: 'conflicting-file.txt\nconflicting-file2.txt\n',
|
|
39
|
+
stderr: '',
|
|
40
|
+
});
|
|
41
|
+
const options = {
|
|
42
|
+
repoOwner: 'elastic',
|
|
43
|
+
repoName: 'kibana',
|
|
44
|
+
};
|
|
45
|
+
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([
|
|
46
|
+
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
47
|
+
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file2.txt',
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
it('should not error on empty', async () => {
|
|
51
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
|
|
52
|
+
stdout: '',
|
|
53
|
+
stderr: '',
|
|
54
|
+
});
|
|
55
|
+
const options = {
|
|
56
|
+
repoOwner: 'elastic',
|
|
57
|
+
repoName: 'kibana',
|
|
58
|
+
};
|
|
59
|
+
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('getLocalConfigFileCommitDate', () => {
|
|
63
|
+
it('returns a timestamp the file exists', async () => {
|
|
64
|
+
const res = {
|
|
65
|
+
stdout: 'Wed Dec 16 10:10:39 2020 -0800\n',
|
|
66
|
+
stderr: '',
|
|
67
|
+
};
|
|
68
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
69
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(1608142239000);
|
|
70
|
+
});
|
|
71
|
+
it('returns empty when file does not exists', async () => {
|
|
72
|
+
const res = { stdout: '', stderr: '' };
|
|
73
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
74
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
75
|
+
});
|
|
76
|
+
it('handles errors', async () => {
|
|
77
|
+
const err = {
|
|
78
|
+
killed: false,
|
|
79
|
+
code: 128,
|
|
80
|
+
signal: null,
|
|
81
|
+
cmd: 'any command...',
|
|
82
|
+
stdout: '',
|
|
83
|
+
stderr: 'any error',
|
|
84
|
+
};
|
|
85
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
86
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('isLocalConfigFileUntracked', () => {
|
|
90
|
+
it('returns "false" if file does not exist', async () => {
|
|
91
|
+
const res = { stdout: '', stderr: '' };
|
|
92
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
93
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(false);
|
|
94
|
+
});
|
|
95
|
+
it('returns "true" if file is untracked', async () => {
|
|
96
|
+
const res = { stdout: '.backportrc.json\n', stderr: '' };
|
|
97
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
98
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(true);
|
|
99
|
+
});
|
|
100
|
+
it('handles errors', async () => {
|
|
101
|
+
const err = {
|
|
102
|
+
killed: false,
|
|
103
|
+
code: 128,
|
|
104
|
+
signal: null,
|
|
105
|
+
cmd: 'any command...',
|
|
106
|
+
stdout: '',
|
|
107
|
+
stderr: 'any error',
|
|
108
|
+
};
|
|
109
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
110
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('isLocalConfigFileModified', () => {
|
|
114
|
+
it('returns "false" if file does not exist', async () => {
|
|
115
|
+
const res = { stdout: '', stderr: '' };
|
|
116
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
117
|
+
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
118
|
+
});
|
|
119
|
+
it('returns "false" if file is untracked', async () => {
|
|
120
|
+
const res = { stdout: '', stderr: '' };
|
|
121
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
122
|
+
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
123
|
+
});
|
|
124
|
+
it('returns "true" if file is staged', async () => {
|
|
125
|
+
const res = { stdout: '.backportrc.json\n', stderr: '' };
|
|
126
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
127
|
+
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(true);
|
|
128
|
+
});
|
|
129
|
+
it('handles errors', async () => {
|
|
130
|
+
const err = {
|
|
131
|
+
killed: false,
|
|
132
|
+
code: 128,
|
|
133
|
+
signal: null,
|
|
134
|
+
cmd: 'any command...',
|
|
135
|
+
stdout: '',
|
|
136
|
+
stderr: 'any error',
|
|
137
|
+
};
|
|
138
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
139
|
+
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('getRepoInfoFromGitRemotes', () => {
|
|
143
|
+
it('returns repoName and repoOwner for every remote', async () => {
|
|
144
|
+
const res = {
|
|
145
|
+
stdout: 'john.doe\tgit@github.com:john.doe/kibana (fetch)\n' +
|
|
146
|
+
'john.doe\tgit@github.com:john.doe/kibana (push)\n' +
|
|
147
|
+
'elastic\tgit@github.com:elastic/kibana.git (fetch)\n' +
|
|
148
|
+
'elastic\tgit@github.com:elastic/kibana.git (push)\n' +
|
|
149
|
+
'peter\tgit@github.com:peter/kibana (fetch)\n' +
|
|
150
|
+
'peter\tgit@github.com:peter/kibana (push)\n' +
|
|
151
|
+
'sqren\tgit@github.com:sqren/kibana.git (fetch)\n' +
|
|
152
|
+
'sqren\tgit@github.com:sqren/kibana.git (push)\n',
|
|
153
|
+
stderr: '',
|
|
154
|
+
};
|
|
155
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
156
|
+
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
157
|
+
{ repoName: 'kibana', repoOwner: 'john.doe' },
|
|
158
|
+
{ repoName: 'kibana', repoOwner: 'elastic' },
|
|
159
|
+
{ repoName: 'kibana', repoOwner: 'peter' },
|
|
160
|
+
{ repoName: 'kibana', repoOwner: 'sqren' },
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
it('returns undefined when no remotes exist', async () => {
|
|
164
|
+
const res = { stdout: '', stderr: '' };
|
|
165
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
166
|
+
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
it('handles errors', async () => {
|
|
169
|
+
const err = {
|
|
170
|
+
killed: false,
|
|
171
|
+
code: 128,
|
|
172
|
+
signal: null,
|
|
173
|
+
cmd: 'git ls-files .backportrc.js* --exclude-standard --others',
|
|
174
|
+
stdout: '',
|
|
175
|
+
stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
|
|
176
|
+
};
|
|
177
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
178
|
+
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
describe('getConflictingFiles', () => {
|
|
182
|
+
it('should split by linebreak and remove empty and duplicate items', async () => {
|
|
183
|
+
const err = {
|
|
184
|
+
killed: false,
|
|
185
|
+
code: 2,
|
|
186
|
+
signal: null,
|
|
187
|
+
cmd: 'git --no-pager diff --check',
|
|
188
|
+
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
189
|
+
stderr: '',
|
|
190
|
+
};
|
|
191
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
192
|
+
const options = {
|
|
193
|
+
repoOwner: 'elastic',
|
|
194
|
+
repoName: 'kibana',
|
|
195
|
+
};
|
|
196
|
+
expect(await (0, git_1.getConflictingFiles)(options)).toEqual([
|
|
197
|
+
{
|
|
198
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
199
|
+
relative: 'conflicting-file.txt',
|
|
200
|
+
},
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
describe('createFeatureBranch', () => {
|
|
205
|
+
const options = {
|
|
206
|
+
repoOwner: 'elastic',
|
|
207
|
+
repoName: 'kibana',
|
|
208
|
+
};
|
|
209
|
+
const targetBranch = '4.x';
|
|
210
|
+
const backportBranch = 'backport/4.x/commit-72f94e76';
|
|
211
|
+
it(`should handle "couldn't find remote ref" error`, async () => {
|
|
212
|
+
expect.assertions(1);
|
|
213
|
+
const err = {
|
|
214
|
+
killed: false,
|
|
215
|
+
code: 128,
|
|
216
|
+
signal: null,
|
|
217
|
+
cmd: '',
|
|
218
|
+
stdout: 'HEAD is now at 72f94e7 Create "conflicting-file.txt" in master\n',
|
|
219
|
+
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
220
|
+
};
|
|
221
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
222
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
223
|
+
});
|
|
224
|
+
it('should throw "Invalid refspec" error', async () => {
|
|
225
|
+
expect.assertions(1);
|
|
226
|
+
const err = {
|
|
227
|
+
killed: false,
|
|
228
|
+
code: 128,
|
|
229
|
+
signal: null,
|
|
230
|
+
cmd: '',
|
|
231
|
+
stdout: '',
|
|
232
|
+
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
233
|
+
};
|
|
234
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
235
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
236
|
+
});
|
|
237
|
+
it('should rethrow normal error', async () => {
|
|
238
|
+
expect.assertions(1);
|
|
239
|
+
const err = new Error('just a normal error');
|
|
240
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
241
|
+
expect.assertions(1);
|
|
242
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
describe('deleteRemote', () => {
|
|
246
|
+
const remoteName = 'my-remote';
|
|
247
|
+
const options = {
|
|
248
|
+
repoOwner: 'elastic',
|
|
249
|
+
repoName: 'kibana',
|
|
250
|
+
};
|
|
251
|
+
it('should swallow exec error', async () => {
|
|
252
|
+
const err = {
|
|
253
|
+
killed: false,
|
|
254
|
+
code: 128,
|
|
255
|
+
signal: null,
|
|
256
|
+
cmd: 'git remote rm origin',
|
|
257
|
+
stdout: '',
|
|
258
|
+
stderr: "fatal: No such remote: 'origin'\n",
|
|
259
|
+
};
|
|
260
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
261
|
+
await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
|
|
262
|
+
});
|
|
263
|
+
it('should rethrow normal error', async () => {
|
|
264
|
+
const err = new Error('just a normal error');
|
|
265
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
266
|
+
expect.assertions(1);
|
|
267
|
+
await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
describe('cherrypick', () => {
|
|
271
|
+
const options = {
|
|
272
|
+
repoOwner: 'elastic',
|
|
273
|
+
repoName: 'kibana',
|
|
274
|
+
};
|
|
275
|
+
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
276
|
+
jest
|
|
277
|
+
.spyOn(childProcess, 'exec')
|
|
278
|
+
// mock cherry pick command
|
|
279
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
280
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
281
|
+
conflictingFiles: [],
|
|
282
|
+
unstagedFiles: [],
|
|
283
|
+
needsResolving: false,
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
it('should use mainline option when specified', async () => {
|
|
287
|
+
const execSpy = jest
|
|
288
|
+
.spyOn(childProcess, 'exec')
|
|
289
|
+
// mock cherry pick command
|
|
290
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
291
|
+
await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
|
|
292
|
+
expect(execSpy.mock.calls[0][0]).toBe('git cherry-pick -x --mainline 1 abcd');
|
|
293
|
+
});
|
|
294
|
+
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
295
|
+
jest
|
|
296
|
+
.spyOn(childProcess, 'exec')
|
|
297
|
+
// mock cherry pick command
|
|
298
|
+
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
299
|
+
killed: false,
|
|
300
|
+
code: 128,
|
|
301
|
+
cmd: 'git cherry-pick -x abcd',
|
|
302
|
+
stdout: '',
|
|
303
|
+
stderr: '',
|
|
304
|
+
}))
|
|
305
|
+
// mock getConflictingFiles
|
|
306
|
+
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
307
|
+
code: 2,
|
|
308
|
+
cmd: 'git --no-pager diff --check',
|
|
309
|
+
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
310
|
+
stderr: '',
|
|
311
|
+
}))
|
|
312
|
+
// mock getUnstagedFiles
|
|
313
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
314
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
315
|
+
conflictingFiles: [
|
|
316
|
+
{
|
|
317
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
318
|
+
relative: 'conflicting-file.txt',
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
needsResolving: true,
|
|
322
|
+
unstagedFiles: [],
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
326
|
+
jest
|
|
327
|
+
.spyOn(childProcess, 'exec')
|
|
328
|
+
// mock cherry pick command
|
|
329
|
+
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
330
|
+
killed: false,
|
|
331
|
+
code: 128,
|
|
332
|
+
signal: null,
|
|
333
|
+
cmd: 'git cherry-pick 381c7b604110257437a289b1f1742685eb8d79c5',
|
|
334
|
+
stdout: '',
|
|
335
|
+
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
336
|
+
}));
|
|
337
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
338
|
+
.toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
|
|
339
|
+
|
|
340
|
+
> backport --mainline
|
|
341
|
+
|
|
342
|
+
or:
|
|
343
|
+
|
|
344
|
+
> backport --mainline <parent-number>
|
|
345
|
+
|
|
346
|
+
Or refer to the git documentation for more information: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt---mainlineparent-number`);
|
|
347
|
+
});
|
|
348
|
+
it('should gracefully handle empty commits', async () => {
|
|
349
|
+
jest
|
|
350
|
+
.spyOn(childProcess, 'exec')
|
|
351
|
+
// mock cherry pick command
|
|
352
|
+
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
353
|
+
killed: false,
|
|
354
|
+
code: 1,
|
|
355
|
+
signal: null,
|
|
356
|
+
cmd: 'git cherry-pick fe6b13b83cc010f722548cd5a0a8c2d5341a20dd',
|
|
357
|
+
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
358
|
+
stderr: "The previous cherry-pick is now empty, possibly due to conflict resolution.\nIf you wish to commit it anyway, use:\n\n git commit --allow-empty\n\nOtherwise, please use 'git cherry-pick --skip'\n",
|
|
359
|
+
}));
|
|
360
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
|
|
361
|
+
});
|
|
362
|
+
it('gracefully handles missing git info', async () => {
|
|
363
|
+
jest
|
|
364
|
+
.spyOn(childProcess, 'exec')
|
|
365
|
+
// mock cherry pick command
|
|
366
|
+
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
367
|
+
killed: false,
|
|
368
|
+
code: 128,
|
|
369
|
+
signal: null,
|
|
370
|
+
cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
|
|
371
|
+
stdout: '',
|
|
372
|
+
stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <foo@bar.net>) not allowed\n',
|
|
373
|
+
}));
|
|
374
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
375
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
376
|
+
"Cherrypick failed:
|
|
377
|
+
|
|
378
|
+
*** Please tell me who you are.
|
|
379
|
+
|
|
380
|
+
Run
|
|
381
|
+
|
|
382
|
+
git config --global user.email \\"you@example.com\\"
|
|
383
|
+
git config --global user.name \\"Your Name\\"
|
|
384
|
+
|
|
385
|
+
to set your account's default identity.
|
|
386
|
+
Omit --global to set the identity only in this repository.
|
|
387
|
+
|
|
388
|
+
fatal: empty ident name (for <foo@bar.net>) not allowed
|
|
389
|
+
"
|
|
390
|
+
`);
|
|
391
|
+
});
|
|
392
|
+
it('should re-throw non-cherrypick errors', async () => {
|
|
393
|
+
jest
|
|
394
|
+
.spyOn(childProcess, 'exec')
|
|
395
|
+
// mock cherry pick command
|
|
396
|
+
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
397
|
+
// getConflictingFiles
|
|
398
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
399
|
+
// getUnstagedFiles
|
|
400
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
401
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
describe('commitChanges', () => {
|
|
405
|
+
const options = {
|
|
406
|
+
repoOwner: 'elastic',
|
|
407
|
+
repoName: 'kibana',
|
|
408
|
+
};
|
|
409
|
+
const commit = {
|
|
410
|
+
sourceCommit: {
|
|
411
|
+
message: 'The original commit message',
|
|
412
|
+
committedDate: '2020',
|
|
413
|
+
sha: 'abc',
|
|
414
|
+
},
|
|
415
|
+
sourceBranch: 'master',
|
|
416
|
+
expectedTargetPullRequests: [],
|
|
417
|
+
};
|
|
418
|
+
it('should return when changes committed successfully', async () => {
|
|
419
|
+
jest
|
|
420
|
+
.spyOn(childProcess, 'exec')
|
|
421
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
422
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
423
|
+
});
|
|
424
|
+
it('should swallow error if changes have already been committed manaully', async () => {
|
|
425
|
+
const err = {
|
|
426
|
+
killed: false,
|
|
427
|
+
code: 1,
|
|
428
|
+
signal: null,
|
|
429
|
+
cmd: 'git commit --no-edit',
|
|
430
|
+
stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
|
|
431
|
+
stderr: '',
|
|
432
|
+
};
|
|
433
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
434
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
435
|
+
});
|
|
436
|
+
describe('when commit fails due to empty message', () => {
|
|
437
|
+
let spy;
|
|
438
|
+
let res;
|
|
439
|
+
beforeEach(async () => {
|
|
440
|
+
const err = {
|
|
441
|
+
killed: false,
|
|
442
|
+
code: 1,
|
|
443
|
+
signal: null,
|
|
444
|
+
cmd: 'git commit --no-edit --no-verify',
|
|
445
|
+
stdout: '',
|
|
446
|
+
stderr: 'Aborting commit due to empty commit message.\n',
|
|
447
|
+
};
|
|
448
|
+
spy = jest
|
|
449
|
+
.spyOn(childProcess, 'exec')
|
|
450
|
+
.mockRejectedValueOnce(err)
|
|
451
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
452
|
+
res = await (0, git_1.commitChanges)(commit, options);
|
|
453
|
+
});
|
|
454
|
+
it('should manually set the commit message', () => {
|
|
455
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
456
|
+
expect(spy).toHaveBeenCalledWith('git commit --no-edit', expect.any(Object));
|
|
457
|
+
expect(spy).toHaveBeenCalledWith('git commit -m "The original commit message" ', expect.any(Object));
|
|
458
|
+
});
|
|
459
|
+
it('should handle the error and resolve successfully', async () => {
|
|
460
|
+
await expect(res).toBe(undefined);
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
it('should re-throw other errors', async () => {
|
|
464
|
+
const err = new Error('non-cherrypick error');
|
|
465
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
466
|
+
expect.assertions(1);
|
|
467
|
+
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
describe('addRemote', () => {
|
|
471
|
+
const options = {
|
|
472
|
+
accessToken: 'myAccessToken',
|
|
473
|
+
repoOwner: 'elastic',
|
|
474
|
+
repoName: 'kibana',
|
|
475
|
+
gitHostname: 'github.com',
|
|
476
|
+
};
|
|
477
|
+
it('add correct origin remote', async () => {
|
|
478
|
+
const spy = jest
|
|
479
|
+
.spyOn(childProcess, 'exec')
|
|
480
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
481
|
+
await (0, git_1.addRemote)(options, 'elastic');
|
|
482
|
+
return expect(spy).toHaveBeenCalledWith('git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
483
|
+
});
|
|
484
|
+
it('add correct user remote', async () => {
|
|
485
|
+
const spy = jest
|
|
486
|
+
.spyOn(childProcess, 'exec')
|
|
487
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
488
|
+
await (0, git_1.addRemote)(options, 'sqren');
|
|
489
|
+
return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
490
|
+
});
|
|
491
|
+
it('allows custom github url', async () => {
|
|
492
|
+
const spy = jest
|
|
493
|
+
.spyOn(childProcess, 'exec')
|
|
494
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
495
|
+
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
496
|
+
return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
describe('pushBackportBranch', () => {
|
|
500
|
+
const options = {
|
|
501
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
502
|
+
fork: true,
|
|
503
|
+
repoOwner: 'elastic',
|
|
504
|
+
repoName: 'kibana',
|
|
505
|
+
};
|
|
506
|
+
const backportBranch = 'backport/7.x/pr-2';
|
|
507
|
+
it('should handle missing fork error', async () => {
|
|
508
|
+
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce({
|
|
509
|
+
killed: false,
|
|
510
|
+
code: 128,
|
|
511
|
+
signal: null,
|
|
512
|
+
cmd: 'git push sqren backport/7.x/pr-2:backport/7.x/pr-2 --force',
|
|
513
|
+
stdout: '',
|
|
514
|
+
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
515
|
+
});
|
|
516
|
+
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren_authenticated/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const commitFormatters_1 = require("./commitFormatters");
|
|
4
|
+
describe('getFirstCommitMessageLine', () => {
|
|
5
|
+
it('should only return the first line of the message', () => {
|
|
6
|
+
expect((0, commitFormatters_1.getFirstLine)('My commit message (#1234)\n\n Additional commit message body')).toEqual('My commit message (#1234)');
|
|
7
|
+
});
|
|
8
|
+
it('should return the commit message as-is', () => {
|
|
9
|
+
expect((0, commitFormatters_1.getFirstLine)('My commit message')).toEqual('My commit message');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
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 nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const addAssigneesToPullRequest_1 = require("./addAssigneesToPullRequest");
|
|
8
|
+
describe('addAssigneesToPullRequest', () => {
|
|
9
|
+
it('should add assignees to PR', async () => {
|
|
10
|
+
const pullNumber = 216;
|
|
11
|
+
const assignees = ['sqren'];
|
|
12
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
13
|
+
.post('/repos/elastic/kibana/issues/216/assignees', {
|
|
14
|
+
assignees: ['sqren'],
|
|
15
|
+
})
|
|
16
|
+
.reply(200, 'some response');
|
|
17
|
+
const res = await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)({
|
|
18
|
+
author: 'sqren',
|
|
19
|
+
repoName: 'kibana',
|
|
20
|
+
repoOwner: 'elastic',
|
|
21
|
+
accessToken: 'my-token',
|
|
22
|
+
}, pullNumber, assignees);
|
|
23
|
+
expect(res).toBe(undefined);
|
|
24
|
+
scope.done();
|
|
25
|
+
nock_1.default.cleanAll();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|