backport 7.3.5 → 8.0.0
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/README.md +13 -18
- package/dist/backportRun.d.ts +14 -3
- package/dist/backportRun.js +59 -37
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +8 -3
- package/dist/entrypoint.module.js +6 -10
- package/dist/entrypoint.module.private.test.js +129 -330
- package/dist/options/ConfigOptions.d.ts +2 -2
- package/dist/options/cliArgs.d.ts +10 -6
- package/dist/options/cliArgs.js +32 -21
- package/dist/options/cliArgs.test.js +3 -3
- package/dist/options/config/config.d.ts +2 -2
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +13 -10
- package/dist/options/config/projectConfig.d.ts +2 -2
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +19 -7
- package/dist/options/config/readConfigFile.d.ts +4 -4
- package/dist/options/options.d.ts +4 -5
- package/dist/options/options.js +2 -3
- package/dist/options/options.test.js +7 -4
- package/dist/runSequentially.d.ts +5 -1
- package/dist/runSequentially.js +23 -8
- package/dist/scripts/postinstall.js +1 -0
- package/dist/scripts/postinstall.test.js +5 -1
- package/dist/services/HandledError.d.ts +6 -2
- package/dist/services/HandledError.js +8 -8
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +188 -126
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -158
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +3 -1
- package/dist/services/github/v3/createStatusComment.js +16 -16
- package/dist/services/github/v3/createStatusComment.test.js +17 -5
- package/dist/services/github/v4/apiRequestV4.js +6 -9
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
- package/dist/services/logger.d.ts +1 -4
- package/dist/services/logger.js +14 -19
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +16 -12
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +1 -1
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +414 -695
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -24,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
29
|
const os_1 = __importDefault(require("os"));
|
|
26
30
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
27
|
-
const ExecError_1 = require("../test/ExecError");
|
|
28
31
|
const git_1 = require("./git");
|
|
29
32
|
beforeEach(() => {
|
|
30
33
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
@@ -35,9 +38,11 @@ afterEach(() => {
|
|
|
35
38
|
const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
|
|
36
39
|
describe('getUnstagedFiles', () => {
|
|
37
40
|
it('should split lines and remove empty', async () => {
|
|
38
|
-
jest.spyOn(childProcess, '
|
|
41
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
|
|
39
42
|
stdout: 'conflicting-file.txt\nconflicting-file2.txt\n',
|
|
40
43
|
stderr: '',
|
|
44
|
+
code: 0,
|
|
45
|
+
cmdArgs: [],
|
|
41
46
|
});
|
|
42
47
|
const options = {
|
|
43
48
|
repoOwner: 'elastic',
|
|
@@ -49,9 +54,11 @@ describe('getUnstagedFiles', () => {
|
|
|
49
54
|
]);
|
|
50
55
|
});
|
|
51
56
|
it('should not error on empty', async () => {
|
|
52
|
-
jest.spyOn(childProcess, '
|
|
57
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
|
|
53
58
|
stdout: '',
|
|
54
59
|
stderr: '',
|
|
60
|
+
code: 0,
|
|
61
|
+
cmdArgs: [],
|
|
55
62
|
});
|
|
56
63
|
const options = {
|
|
57
64
|
repoOwner: 'elastic',
|
|
@@ -65,13 +72,15 @@ describe('getLocalConfigFileCommitDate', () => {
|
|
|
65
72
|
const res = {
|
|
66
73
|
stdout: 'Wed Dec 16 10:10:39 2020 -0800\n',
|
|
67
74
|
stderr: '',
|
|
75
|
+
code: 0,
|
|
76
|
+
cmdArgs: [],
|
|
68
77
|
};
|
|
69
|
-
jest.spyOn(childProcess, '
|
|
78
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
70
79
|
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(1608142239000);
|
|
71
80
|
});
|
|
72
81
|
it('returns empty when file does not exists', async () => {
|
|
73
|
-
const res = { stdout: '', stderr: '' };
|
|
74
|
-
jest.spyOn(childProcess, '
|
|
82
|
+
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
83
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
75
84
|
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
76
85
|
});
|
|
77
86
|
it('handles errors', async () => {
|
|
@@ -83,19 +92,24 @@ describe('getLocalConfigFileCommitDate', () => {
|
|
|
83
92
|
stdout: '',
|
|
84
93
|
stderr: 'any error',
|
|
85
94
|
};
|
|
86
|
-
jest.spyOn(childProcess, '
|
|
95
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
87
96
|
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
88
97
|
});
|
|
89
98
|
});
|
|
90
99
|
describe('isLocalConfigFileUntracked', () => {
|
|
91
100
|
it('returns "false" if file does not exist', async () => {
|
|
92
|
-
const res = { stdout: '', stderr: '' };
|
|
93
|
-
jest.spyOn(childProcess, '
|
|
101
|
+
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
102
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
94
103
|
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(false);
|
|
95
104
|
});
|
|
96
105
|
it('returns "true" if file is untracked', async () => {
|
|
97
|
-
const res = {
|
|
98
|
-
|
|
106
|
+
const res = {
|
|
107
|
+
stdout: '.backportrc.json\n',
|
|
108
|
+
stderr: '',
|
|
109
|
+
code: 0,
|
|
110
|
+
cmdArgs: [],
|
|
111
|
+
};
|
|
112
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
99
113
|
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(true);
|
|
100
114
|
});
|
|
101
115
|
it('handles errors', async () => {
|
|
@@ -107,24 +121,29 @@ describe('isLocalConfigFileUntracked', () => {
|
|
|
107
121
|
stdout: '',
|
|
108
122
|
stderr: 'any error',
|
|
109
123
|
};
|
|
110
|
-
jest.spyOn(childProcess, '
|
|
124
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
111
125
|
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
112
126
|
});
|
|
113
127
|
});
|
|
114
128
|
describe('isLocalConfigFileModified', () => {
|
|
115
129
|
it('returns "false" if file does not exist', async () => {
|
|
116
|
-
const res = { stdout: '', stderr: '' };
|
|
117
|
-
jest.spyOn(childProcess, '
|
|
130
|
+
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
131
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
118
132
|
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
119
133
|
});
|
|
120
134
|
it('returns "false" if file is untracked', async () => {
|
|
121
|
-
const res = { stdout: '', stderr: '' };
|
|
122
|
-
jest.spyOn(childProcess, '
|
|
135
|
+
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
136
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
123
137
|
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
124
138
|
});
|
|
125
139
|
it('returns "true" if file is staged', async () => {
|
|
126
|
-
const res = {
|
|
127
|
-
|
|
140
|
+
const res = {
|
|
141
|
+
stdout: '.backportrc.json\n',
|
|
142
|
+
stderr: '',
|
|
143
|
+
code: 0,
|
|
144
|
+
cmdArgs: [],
|
|
145
|
+
};
|
|
146
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
128
147
|
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(true);
|
|
129
148
|
});
|
|
130
149
|
it('handles errors', async () => {
|
|
@@ -136,8 +155,8 @@ describe('isLocalConfigFileModified', () => {
|
|
|
136
155
|
stdout: '',
|
|
137
156
|
stderr: 'any error',
|
|
138
157
|
};
|
|
139
|
-
jest.spyOn(childProcess, '
|
|
140
|
-
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).
|
|
158
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
159
|
+
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toBe(false);
|
|
141
160
|
});
|
|
142
161
|
});
|
|
143
162
|
describe('getRepoInfoFromGitRemotes', () => {
|
|
@@ -152,8 +171,10 @@ describe('getRepoInfoFromGitRemotes', () => {
|
|
|
152
171
|
'sqren\tgit@github.com:sqren/kibana.git (fetch)\n' +
|
|
153
172
|
'sqren\tgit@github.com:sqren/kibana.git (push)\n',
|
|
154
173
|
stderr: '',
|
|
174
|
+
code: 0,
|
|
175
|
+
cmdArgs: [],
|
|
155
176
|
};
|
|
156
|
-
jest.spyOn(childProcess, '
|
|
177
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
157
178
|
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
158
179
|
{ repoName: 'kibana', repoOwner: 'john.doe' },
|
|
159
180
|
{ repoName: 'kibana', repoOwner: 'elastic' },
|
|
@@ -162,18 +183,20 @@ describe('getRepoInfoFromGitRemotes', () => {
|
|
|
162
183
|
]);
|
|
163
184
|
});
|
|
164
185
|
it('returns repoName and repoOwner https remotes', async () => {
|
|
165
|
-
jest.spyOn(childProcess, '
|
|
186
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue({
|
|
166
187
|
stdout: 'origin\thttps://github.com/shay/elasticsearch.git (fetch)\n' +
|
|
167
188
|
'origin\thttps://github.com/shay/elasticsearch.git (push)\n',
|
|
168
189
|
stderr: '',
|
|
190
|
+
code: 0,
|
|
191
|
+
cmdArgs: [],
|
|
169
192
|
});
|
|
170
193
|
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
171
194
|
{ repoName: 'elasticsearch', repoOwner: 'shay' },
|
|
172
195
|
]);
|
|
173
196
|
});
|
|
174
197
|
it('returns undefined when no remotes exist', async () => {
|
|
175
|
-
const res = { stdout: '', stderr: '' };
|
|
176
|
-
jest.spyOn(childProcess, '
|
|
198
|
+
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
199
|
+
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
177
200
|
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
178
201
|
});
|
|
179
202
|
it('handles errors', async () => {
|
|
@@ -185,21 +208,19 @@ describe('getRepoInfoFromGitRemotes', () => {
|
|
|
185
208
|
stdout: '',
|
|
186
209
|
stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
|
|
187
210
|
};
|
|
188
|
-
jest.spyOn(childProcess, '
|
|
211
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
189
212
|
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
190
213
|
});
|
|
191
214
|
});
|
|
192
215
|
describe('getConflictingFiles', () => {
|
|
193
216
|
it('should split by linebreak and remove empty and duplicate items', async () => {
|
|
194
|
-
const err = {
|
|
195
|
-
killed: false,
|
|
217
|
+
const err = new childProcess.SpawnError({
|
|
196
218
|
code: 2,
|
|
197
|
-
|
|
198
|
-
cmd: 'git --no-pager diff --check',
|
|
219
|
+
cmdArgs: ['--no-pager', 'diff', '--check'],
|
|
199
220
|
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
200
221
|
stderr: '',
|
|
201
|
-
};
|
|
202
|
-
jest.spyOn(childProcess, '
|
|
222
|
+
});
|
|
223
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
203
224
|
const options = {
|
|
204
225
|
repoOwner: 'elastic',
|
|
205
226
|
repoName: 'kibana',
|
|
@@ -212,7 +233,7 @@ describe('getConflictingFiles', () => {
|
|
|
212
233
|
]);
|
|
213
234
|
});
|
|
214
235
|
});
|
|
215
|
-
describe('
|
|
236
|
+
describe('createBackportBranch', () => {
|
|
216
237
|
const options = {
|
|
217
238
|
repoOwner: 'elastic',
|
|
218
239
|
repoName: 'kibana',
|
|
@@ -221,34 +242,30 @@ describe('createFeatureBranch', () => {
|
|
|
221
242
|
const backportBranch = 'backport/4.x/commit-72f94e76';
|
|
222
243
|
it(`should handle "couldn't find remote ref" error`, async () => {
|
|
223
244
|
expect.assertions(1);
|
|
224
|
-
const err = {
|
|
225
|
-
killed: false,
|
|
245
|
+
const err = new childProcess.SpawnError({
|
|
226
246
|
code: 128,
|
|
227
|
-
|
|
228
|
-
cmd: '',
|
|
247
|
+
cmdArgs: [],
|
|
229
248
|
stdout: 'HEAD is now at 72f94e7 Create "conflicting-file.txt" in master\n',
|
|
230
249
|
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
231
|
-
};
|
|
232
|
-
jest.spyOn(childProcess, '
|
|
250
|
+
});
|
|
251
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
233
252
|
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
234
253
|
});
|
|
235
254
|
it('should throw "Invalid refspec" error', async () => {
|
|
236
255
|
expect.assertions(1);
|
|
237
|
-
const err = {
|
|
238
|
-
killed: false,
|
|
256
|
+
const err = new childProcess.SpawnError({
|
|
239
257
|
code: 128,
|
|
240
|
-
|
|
241
|
-
cmd: '',
|
|
258
|
+
cmdArgs: [],
|
|
242
259
|
stdout: '',
|
|
243
260
|
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
244
|
-
};
|
|
245
|
-
jest.spyOn(childProcess, '
|
|
261
|
+
});
|
|
262
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
246
263
|
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
247
264
|
});
|
|
248
265
|
it('should rethrow normal error', async () => {
|
|
249
266
|
expect.assertions(1);
|
|
250
267
|
const err = new Error('just a normal error');
|
|
251
|
-
jest.spyOn(childProcess, '
|
|
268
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
252
269
|
expect.assertions(1);
|
|
253
270
|
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
254
271
|
});
|
|
@@ -259,21 +276,19 @@ describe('deleteRemote', () => {
|
|
|
259
276
|
repoOwner: 'elastic',
|
|
260
277
|
repoName: 'kibana',
|
|
261
278
|
};
|
|
262
|
-
it('should swallow
|
|
263
|
-
const err = {
|
|
264
|
-
killed: false,
|
|
279
|
+
it('should swallow SpawnError error', async () => {
|
|
280
|
+
const err = new childProcess.SpawnError({
|
|
265
281
|
code: 128,
|
|
266
|
-
|
|
267
|
-
cmd: 'git remote rm origin',
|
|
282
|
+
cmdArgs: [],
|
|
268
283
|
stdout: '',
|
|
269
284
|
stderr: "fatal: No such remote: 'origin'\n",
|
|
270
|
-
};
|
|
271
|
-
jest.spyOn(childProcess, '
|
|
285
|
+
});
|
|
286
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
272
287
|
await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
|
|
273
288
|
});
|
|
274
289
|
it('should rethrow normal error', async () => {
|
|
275
290
|
const err = new Error('just a normal error');
|
|
276
|
-
jest.spyOn(childProcess, '
|
|
291
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
277
292
|
expect.assertions(1);
|
|
278
293
|
await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
279
294
|
});
|
|
@@ -285,11 +300,9 @@ describe('cherrypick', () => {
|
|
|
285
300
|
};
|
|
286
301
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
287
302
|
jest
|
|
288
|
-
.spyOn(childProcess, '
|
|
289
|
-
// mock getIsMergeCommit(...)
|
|
290
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
291
|
-
// mock cherrypick(...)
|
|
292
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
303
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
304
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
305
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
293
306
|
expect(await (0, git_1.cherrypick)({
|
|
294
307
|
options,
|
|
295
308
|
sha: 'abcd',
|
|
@@ -301,41 +314,52 @@ describe('cherrypick', () => {
|
|
|
301
314
|
});
|
|
302
315
|
});
|
|
303
316
|
it('should use mainline option when specified', async () => {
|
|
304
|
-
const
|
|
305
|
-
.spyOn(childProcess, '
|
|
306
|
-
// mock getIsMergeCommit(...)
|
|
307
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
308
|
-
// mock cherry pick command
|
|
309
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
317
|
+
const spawnSpy = jest
|
|
318
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
319
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
320
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
310
321
|
await (0, git_1.cherrypick)({
|
|
311
322
|
options: { ...options, mainline: 1 },
|
|
312
323
|
sha: 'abcd',
|
|
313
324
|
commitAuthor,
|
|
314
325
|
});
|
|
315
|
-
|
|
326
|
+
const args = spawnSpy.mock.calls[0];
|
|
327
|
+
expect(args).toEqual([
|
|
328
|
+
'git',
|
|
329
|
+
[
|
|
330
|
+
'-c',
|
|
331
|
+
'user.name="Soren L"',
|
|
332
|
+
'-c',
|
|
333
|
+
'user.email="soren@mail.dk"',
|
|
334
|
+
'cherry-pick',
|
|
335
|
+
'--mainline',
|
|
336
|
+
'1',
|
|
337
|
+
'-x',
|
|
338
|
+
'abcd',
|
|
339
|
+
],
|
|
340
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
341
|
+
]);
|
|
316
342
|
});
|
|
317
343
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
318
344
|
jest
|
|
319
|
-
.spyOn(childProcess, '
|
|
320
|
-
// mock getIsMergeCommit(...)
|
|
321
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
345
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
346
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
322
347
|
// mock `git cherrypick`
|
|
323
|
-
.mockRejectedValueOnce(new
|
|
324
|
-
killed: false,
|
|
348
|
+
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
325
349
|
code: 128,
|
|
326
|
-
|
|
350
|
+
cmdArgs: ['cherry-pick', '-x', 'abcd'],
|
|
327
351
|
stdout: '',
|
|
328
352
|
stderr: '',
|
|
329
353
|
}))
|
|
330
354
|
// mock getConflictingFiles
|
|
331
|
-
.mockRejectedValueOnce(new
|
|
355
|
+
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
332
356
|
code: 2,
|
|
333
|
-
|
|
357
|
+
cmdArgs: ['--no-pager', 'diff', '--check'],
|
|
334
358
|
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
335
359
|
stderr: '',
|
|
336
360
|
}))
|
|
337
361
|
// mock getUnstagedFiles
|
|
338
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
362
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
339
363
|
expect(await (0, git_1.cherrypick)({
|
|
340
364
|
options,
|
|
341
365
|
sha: 'abcd',
|
|
@@ -353,15 +377,13 @@ describe('cherrypick', () => {
|
|
|
353
377
|
});
|
|
354
378
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
355
379
|
jest
|
|
356
|
-
.spyOn(childProcess, '
|
|
380
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
357
381
|
// mock getIsMergeCommit(...)
|
|
358
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
382
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
359
383
|
// mock cherry pick command
|
|
360
|
-
.mockRejectedValueOnce(new
|
|
361
|
-
killed: false,
|
|
384
|
+
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
362
385
|
code: 128,
|
|
363
|
-
|
|
364
|
-
cmd: 'git cherry-pick 381c7b604110257437a289b1f1742685eb8d79c5',
|
|
386
|
+
cmdArgs: ['cherry-pick', '381c7b604110257437a289b1f1742685eb8d79c5'],
|
|
365
387
|
stdout: '',
|
|
366
388
|
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
367
389
|
}));
|
|
@@ -382,15 +404,13 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
382
404
|
});
|
|
383
405
|
it('should gracefully handle empty commits', async () => {
|
|
384
406
|
jest
|
|
385
|
-
.spyOn(childProcess, '
|
|
407
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
386
408
|
// mock getIsMergeCommit(...)
|
|
387
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
409
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
388
410
|
// mock cherry pick command
|
|
389
|
-
.mockRejectedValueOnce(new
|
|
390
|
-
killed: false,
|
|
411
|
+
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
391
412
|
code: 1,
|
|
392
|
-
|
|
393
|
-
cmd: 'git cherry-pick fe6b13b83cc010f722548cd5a0a8c2d5341a20dd',
|
|
413
|
+
cmdArgs: ['cherry-pick', 'fe6b13b83cc010f722548cd5a0a8c2d5341a20dd'],
|
|
394
414
|
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
395
415
|
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",
|
|
396
416
|
}));
|
|
@@ -400,51 +420,17 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
400
420
|
commitAuthor,
|
|
401
421
|
})).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
|
|
402
422
|
});
|
|
403
|
-
it('gracefully handles missing git info', async () => {
|
|
404
|
-
jest
|
|
405
|
-
.spyOn(childProcess, 'exec')
|
|
406
|
-
// mock getIsMergeCommit(...)
|
|
407
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
408
|
-
// mock cherry pick command
|
|
409
|
-
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
410
|
-
killed: false,
|
|
411
|
-
code: 128,
|
|
412
|
-
signal: null,
|
|
413
|
-
cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
|
|
414
|
-
stdout: '',
|
|
415
|
-
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',
|
|
416
|
-
}));
|
|
417
|
-
await expect((0, git_1.cherrypick)({
|
|
418
|
-
options,
|
|
419
|
-
sha: 'abcd',
|
|
420
|
-
commitAuthor,
|
|
421
|
-
})).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
422
|
-
"
|
|
423
|
-
*** Please tell me who you are.
|
|
424
|
-
|
|
425
|
-
Run
|
|
426
|
-
|
|
427
|
-
git config --global user.email \\"you@example.com\\"
|
|
428
|
-
git config --global user.name \\"Your Name\\"
|
|
429
|
-
|
|
430
|
-
to set your account's default identity.
|
|
431
|
-
Omit --global to set the identity only in this repository.
|
|
432
|
-
|
|
433
|
-
fatal: empty ident name (for <foo@bar.net>) not allowed
|
|
434
|
-
"
|
|
435
|
-
`);
|
|
436
|
-
});
|
|
437
423
|
it('should re-throw non-cherrypick errors', async () => {
|
|
438
424
|
jest
|
|
439
|
-
.spyOn(childProcess, '
|
|
425
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
440
426
|
// mock getIsMergeCommit(...)
|
|
441
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
427
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
442
428
|
// mock cherry pick command
|
|
443
429
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
444
430
|
// getConflictingFiles
|
|
445
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
431
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] })
|
|
446
432
|
// getUnstagedFiles
|
|
447
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
433
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
448
434
|
await expect((0, git_1.cherrypick)({
|
|
449
435
|
options,
|
|
450
436
|
sha: 'abcd',
|
|
@@ -469,44 +455,45 @@ describe('commitChanges', () => {
|
|
|
469
455
|
};
|
|
470
456
|
it('should return when changes committed successfully', async () => {
|
|
471
457
|
jest
|
|
472
|
-
.spyOn(childProcess, '
|
|
473
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
458
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
459
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
474
460
|
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
475
461
|
});
|
|
476
462
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
477
|
-
const err = {
|
|
478
|
-
killed: false,
|
|
463
|
+
const err = new childProcess.SpawnError({
|
|
479
464
|
code: 1,
|
|
480
|
-
|
|
481
|
-
cmd: 'git commit --no-edit',
|
|
465
|
+
cmdArgs: ['commit', '--no-edit'],
|
|
482
466
|
stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
|
|
483
467
|
stderr: '',
|
|
484
|
-
};
|
|
485
|
-
jest.spyOn(childProcess, '
|
|
468
|
+
});
|
|
469
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
486
470
|
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
487
471
|
});
|
|
488
472
|
describe('when commit fails due to empty message', () => {
|
|
489
473
|
let spy;
|
|
490
474
|
let res;
|
|
491
475
|
beforeEach(async () => {
|
|
492
|
-
const err = {
|
|
493
|
-
killed: false,
|
|
476
|
+
const err = new childProcess.SpawnError({
|
|
494
477
|
code: 1,
|
|
495
|
-
|
|
496
|
-
cmd: 'git commit --no-edit --no-verify',
|
|
478
|
+
cmdArgs: ['commit', '--no-edit', '--no-verify'],
|
|
497
479
|
stdout: '',
|
|
498
480
|
stderr: 'Aborting commit due to empty commit message.\n',
|
|
499
|
-
};
|
|
481
|
+
});
|
|
500
482
|
spy = jest
|
|
501
|
-
.spyOn(childProcess, '
|
|
483
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
502
484
|
.mockRejectedValueOnce(err)
|
|
503
|
-
.mockResolvedValueOnce({
|
|
485
|
+
.mockResolvedValueOnce({
|
|
486
|
+
stderr: '',
|
|
487
|
+
stdout: '',
|
|
488
|
+
code: 0,
|
|
489
|
+
cmdArgs: [],
|
|
490
|
+
});
|
|
504
491
|
res = await (0, git_1.commitChanges)(commit, options);
|
|
505
492
|
});
|
|
506
493
|
it('should manually set the commit message', () => {
|
|
507
494
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
508
|
-
expect(spy).toHaveBeenCalledWith('git commit --no-edit', expect.any(
|
|
509
|
-
expect(spy).toHaveBeenCalledWith('git commit
|
|
495
|
+
expect(spy).toHaveBeenCalledWith('git', ['commit', '--no-edit'], expect.any(String));
|
|
496
|
+
expect(spy).toHaveBeenCalledWith('git', ['commit', '--message=The original commit message'], expect.any(String));
|
|
510
497
|
});
|
|
511
498
|
it('should handle the error and resolve successfully', async () => {
|
|
512
499
|
await expect(res).toBe(undefined);
|
|
@@ -514,7 +501,7 @@ describe('commitChanges', () => {
|
|
|
514
501
|
});
|
|
515
502
|
it('should re-throw other errors', async () => {
|
|
516
503
|
const err = new Error('another error');
|
|
517
|
-
jest.spyOn(childProcess, '
|
|
504
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
518
505
|
expect.assertions(1);
|
|
519
506
|
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
520
507
|
});
|
|
@@ -528,24 +515,39 @@ describe('addRemote', () => {
|
|
|
528
515
|
};
|
|
529
516
|
it('add correct origin remote', async () => {
|
|
530
517
|
const spy = jest
|
|
531
|
-
.spyOn(childProcess, '
|
|
532
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
518
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
519
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
533
520
|
await (0, git_1.addRemote)(options, 'elastic');
|
|
534
|
-
return expect(spy).toHaveBeenCalledWith('git
|
|
521
|
+
return expect(spy).toHaveBeenCalledWith('git', [
|
|
522
|
+
'remote',
|
|
523
|
+
'add',
|
|
524
|
+
'elastic',
|
|
525
|
+
'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
526
|
+
], '/myHomeDir/.backport/repositories/elastic/kibana');
|
|
535
527
|
});
|
|
536
528
|
it('add correct user remote', async () => {
|
|
537
529
|
const spy = jest
|
|
538
|
-
.spyOn(childProcess, '
|
|
539
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
530
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
531
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
540
532
|
await (0, git_1.addRemote)(options, 'sqren');
|
|
541
|
-
return expect(spy).toHaveBeenCalledWith('git
|
|
533
|
+
return expect(spy).toHaveBeenCalledWith('git', [
|
|
534
|
+
'remote',
|
|
535
|
+
'add',
|
|
536
|
+
'sqren',
|
|
537
|
+
'https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
|
|
538
|
+
], '/myHomeDir/.backport/repositories/elastic/kibana');
|
|
542
539
|
});
|
|
543
540
|
it('allows custom github url', async () => {
|
|
544
541
|
const spy = jest
|
|
545
|
-
.spyOn(childProcess, '
|
|
546
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
542
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
543
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
547
544
|
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
548
|
-
return expect(spy).toHaveBeenCalledWith('git
|
|
545
|
+
return expect(spy).toHaveBeenCalledWith('git', [
|
|
546
|
+
'remote',
|
|
547
|
+
'add',
|
|
548
|
+
'sqren',
|
|
549
|
+
'https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git',
|
|
550
|
+
], '/myHomeDir/.backport/repositories/elastic/kibana');
|
|
549
551
|
});
|
|
550
552
|
});
|
|
551
553
|
describe('pushBackportBranch', () => {
|
|
@@ -558,14 +560,21 @@ describe('pushBackportBranch', () => {
|
|
|
558
560
|
};
|
|
559
561
|
const backportBranch = 'backport/7.x/pr-2';
|
|
560
562
|
it('should handle missing fork error', async () => {
|
|
561
|
-
jest.spyOn(childProcess, '
|
|
562
|
-
killed: false,
|
|
563
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(new childProcess.SpawnError({
|
|
563
564
|
code: 128,
|
|
564
|
-
|
|
565
|
-
|
|
565
|
+
cmdArgs: [
|
|
566
|
+
'push',
|
|
567
|
+
'sqren',
|
|
568
|
+
'backport/7.x/pr-2:backport/7.x/pr-2',
|
|
569
|
+
'--force',
|
|
570
|
+
],
|
|
566
571
|
stdout: '',
|
|
567
572
|
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
568
|
-
});
|
|
569
|
-
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects
|
|
573
|
+
}));
|
|
574
|
+
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects
|
|
575
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
576
|
+
"Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the repository (https://github.com/elastic/kibana) or disable fork mode via \\"--no-fork\\".
|
|
577
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/configuration.md#fork"
|
|
578
|
+
`);
|
|
570
579
|
});
|
|
571
580
|
});
|
|
@@ -26,7 +26,7 @@ async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwn
|
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
28
|
spinner.fail();
|
|
29
|
-
logger_1.logger.info(`Could not add assignees to PR ${pullNumber}`, e
|
|
29
|
+
logger_1.logger.info(`Could not add assignees to PR ${pullNumber}`, e);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.addAssigneesToPullRequest = addAssigneesToPullRequest;
|
|
@@ -24,7 +24,7 @@ async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner,
|
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
spinner.fail();
|
|
27
|
-
logger_1.logger.info(`Could not add labels to PR ${pullNumber}`, e
|
|
27
|
+
logger_1.logger.info(`Could not add labels to PR ${pullNumber}`, e);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.addLabelsToPullRequest = addLabelsToPullRequest;
|
|
@@ -23,9 +23,10 @@ async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwn
|
|
|
23
23
|
spinner.succeed();
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
|
+
//@ts-expect-error
|
|
26
27
|
const message = e.response?.data?.message;
|
|
27
28
|
spinner.fail(`Adding reviewers. ${message ? message : ''}`);
|
|
28
|
-
logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e
|
|
29
|
+
logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
exports.addReviewersToPullRequest = addReviewersToPullRequest;
|