backport 7.2.0 → 7.3.1
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 +12 -5
- package/dist/backportRun.js +12 -1
- package/dist/entrypoint.cli.d.ts +0 -1
- package/dist/entrypoint.cli.js +0 -1
- package/dist/entrypoint.cli.private.test.js +1 -0
- package/dist/options/ConfigOptions.d.ts +3 -1
- package/dist/options/cliArgs.d.ts +3 -1
- package/dist/options/cliArgs.js +16 -7
- package/dist/options/config/config.d.ts +3 -1
- package/dist/options/config/readConfigFile.d.ts +3 -1
- package/dist/options/options.d.ts +3 -1
- package/dist/options/options.js +3 -1
- package/dist/options/options.test.js +2 -1
- package/dist/runSequentially.d.ts +3 -1
- package/dist/runSequentially.js +2 -3
- package/dist/services/git.d.ts +15 -7
- package/dist/services/git.integration.test.js +38 -58
- package/dist/services/git.js +21 -28
- package/dist/services/git.test.js +56 -17
- package/dist/services/github/v3/createPullRequest.test.js +52 -0
- package/dist/services/github/v3/createStatusComment.test.js +12 -2
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -3
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
- package/dist/services/prompt.test.js +5 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
- package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/cli.private.test.js +219 -0
- package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
- package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/module.mutation.test.js +369 -0
- package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
- package/dist/test/e2e/module.e2e.private.test.js +6 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +29 -10
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +38 -25
- package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
- package/dist/ui/getGitConfigAuthor.d.ts +6 -0
- package/dist/ui/getGitConfigAuthor.js +15 -0
- package/dist/ui/getTargetBranches.test.js +2 -0
- package/dist/ui/setupRepo.d.ts +2 -0
- package/dist/ui/setupRepo.js +56 -0
- package/dist/ui/setupRepo.test.d.ts +1 -0
- package/dist/ui/setupRepo.test.js +236 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +11 -11
- package/yarn.lock +61 -81
package/dist/services/git.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLocalRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
const ora_1 = require("../ui/ora");
|
|
@@ -9,7 +9,6 @@ const HandledError_1 = require("./HandledError");
|
|
|
9
9
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
10
10
|
const env_1 = require("./env");
|
|
11
11
|
const commitFormatters_1 = require("./github/commitFormatters");
|
|
12
|
-
const getRepoOwnerAndNameFromGitRemotes_1 = require("./github/v4/getRepoOwnerAndNameFromGitRemotes");
|
|
13
12
|
const logger_1 = require("./logger");
|
|
14
13
|
function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, repoOwner) {
|
|
15
14
|
return `https://x-access-token:${accessToken}@${gitHostname}/${repoOwner}/${repoName}.git`;
|
|
@@ -85,7 +84,7 @@ async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
|
85
84
|
const remotes = stdout
|
|
86
85
|
.split('\n')
|
|
87
86
|
.map((line) => {
|
|
88
|
-
const match = line.match(
|
|
87
|
+
const match = line.match(/github.com[/|:](.+?)(.git)? \((fetch|push)\)/);
|
|
89
88
|
return match?.[1];
|
|
90
89
|
})
|
|
91
90
|
.filter(filterEmpty_1.filterNil);
|
|
@@ -99,7 +98,7 @@ async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
exports.getRepoInfoFromGitRemotes = getRepoInfoFromGitRemotes;
|
|
102
|
-
async function
|
|
101
|
+
async function getGitProjectRootPath(dir) {
|
|
103
102
|
try {
|
|
104
103
|
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
105
104
|
cwd: dir,
|
|
@@ -111,7 +110,7 @@ async function getGitProjectRoot(dir) {
|
|
|
111
110
|
return;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
|
-
exports.
|
|
113
|
+
exports.getGitProjectRootPath = getGitProjectRootPath;
|
|
115
114
|
async function getIsCommitInBranch(options, commitSha) {
|
|
116
115
|
try {
|
|
117
116
|
await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
|
|
@@ -181,7 +180,7 @@ async function getCommitsInMergeCommit(options, sha) {
|
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
|
|
184
|
-
async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
183
|
+
async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
|
|
185
184
|
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
186
185
|
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
187
186
|
let shaOrRange = sha;
|
|
@@ -201,7 +200,7 @@ async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
|
-
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
|
|
203
|
+
const cmd = `git -c user.name="${commitAuthor.name}" -c user.email="${commitAuthor.email}" cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
|
|
205
204
|
try {
|
|
206
205
|
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
207
206
|
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
@@ -220,12 +219,12 @@ async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
|
220
219
|
}
|
|
221
220
|
// git info missing
|
|
222
221
|
if (e.message.includes('Please tell me who you are')) {
|
|
223
|
-
throw new HandledError_1.HandledError(
|
|
222
|
+
throw new HandledError_1.HandledError(e.message);
|
|
224
223
|
}
|
|
225
224
|
if (e.message.includes(`bad object ${sha}`)) {
|
|
226
225
|
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
|
|
227
226
|
}
|
|
228
|
-
const isCherryPickError = e.cmd
|
|
227
|
+
const isCherryPickError = e.cmd?.includes('cherry-pick') && e.code > 0;
|
|
229
228
|
if (isCherryPickError) {
|
|
230
229
|
const [conflictingFiles, unstagedFiles] = await Promise.all([
|
|
231
230
|
getConflictingFiles(options),
|
|
@@ -307,19 +306,16 @@ async function getUnstagedFiles(options) {
|
|
|
307
306
|
return (0, lodash_1.uniq)(files);
|
|
308
307
|
}
|
|
309
308
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
310
|
-
async function
|
|
311
|
-
const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
|
|
309
|
+
async function getGitConfig({ dir, key, }) {
|
|
312
310
|
try {
|
|
313
|
-
const res = await (0, child_process_promisified_1.exec)(`git
|
|
314
|
-
|
|
315
|
-
return res;
|
|
311
|
+
const res = await (0, child_process_promisified_1.exec)(`git config ${key}`, { cwd: dir });
|
|
312
|
+
return res.stdout;
|
|
316
313
|
}
|
|
317
314
|
catch (e) {
|
|
318
|
-
|
|
319
|
-
throw e;
|
|
315
|
+
return;
|
|
320
316
|
}
|
|
321
317
|
}
|
|
322
|
-
exports.
|
|
318
|
+
exports.getGitConfig = getGitConfig;
|
|
323
319
|
// How the commit flows:
|
|
324
320
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
325
321
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
@@ -351,7 +347,7 @@ exports.deleteBackportBranch = deleteBackportBranch;
|
|
|
351
347
|
* Returns the repo owner of the forked repo or the source repo
|
|
352
348
|
*/
|
|
353
349
|
function getRepoForkOwner(options) {
|
|
354
|
-
return options.fork ? options.
|
|
350
|
+
return options.fork ? options.repoForkOwner : options.repoOwner;
|
|
355
351
|
}
|
|
356
352
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
357
353
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
@@ -371,14 +367,11 @@ async function pushBackportBranch({ options, backportBranch, }) {
|
|
|
371
367
|
}
|
|
372
368
|
}
|
|
373
369
|
exports.pushBackportBranch = pushBackportBranch;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
? (await getGitProjectRoot(options.cwd)) ?? remoteUrl
|
|
381
|
-
: remoteUrl;
|
|
382
|
-
return sourcePath;
|
|
370
|
+
// retrieve path to local repo (cwd) if it matches `repoName` / `repoOwner`
|
|
371
|
+
async function getLocalRepoPath(options) {
|
|
372
|
+
const remotes = await getRepoInfoFromGitRemotes({ cwd: options.cwd });
|
|
373
|
+
const hasMatchingGitRemote = remotes.some((remote) => remote.repoName === options.repoName &&
|
|
374
|
+
remote.repoOwner === options.repoOwner);
|
|
375
|
+
return hasMatchingGitRemote ? getGitProjectRootPath(options.cwd) : undefined;
|
|
383
376
|
}
|
|
384
|
-
exports.
|
|
377
|
+
exports.getLocalRepoPath = getLocalRepoPath;
|
|
@@ -32,6 +32,7 @@ beforeEach(() => {
|
|
|
32
32
|
afterEach(() => {
|
|
33
33
|
jest.restoreAllMocks();
|
|
34
34
|
});
|
|
35
|
+
const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
|
|
35
36
|
describe('getUnstagedFiles', () => {
|
|
36
37
|
it('should split lines and remove empty', async () => {
|
|
37
38
|
jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
|
|
@@ -140,7 +141,7 @@ describe('isLocalConfigFileModified', () => {
|
|
|
140
141
|
});
|
|
141
142
|
});
|
|
142
143
|
describe('getRepoInfoFromGitRemotes', () => {
|
|
143
|
-
it('returns repoName and repoOwner
|
|
144
|
+
it('returns repoName and repoOwner ssh remotes', async () => {
|
|
144
145
|
const res = {
|
|
145
146
|
stdout: 'john.doe\tgit@github.com:john.doe/kibana (fetch)\n' +
|
|
146
147
|
'john.doe\tgit@github.com:john.doe/kibana (push)\n' +
|
|
@@ -160,6 +161,16 @@ describe('getRepoInfoFromGitRemotes', () => {
|
|
|
160
161
|
{ repoName: 'kibana', repoOwner: 'sqren' },
|
|
161
162
|
]);
|
|
162
163
|
});
|
|
164
|
+
it('returns repoName and repoOwner https remotes', async () => {
|
|
165
|
+
jest.spyOn(childProcess, 'exec').mockResolvedValue({
|
|
166
|
+
stdout: 'origin\thttps://github.com/shay/elasticsearch.git (fetch)\n' +
|
|
167
|
+
'origin\thttps://github.com/shay/elasticsearch.git (push)\n',
|
|
168
|
+
stderr: '',
|
|
169
|
+
});
|
|
170
|
+
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
171
|
+
{ repoName: 'elasticsearch', repoOwner: 'shay' },
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
163
174
|
it('returns undefined when no remotes exist', async () => {
|
|
164
175
|
const res = { stdout: '', stderr: '' };
|
|
165
176
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
@@ -279,7 +290,11 @@ describe('cherrypick', () => {
|
|
|
279
290
|
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
280
291
|
// mock cherrypick(...)
|
|
281
292
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
282
|
-
expect(await (0, git_1.cherrypick)(
|
|
293
|
+
expect(await (0, git_1.cherrypick)({
|
|
294
|
+
options,
|
|
295
|
+
sha: 'abcd',
|
|
296
|
+
commitAuthor,
|
|
297
|
+
})).toEqual({
|
|
283
298
|
conflictingFiles: [],
|
|
284
299
|
unstagedFiles: [],
|
|
285
300
|
needsResolving: false,
|
|
@@ -292,15 +307,19 @@ describe('cherrypick', () => {
|
|
|
292
307
|
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
293
308
|
// mock cherry pick command
|
|
294
309
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
295
|
-
await (0, git_1.cherrypick)({
|
|
296
|
-
|
|
310
|
+
await (0, git_1.cherrypick)({
|
|
311
|
+
options: { ...options, mainline: 1 },
|
|
312
|
+
sha: 'abcd',
|
|
313
|
+
commitAuthor,
|
|
314
|
+
});
|
|
315
|
+
expect(execSpy.mock.calls[0][0]).toBe('git -c user.name="Soren L" -c user.email="soren@mail.dk" cherry-pick -x --mainline 1 abcd');
|
|
297
316
|
});
|
|
298
317
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
299
318
|
jest
|
|
300
319
|
.spyOn(childProcess, 'exec')
|
|
301
320
|
// mock getIsMergeCommit(...)
|
|
302
321
|
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
303
|
-
// mock
|
|
322
|
+
// mock `git cherrypick`
|
|
304
323
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
305
324
|
killed: false,
|
|
306
325
|
code: 128,
|
|
@@ -317,7 +336,11 @@ describe('cherrypick', () => {
|
|
|
317
336
|
}))
|
|
318
337
|
// mock getUnstagedFiles
|
|
319
338
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
320
|
-
expect(await (0, git_1.cherrypick)(
|
|
339
|
+
expect(await (0, git_1.cherrypick)({
|
|
340
|
+
options,
|
|
341
|
+
sha: 'abcd',
|
|
342
|
+
commitAuthor,
|
|
343
|
+
})).toEqual({
|
|
321
344
|
conflictingFiles: [
|
|
322
345
|
{
|
|
323
346
|
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
@@ -342,7 +365,11 @@ describe('cherrypick', () => {
|
|
|
342
365
|
stdout: '',
|
|
343
366
|
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
344
367
|
}));
|
|
345
|
-
await expect((0, git_1.cherrypick)(
|
|
368
|
+
await expect((0, git_1.cherrypick)({
|
|
369
|
+
options,
|
|
370
|
+
sha: 'abcd',
|
|
371
|
+
commitAuthor,
|
|
372
|
+
})).rejects
|
|
346
373
|
.toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
|
|
347
374
|
|
|
348
375
|
> backport --mainline
|
|
@@ -367,7 +394,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
367
394
|
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
368
395
|
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",
|
|
369
396
|
}));
|
|
370
|
-
await expect((0, git_1.cherrypick)(
|
|
397
|
+
await expect((0, git_1.cherrypick)({
|
|
398
|
+
options,
|
|
399
|
+
sha: 'abcd',
|
|
400
|
+
commitAuthor,
|
|
401
|
+
})).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
|
|
371
402
|
});
|
|
372
403
|
it('gracefully handles missing git info', async () => {
|
|
373
404
|
jest
|
|
@@ -383,10 +414,12 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
383
414
|
stdout: '',
|
|
384
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',
|
|
385
416
|
}));
|
|
386
|
-
await expect((0, git_1.cherrypick)(
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
417
|
+
await expect((0, git_1.cherrypick)({
|
|
418
|
+
options,
|
|
419
|
+
sha: 'abcd',
|
|
420
|
+
commitAuthor,
|
|
421
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
422
|
+
"
|
|
390
423
|
*** Please tell me who you are.
|
|
391
424
|
|
|
392
425
|
Run
|
|
@@ -412,7 +445,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
412
445
|
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
413
446
|
// getUnstagedFiles
|
|
414
447
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
415
|
-
await expect((0, git_1.cherrypick)(
|
|
448
|
+
await expect((0, git_1.cherrypick)({
|
|
449
|
+
options,
|
|
450
|
+
sha: 'abcd',
|
|
451
|
+
commitAuthor,
|
|
452
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
416
453
|
});
|
|
417
454
|
});
|
|
418
455
|
describe('commitChanges', () => {
|
|
@@ -421,6 +458,7 @@ describe('commitChanges', () => {
|
|
|
421
458
|
repoName: 'kibana',
|
|
422
459
|
};
|
|
423
460
|
const commit = {
|
|
461
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
424
462
|
sourceCommit: {
|
|
425
463
|
message: 'The original commit message',
|
|
426
464
|
committedDate: '2020',
|
|
@@ -475,10 +513,10 @@ describe('commitChanges', () => {
|
|
|
475
513
|
});
|
|
476
514
|
});
|
|
477
515
|
it('should re-throw other errors', async () => {
|
|
478
|
-
const err = new Error('
|
|
516
|
+
const err = new Error('another error');
|
|
479
517
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
480
518
|
expect.assertions(1);
|
|
481
|
-
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"
|
|
519
|
+
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
482
520
|
});
|
|
483
521
|
});
|
|
484
522
|
describe('addRemote', () => {
|
|
@@ -514,8 +552,9 @@ describe('pushBackportBranch', () => {
|
|
|
514
552
|
const options = {
|
|
515
553
|
authenticatedUsername: 'sqren_authenticated',
|
|
516
554
|
fork: true,
|
|
517
|
-
|
|
555
|
+
repoForkOwner: 'the_fork_owner',
|
|
518
556
|
repoName: 'kibana',
|
|
557
|
+
repoOwner: 'elastic',
|
|
519
558
|
};
|
|
520
559
|
const backportBranch = 'backport/7.x/pr-2';
|
|
521
560
|
it('should handle missing fork error', async () => {
|
|
@@ -527,6 +566,6 @@ describe('pushBackportBranch', () => {
|
|
|
527
566
|
stdout: '',
|
|
528
567
|
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
529
568
|
});
|
|
530
|
-
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/
|
|
569
|
+
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/the_fork_owner/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"`);
|
|
531
570
|
});
|
|
532
571
|
});
|
|
@@ -7,6 +7,10 @@ describe('getPullRequestBody', () => {
|
|
|
7
7
|
options: {},
|
|
8
8
|
commits: [
|
|
9
9
|
{
|
|
10
|
+
author: {
|
|
11
|
+
email: 'soren.louv@elastic.co',
|
|
12
|
+
name: 'Søren Louv-Jansen',
|
|
13
|
+
},
|
|
10
14
|
sourcePullRequest: {
|
|
11
15
|
number: 55,
|
|
12
16
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
|
|
@@ -42,6 +46,10 @@ describe('getPullRequestBody', () => {
|
|
|
42
46
|
options: {},
|
|
43
47
|
commits: [
|
|
44
48
|
{
|
|
49
|
+
author: {
|
|
50
|
+
email: 'soren.louv@elastic.co',
|
|
51
|
+
name: 'Søren Louv-Jansen',
|
|
52
|
+
},
|
|
45
53
|
sourceCommit: {
|
|
46
54
|
committedDate: '',
|
|
47
55
|
sha: 'abcdefghijklmw',
|
|
@@ -69,6 +77,10 @@ describe('getPullRequestBody', () => {
|
|
|
69
77
|
options: {},
|
|
70
78
|
commits: [
|
|
71
79
|
{
|
|
80
|
+
author: {
|
|
81
|
+
email: 'soren.louv@elastic.co',
|
|
82
|
+
name: 'Søren Louv-Jansen',
|
|
83
|
+
},
|
|
72
84
|
sourcePullRequest: {
|
|
73
85
|
number: 55,
|
|
74
86
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
|
|
@@ -86,6 +98,10 @@ describe('getPullRequestBody', () => {
|
|
|
86
98
|
expectedTargetPullRequests: [],
|
|
87
99
|
},
|
|
88
100
|
{
|
|
101
|
+
author: {
|
|
102
|
+
email: 'soren.louv@elastic.co',
|
|
103
|
+
name: 'Søren Louv-Jansen',
|
|
104
|
+
},
|
|
89
105
|
sourceCommit: {
|
|
90
106
|
committedDate: '',
|
|
91
107
|
sha: 'qwertyuiop',
|
|
@@ -119,6 +135,10 @@ describe('getPullRequestBody', () => {
|
|
|
119
135
|
message: 'Merge strategy: Second commit',
|
|
120
136
|
sha: 'e8df5eaa4db7b94474b48e2320b02d33a830d9fb',
|
|
121
137
|
},
|
|
138
|
+
author: {
|
|
139
|
+
email: 'soren.louv@elastic.co',
|
|
140
|
+
name: 'Søren Louv-Jansen',
|
|
141
|
+
},
|
|
122
142
|
sourcePullRequest: {
|
|
123
143
|
number: 1,
|
|
124
144
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
|
|
@@ -136,6 +156,10 @@ describe('getPullRequestBody', () => {
|
|
|
136
156
|
message: 'Merge strategy: First commit',
|
|
137
157
|
sha: '5411b1c1144093e422220008f23f2c2b909ed113',
|
|
138
158
|
},
|
|
159
|
+
author: {
|
|
160
|
+
email: 'soren.louv@elastic.co',
|
|
161
|
+
name: 'Søren Louv-Jansen',
|
|
162
|
+
},
|
|
139
163
|
sourcePullRequest: {
|
|
140
164
|
number: 1,
|
|
141
165
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/1',
|
|
@@ -169,6 +193,10 @@ describe('getPullRequestBody', () => {
|
|
|
169
193
|
},
|
|
170
194
|
commits: [
|
|
171
195
|
{
|
|
196
|
+
author: {
|
|
197
|
+
email: 'soren.louv@elastic.co',
|
|
198
|
+
name: 'Søren Louv-Jansen',
|
|
199
|
+
},
|
|
172
200
|
sourcePullRequest: {
|
|
173
201
|
number: 55,
|
|
174
202
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
|
|
@@ -186,6 +214,10 @@ describe('getPullRequestBody', () => {
|
|
|
186
214
|
expectedTargetPullRequests: [],
|
|
187
215
|
},
|
|
188
216
|
{
|
|
217
|
+
author: {
|
|
218
|
+
email: 'soren.louv@elastic.co',
|
|
219
|
+
name: 'Søren Louv-Jansen',
|
|
220
|
+
},
|
|
189
221
|
sourceCommit: {
|
|
190
222
|
committedDate: '',
|
|
191
223
|
sha: 'qwertyuiop',
|
|
@@ -209,6 +241,10 @@ describe('getPullRequestBody', () => {
|
|
|
209
241
|
},
|
|
210
242
|
commits: [
|
|
211
243
|
{
|
|
244
|
+
author: {
|
|
245
|
+
email: 'soren.louv@elastic.co',
|
|
246
|
+
name: 'Søren Louv-Jansen',
|
|
247
|
+
},
|
|
212
248
|
sourcePullRequest: {
|
|
213
249
|
number: 55,
|
|
214
250
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
|
|
@@ -226,6 +262,10 @@ describe('getPullRequestBody', () => {
|
|
|
226
262
|
expectedTargetPullRequests: [],
|
|
227
263
|
},
|
|
228
264
|
{
|
|
265
|
+
author: {
|
|
266
|
+
email: 'soren.louv@elastic.co',
|
|
267
|
+
name: 'Søren Louv-Jansen',
|
|
268
|
+
},
|
|
229
269
|
sourceCommit: {
|
|
230
270
|
committedDate: '',
|
|
231
271
|
sha: 'qwertyuiop',
|
|
@@ -258,6 +298,10 @@ describe('getTitle', () => {
|
|
|
258
298
|
options: {},
|
|
259
299
|
commits: [
|
|
260
300
|
{
|
|
301
|
+
author: {
|
|
302
|
+
email: 'soren.louv@elastic.co',
|
|
303
|
+
name: 'Søren Louv-Jansen',
|
|
304
|
+
},
|
|
261
305
|
sourceBranch: 'main',
|
|
262
306
|
sourcePullRequest: {
|
|
263
307
|
number: 55,
|
|
@@ -275,6 +319,10 @@ describe('getTitle', () => {
|
|
|
275
319
|
expectedTargetPullRequests: [],
|
|
276
320
|
},
|
|
277
321
|
{
|
|
322
|
+
author: {
|
|
323
|
+
email: 'soren.louv@elastic.co',
|
|
324
|
+
name: 'Søren Louv-Jansen',
|
|
325
|
+
},
|
|
278
326
|
sourcePullRequest: {
|
|
279
327
|
number: 56,
|
|
280
328
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/56',
|
|
@@ -302,6 +350,10 @@ describe('getTitle', () => {
|
|
|
302
350
|
},
|
|
303
351
|
commits: [
|
|
304
352
|
{
|
|
353
|
+
author: {
|
|
354
|
+
email: 'soren.louv@elastic.co',
|
|
355
|
+
name: 'Søren Louv-Jansen',
|
|
356
|
+
},
|
|
305
357
|
sourcePullRequest: {
|
|
306
358
|
number: 55,
|
|
307
359
|
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
|
|
@@ -266,9 +266,13 @@ describe('getCommentBody', () => {
|
|
|
266
266
|
error: new HandledError_1.HandledError({
|
|
267
267
|
code: 'merge-conflict-exception',
|
|
268
268
|
commitsWithoutBackports: [
|
|
269
|
-
//@ts-expect-error
|
|
270
269
|
{
|
|
270
|
+
formatted: 'some-formatted-text',
|
|
271
271
|
commit: {
|
|
272
|
+
author: {
|
|
273
|
+
email: 'soren.louv@elastic.co',
|
|
274
|
+
name: 'Søren Louv-Jansen',
|
|
275
|
+
},
|
|
272
276
|
sourceBranch: 'master',
|
|
273
277
|
sourcePullRequest: {
|
|
274
278
|
number: 5,
|
|
@@ -287,8 +291,13 @@ describe('getCommentBody', () => {
|
|
|
287
291
|
},
|
|
288
292
|
},
|
|
289
293
|
{
|
|
290
|
-
|
|
294
|
+
formatted: 'some-formatted-text',
|
|
291
295
|
commit: {
|
|
296
|
+
author: {
|
|
297
|
+
email: 'soren.louv@elastic.co',
|
|
298
|
+
name: 'Søren Louv-Jansen',
|
|
299
|
+
},
|
|
300
|
+
sourceBranch: 'master',
|
|
292
301
|
sourcePullRequest: {
|
|
293
302
|
number: 44,
|
|
294
303
|
url: 'url-to-pr-44',
|
|
@@ -302,6 +311,7 @@ describe('getCommentBody', () => {
|
|
|
302
311
|
sha: '',
|
|
303
312
|
message: 'Australia commit',
|
|
304
313
|
},
|
|
314
|
+
expectedTargetPullRequests: [],
|
|
305
315
|
},
|
|
306
316
|
},
|
|
307
317
|
],
|
|
@@ -61,6 +61,7 @@ describe('allFetchers', () => {
|
|
|
61
61
|
});
|
|
62
62
|
it('returns correct response for commitByAuthor', async () => {
|
|
63
63
|
const expectedCommit = {
|
|
64
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
64
65
|
sourceCommit: {
|
|
65
66
|
committedDate: '2021-12-20T14:20:16Z',
|
|
66
67
|
message: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
@@ -67,6 +67,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
67
67
|
sourceBranch: 'main',
|
|
68
68
|
};
|
|
69
69
|
const expectedCommit = {
|
|
70
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
70
71
|
sourceCommit: {
|
|
71
72
|
committedDate: '2020-08-15T12:40:19Z',
|
|
72
73
|
message: 'Add 🍏 emoji (#5)',
|
|
@@ -60,6 +60,7 @@ describe('fetchCommitBySha', () => {
|
|
|
60
60
|
});
|
|
61
61
|
it('should return single commit with pull request', async () => {
|
|
62
62
|
const expectedCommit = {
|
|
63
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
63
64
|
sourceCommit: {
|
|
64
65
|
committedDate: '2020-07-07T20:40:28Z',
|
|
65
66
|
message: '[APM] Add API tests (#70740)',
|
|
@@ -46,6 +46,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
46
46
|
it('should return a list of commits with pullNumber and existing backports', () => {
|
|
47
47
|
const expectedCommits = [
|
|
48
48
|
{
|
|
49
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
49
50
|
sourceCommit: {
|
|
50
51
|
committedDate: '2021-12-24T00:00:00Z',
|
|
51
52
|
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
@@ -55,6 +56,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
55
56
|
sourceBranch: 'source-branch-from-options',
|
|
56
57
|
},
|
|
57
58
|
{
|
|
59
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
58
60
|
sourceCommit: {
|
|
59
61
|
committedDate: '2021-12-23T00:00:00Z',
|
|
60
62
|
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
@@ -72,6 +74,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
72
74
|
sourceBranch: 'master',
|
|
73
75
|
},
|
|
74
76
|
{
|
|
77
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
75
78
|
sourceCommit: {
|
|
76
79
|
committedDate: '2021-12-22T00:00:00Z',
|
|
77
80
|
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
@@ -100,6 +103,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
100
103
|
sourceBranch: 'master',
|
|
101
104
|
},
|
|
102
105
|
{
|
|
106
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
103
107
|
sourceCommit: {
|
|
104
108
|
committedDate: '2021-12-21T00:00:00Z',
|
|
105
109
|
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
@@ -109,6 +113,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
109
113
|
sourceBranch: 'source-branch-from-options',
|
|
110
114
|
},
|
|
111
115
|
{
|
|
116
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
112
117
|
sourceCommit: {
|
|
113
118
|
committedDate: '2021-12-20T00:00:00Z',
|
|
114
119
|
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
@@ -34,6 +34,7 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
34
34
|
};
|
|
35
35
|
const expectedCommits = [
|
|
36
36
|
{
|
|
37
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
37
38
|
sourceCommit: {
|
|
38
39
|
committedDate: '2020-08-16T21:44:28Z',
|
|
39
40
|
message: 'Add sheep emoji (#9)',
|
|
@@ -58,6 +59,7 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
58
59
|
],
|
|
59
60
|
},
|
|
60
61
|
{
|
|
62
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
61
63
|
sourceCommit: {
|
|
62
64
|
committedDate: '2020-08-15T12:40:19Z',
|
|
63
65
|
message: 'Add 🍏 emoji (#5)',
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
|
|
2
2
|
export declare function getOptionsFromGithub(options: {
|
|
3
3
|
accessToken: string;
|
|
4
|
+
cwd?: string;
|
|
4
5
|
githubApiBaseUrlV4?: string;
|
|
5
6
|
repoName: string;
|
|
6
7
|
repoOwner: string;
|
|
7
|
-
username?: string;
|
|
8
8
|
skipRemoteConfig?: boolean;
|
|
9
|
-
cwd?: string;
|
|
10
9
|
}): Promise<{
|
|
11
10
|
accessToken?: string | undefined;
|
|
12
11
|
assignees?: string[] | undefined;
|
|
@@ -29,6 +28,8 @@ export declare function getOptionsFromGithub(options: {
|
|
|
29
28
|
dir?: string | undefined;
|
|
30
29
|
editor?: string | undefined;
|
|
31
30
|
fork?: boolean | undefined;
|
|
31
|
+
gitAuthorEmail?: string | undefined;
|
|
32
|
+
gitAuthorName?: string | undefined;
|
|
32
33
|
gitHostname?: string | undefined;
|
|
33
34
|
githubApiBaseUrlV3?: string | undefined;
|
|
34
35
|
githubApiBaseUrlV4?: string | undefined;
|
|
@@ -43,6 +44,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
43
44
|
prTitle?: string | undefined;
|
|
44
45
|
publishStatusComment?: boolean | undefined;
|
|
45
46
|
pullNumber?: number | undefined;
|
|
47
|
+
repoForkOwner?: string | undefined;
|
|
46
48
|
repoName?: string | undefined;
|
|
47
49
|
repoOwner?: string | undefined;
|
|
48
50
|
resetAuthor?: boolean | undefined;
|
|
@@ -54,7 +56,6 @@ export declare function getOptionsFromGithub(options: {
|
|
|
54
56
|
targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
55
57
|
targetBranches?: string[] | undefined;
|
|
56
58
|
targetPRLabels?: string[] | undefined;
|
|
57
|
-
username?: string | undefined;
|
|
58
59
|
verbose?: boolean | undefined;
|
|
59
60
|
help?: boolean | undefined;
|
|
60
61
|
version?: boolean | undefined;
|
|
@@ -32,7 +32,7 @@ async function getOptionsFromGithub(options) {
|
|
|
32
32
|
}
|
|
33
33
|
const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
|
|
34
34
|
return {
|
|
35
|
-
authenticatedUsername:
|
|
35
|
+
authenticatedUsername: res.viewer.login,
|
|
36
36
|
sourceBranch: res.repository.defaultBranchRef.name,
|
|
37
37
|
...remoteConfig,
|
|
38
38
|
};
|
|
@@ -9,6 +9,7 @@ const maybe_1 = require("../../../utils/maybe");
|
|
|
9
9
|
const git_1 = require("../../git");
|
|
10
10
|
const logger_1 = require("../../logger");
|
|
11
11
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
12
|
+
// This method should be used to get the origin owner (instead of a fork owner)
|
|
12
13
|
async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }) {
|
|
13
14
|
const remotes = await (0, git_1.getRepoInfoFromGitRemotes)({ cwd });
|
|
14
15
|
const firstRemote = (0, maybe_1.maybe)(remotes[0]);
|