backport 7.4.0 → 8.2.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 +15 -16
- package/dist/backportRun.d.ts +12 -6
- package/dist/backportRun.js +64 -62
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +14 -20
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/errors/BackportError.d.ts +19 -0
- package/dist/errors/BackportError.js +29 -0
- package/dist/lib/BackportError.d.ts +19 -0
- package/dist/lib/BackportError.js +29 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
- package/dist/lib/child-process-promisified.d.ts +25 -0
- package/dist/lib/child-process-promisified.js +60 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +33 -0
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +26 -0
- package/dist/lib/getCommits.d.ts +2 -0
- package/dist/lib/getCommits.js +75 -0
- package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/lib/getCommitsWithoutBackports.js +68 -0
- package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
- package/dist/lib/getGitConfigAuthor.d.ts +6 -0
- package/dist/lib/getGitConfigAuthor.js +15 -0
- package/dist/lib/getTargetBranches.d.ts +5 -0
- package/dist/lib/getTargetBranches.js +67 -0
- package/dist/lib/getTargetBranches.test.d.ts +1 -0
- package/dist/lib/getTargetBranches.test.js +210 -0
- package/dist/lib/git.d.ts +77 -0
- package/dist/lib/git.js +439 -0
- package/dist/lib/git.private.test.d.ts +1 -0
- package/dist/lib/git.private.test.js +618 -0
- package/dist/lib/git.test.d.ts +1 -0
- package/dist/lib/git.test.js +580 -0
- package/dist/lib/github/commitFormatters.d.ts +3 -0
- package/dist/lib/github/commitFormatters.js +17 -0
- package/dist/lib/github/commitFormatters.test.d.ts +1 -0
- package/dist/lib/github/commitFormatters.test.js +11 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
- package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
- package/dist/lib/github/v3/createPullRequest.js +91 -0
- package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/createPullRequest.test.js +377 -0
- package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
- package/dist/lib/github/v3/createStatusComment.js +138 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +566 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
- package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
- package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
- package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
- package/dist/lib/github/v4/apiRequestV4.js +71 -0
- package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
- package/dist/lib/github/v4/fetchAuthorId.js +28 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/lib/github/v4/validateTargetBranches.d.ts +14 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.js +80 -0
- package/dist/lib/ora.d.ts +2 -0
- package/dist/lib/ora.js +21 -0
- package/dist/lib/prompt.test.d.ts +1 -0
- package/dist/lib/prompt.test.js +139 -0
- package/dist/lib/prompts.d.ts +17 -0
- package/dist/lib/prompts.js +132 -0
- package/dist/lib/remoteConfig.d.ts +20 -0
- package/dist/lib/remoteConfig.js +52 -0
- package/dist/lib/sequentially.d.ts +1 -0
- package/dist/lib/sequentially.js +10 -0
- package/dist/lib/setupRepo.d.ts +2 -0
- package/dist/lib/setupRepo.js +56 -0
- package/dist/lib/setupRepo.test.d.ts +1 -0
- package/dist/lib/setupRepo.test.js +278 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
- package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/options/ConfigOptions.d.ts +4 -2
- package/dist/options/cliArgs.d.ts +14 -6
- package/dist/options/cliArgs.js +50 -22
- package/dist/options/cliArgs.test.js +128 -4
- package/dist/options/config/config.d.ts +5 -4
- package/dist/options/config/config.js +3 -5
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +5 -3
- package/dist/options/config/globalConfig.js +17 -14
- package/dist/options/config/readConfigFile.d.ts +5 -3
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +41 -5
- package/dist/options/options.js +24 -24
- package/dist/options/options.test.js +117 -55
- package/dist/runSequentially.d.ts +14 -9
- package/dist/runSequentially.js +27 -12
- package/dist/scripts/postinstall.js +4 -3
- package/dist/scripts/postinstall.test.js +6 -2
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +2 -2
- package/dist/services/HandledError.js +7 -7
- 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 +189 -123
- 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 -124
- 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 +4 -2
- package/dist/services/github/v3/createStatusComment.js +16 -17
- package/dist/services/github/v3/createStatusComment.test.js +20 -9
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +53 -75
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +28 -29
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +28 -21
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +3 -3
- 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 +19 -19
- package/yarn.lock +472 -701
|
@@ -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
|
}));
|
|
@@ -402,15 +422,15 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
402
422
|
});
|
|
403
423
|
it('should re-throw non-cherrypick errors', async () => {
|
|
404
424
|
jest
|
|
405
|
-
.spyOn(childProcess, '
|
|
425
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
406
426
|
// mock getIsMergeCommit(...)
|
|
407
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
427
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
408
428
|
// mock cherry pick command
|
|
409
429
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
410
430
|
// getConflictingFiles
|
|
411
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
431
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] })
|
|
412
432
|
// getUnstagedFiles
|
|
413
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
433
|
+
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
414
434
|
await expect((0, git_1.cherrypick)({
|
|
415
435
|
options,
|
|
416
436
|
sha: 'abcd',
|
|
@@ -435,44 +455,45 @@ describe('commitChanges', () => {
|
|
|
435
455
|
};
|
|
436
456
|
it('should return when changes committed successfully', async () => {
|
|
437
457
|
jest
|
|
438
|
-
.spyOn(childProcess, '
|
|
439
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
458
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
459
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
440
460
|
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
441
461
|
});
|
|
442
462
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
443
|
-
const err = {
|
|
444
|
-
killed: false,
|
|
463
|
+
const err = new childProcess.SpawnError({
|
|
445
464
|
code: 1,
|
|
446
|
-
|
|
447
|
-
cmd: 'git commit --no-edit',
|
|
465
|
+
cmdArgs: ['commit', '--no-edit'],
|
|
448
466
|
stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
|
|
449
467
|
stderr: '',
|
|
450
|
-
};
|
|
451
|
-
jest.spyOn(childProcess, '
|
|
468
|
+
});
|
|
469
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
452
470
|
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
453
471
|
});
|
|
454
472
|
describe('when commit fails due to empty message', () => {
|
|
455
473
|
let spy;
|
|
456
474
|
let res;
|
|
457
475
|
beforeEach(async () => {
|
|
458
|
-
const err = {
|
|
459
|
-
killed: false,
|
|
476
|
+
const err = new childProcess.SpawnError({
|
|
460
477
|
code: 1,
|
|
461
|
-
|
|
462
|
-
cmd: 'git commit --no-edit --no-verify',
|
|
478
|
+
cmdArgs: ['commit', '--no-edit', '--no-verify'],
|
|
463
479
|
stdout: '',
|
|
464
480
|
stderr: 'Aborting commit due to empty commit message.\n',
|
|
465
|
-
};
|
|
481
|
+
});
|
|
466
482
|
spy = jest
|
|
467
|
-
.spyOn(childProcess, '
|
|
483
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
468
484
|
.mockRejectedValueOnce(err)
|
|
469
|
-
.mockResolvedValueOnce({
|
|
485
|
+
.mockResolvedValueOnce({
|
|
486
|
+
stderr: '',
|
|
487
|
+
stdout: '',
|
|
488
|
+
code: 0,
|
|
489
|
+
cmdArgs: [],
|
|
490
|
+
});
|
|
470
491
|
res = await (0, git_1.commitChanges)(commit, options);
|
|
471
492
|
});
|
|
472
493
|
it('should manually set the commit message', () => {
|
|
473
494
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
474
|
-
expect(spy).toHaveBeenCalledWith('git commit --no-edit', expect.any(
|
|
475
|
-
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));
|
|
476
497
|
});
|
|
477
498
|
it('should handle the error and resolve successfully', async () => {
|
|
478
499
|
await expect(res).toBe(undefined);
|
|
@@ -480,7 +501,7 @@ describe('commitChanges', () => {
|
|
|
480
501
|
});
|
|
481
502
|
it('should re-throw other errors', async () => {
|
|
482
503
|
const err = new Error('another error');
|
|
483
|
-
jest.spyOn(childProcess, '
|
|
504
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
484
505
|
expect.assertions(1);
|
|
485
506
|
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
486
507
|
});
|
|
@@ -494,24 +515,39 @@ describe('addRemote', () => {
|
|
|
494
515
|
};
|
|
495
516
|
it('add correct origin remote', async () => {
|
|
496
517
|
const spy = jest
|
|
497
|
-
.spyOn(childProcess, '
|
|
498
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
518
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
519
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
499
520
|
await (0, git_1.addRemote)(options, 'elastic');
|
|
500
|
-
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');
|
|
501
527
|
});
|
|
502
528
|
it('add correct user remote', async () => {
|
|
503
529
|
const spy = jest
|
|
504
|
-
.spyOn(childProcess, '
|
|
505
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
530
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
531
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
506
532
|
await (0, git_1.addRemote)(options, 'sqren');
|
|
507
|
-
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');
|
|
508
539
|
});
|
|
509
540
|
it('allows custom github url', async () => {
|
|
510
541
|
const spy = jest
|
|
511
|
-
.spyOn(childProcess, '
|
|
512
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
542
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
543
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
513
544
|
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
514
|
-
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');
|
|
515
551
|
});
|
|
516
552
|
});
|
|
517
553
|
describe('pushBackportBranch', () => {
|
|
@@ -524,14 +560,21 @@ describe('pushBackportBranch', () => {
|
|
|
524
560
|
};
|
|
525
561
|
const backportBranch = 'backport/7.x/pr-2';
|
|
526
562
|
it('should handle missing fork error', async () => {
|
|
527
|
-
jest.spyOn(childProcess, '
|
|
528
|
-
killed: false,
|
|
563
|
+
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(new childProcess.SpawnError({
|
|
529
564
|
code: 128,
|
|
530
|
-
|
|
531
|
-
|
|
565
|
+
cmdArgs: [
|
|
566
|
+
'push',
|
|
567
|
+
'sqren',
|
|
568
|
+
'backport/7.x/pr-2:backport/7.x/pr-2',
|
|
569
|
+
'--force',
|
|
570
|
+
],
|
|
532
571
|
stdout: '',
|
|
533
572
|
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
534
|
-
});
|
|
535
|
-
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
|
+
`);
|
|
536
579
|
});
|
|
537
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;
|
|
@@ -4,7 +4,7 @@ exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void
|
|
|
4
4
|
const rest_1 = require("@octokit/rest");
|
|
5
5
|
const ora_1 = require("../../../ui/ora");
|
|
6
6
|
const packageVersion_1 = require("../../../utils/packageVersion");
|
|
7
|
-
const
|
|
7
|
+
const BackportError_1 = require("../../BackportError");
|
|
8
8
|
const logger_1 = require("../../logger");
|
|
9
9
|
const commitFormatters_1 = require("../commitFormatters");
|
|
10
10
|
const fetchExistingPullRequest_1 = require("../v4/fetchExistingPullRequest");
|
|
@@ -48,7 +48,9 @@ async function createPullRequest({ options, prPayload, }) {
|
|
|
48
48
|
// swallow error
|
|
49
49
|
}
|
|
50
50
|
spinner.fail();
|
|
51
|
-
throw new
|
|
51
|
+
throw new BackportError_1.BackportError(
|
|
52
|
+
//@ts-expect-error
|
|
53
|
+
`Could not create pull request: ${(0, getGithubV3ErrorMessage_1.getGithubV3ErrorMessage)(e)}`);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
exports.createPullRequest = createPullRequest;
|