backport 8.3.0-beta.1 → 8.4.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/dist/backportRun.js +1 -1
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +2 -0
- package/dist/entrypoint.module.private.test.js +11 -10
- package/dist/lib/child-process-promisified.js +2 -2
- package/dist/lib/getCommits.js +1 -1
- package/dist/lib/git.js +3 -1
- package/dist/lib/git.test.js +26 -0
- package/dist/lib/github/v3/createStatusComment.js +3 -2
- package/dist/lib/github/v3/createStatusComment.test.js +61 -0
- package/dist/lib/github/v4/apiRequestV4.js +1 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
- package/dist/{entrypoint.cli.private.test.d.ts → lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts} +0 -0
- package/dist/lib/github/v4/{enablePullRequestAutoMerge.private.test.js → enablePullRequestAutoMerge.mutation.test.js} +34 -8
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +5 -3
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
- package/dist/lib/remoteConfig.d.ts +1 -1
- package/dist/lib/remoteConfig.js +4 -0
- package/dist/options/ConfigOptions.d.ts +1 -0
- package/dist/options/cliArgs.d.ts +3 -2
- package/dist/options/cliArgs.js +21 -6
- package/dist/options/config/config.d.ts +1 -0
- package/dist/options/config/readConfigFile.d.ts +1 -0
- package/dist/options/options.d.ts +5 -2
- package/dist/options/options.js +1 -1
- package/dist/options/options.test.js +3 -0
- package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/date-filters.private.test.d.ts} +0 -0
- package/dist/test/e2e/cli/date-filters.private.test.js +47 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +4 -18
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +14 -15
- package/yarn.lock +165 -171
- package/dist/entrypoint.cli.private.test.js +0 -47
- package/dist/errors/BackportError.d.ts +0 -19
- package/dist/errors/BackportError.js +0 -29
- package/dist/runSequentially.test.d.ts +0 -1
- package/dist/runSequentially.test.js +0 -243
- package/dist/services/BackportError.d.ts +0 -19
- package/dist/services/BackportError.js +0 -29
- package/dist/services/HandledBackportError.d.ts +0 -19
- package/dist/services/HandledBackportError.js +0 -29
- package/dist/services/HandledError.d.ts +0 -19
- package/dist/services/HandledError.js +0 -29
- package/dist/services/child-process-promisified.d.ts +0 -25
- package/dist/services/child-process-promisified.js +0 -58
- package/dist/services/env.d.ts +0 -7
- package/dist/services/env.js +0 -30
- package/dist/services/env.test.d.ts +0 -1
- package/dist/services/env.test.js +0 -21
- package/dist/services/git.d.ts +0 -77
- package/dist/services/git.integration.test.d.ts +0 -1
- package/dist/services/git.integration.test.js +0 -616
- package/dist/services/git.js +0 -439
- package/dist/services/git.private.test.d.ts +0 -1
- package/dist/services/git.private.test.js +0 -618
- package/dist/services/git.test.d.ts +0 -1
- package/dist/services/git.test.js +0 -580
- package/dist/services/github/commitFormatters.d.ts +0 -3
- package/dist/services/github/commitFormatters.js +0 -17
- package/dist/services/github/commitFormatters.test.d.ts +0 -1
- package/dist/services/github/commitFormatters.test.js +0 -11
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
- package/dist/services/github/v3/createPullRequest.d.ts +0 -29
- package/dist/services/github/v3/createPullRequest.js +0 -91
- package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/createPullRequest.test.js +0 -377
- package/dist/services/github/v3/createStatusComment.d.ts +0 -11
- package/dist/services/github/v3/createStatusComment.js +0 -131
- package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
- package/dist/services/github/v3/createStatusComment.test.js +0 -409
- package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
- package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
- package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
- package/dist/services/github/v4/FetchPullRequestId.js +0 -36
- package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
- package/dist/services/github/v4/apiRequestV4.js +0 -71
- package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
- package/dist/services/github/v4/apiRequestV4.test.js +0 -109
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
- package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
- package/dist/services/github/v4/fetchAuthorId.js +0 -28
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
- package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
- package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
- package/dist/services/logger.d.ts +0 -9
- package/dist/services/logger.js +0 -74
- package/dist/services/prompt.test.d.ts +0 -1
- package/dist/services/prompt.test.js +0 -139
- package/dist/services/prompts.d.ts +0 -17
- package/dist/services/prompts.js +0 -132
- package/dist/services/remoteConfig.d.ts +0 -20
- package/dist/services/remoteConfig.js +0 -52
- package/dist/services/sequentially.d.ts +0 -1
- package/dist/services/sequentially.js +0 -10
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
- package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
- package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
- package/dist/services/test.d.ts +0 -1
- package/dist/services/test.js +0 -23
- package/dist/state.d.ts +0 -0
- package/dist/state.js +0 -1
- package/dist/test/ExecError.d.ts +0 -16
- package/dist/test/ExecError.js +0 -15
- package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/cli.private.test.js +0 -222
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
- package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
- package/dist/test/e2e/cli.e2e.private.test.js +0 -433
- package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
- package/dist/test/e2e/module/module.mutation.test.js +0 -369
- package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
- package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
- package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
- package/dist/test/e2e/module.e2e.private.test.js +0 -369
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
- package/dist/ui/getCommits.d.ts +0 -2
- package/dist/ui/getCommits.js +0 -75
- package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
- package/dist/ui/getCommitsWithoutBackports.js +0 -68
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
- package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
- package/dist/ui/getGitConfigAuthor.d.ts +0 -6
- package/dist/ui/getGitConfigAuthor.js +0 -15
- package/dist/ui/getTargetBranches.d.ts +0 -5
- package/dist/ui/getTargetBranches.js +0 -67
- package/dist/ui/getTargetBranches.test.d.ts +0 -1
- package/dist/ui/getTargetBranches.test.js +0 -204
- package/dist/ui/maybeSetupRepo.d.ts +0 -2
- package/dist/ui/maybeSetupRepo.js +0 -53
- package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
- package/dist/ui/maybeSetupRepo.test.js +0 -238
- package/dist/ui/ora.d.ts +0 -2
- package/dist/ui/ora.js +0 -21
- package/dist/ui/setupRepo.d.ts +0 -2
- package/dist/ui/setupRepo.js +0 -56
- package/dist/ui/setupRepo.test.d.ts +0 -1
- package/dist/ui/setupRepo.test.js +0 -273
- package/dist/utils/filterMissingCommits.d.ts +0 -2
- package/dist/utils/filterMissingCommits.js +0 -7
- package/dist/utils/redact.d.ts +0 -1
- package/dist/utils/redact.js +0 -7
|
@@ -1,580 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const os_1 = __importDefault(require("os"));
|
|
30
|
-
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
31
|
-
const git_1 = require("./git");
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
34
|
-
});
|
|
35
|
-
afterEach(() => {
|
|
36
|
-
jest.restoreAllMocks();
|
|
37
|
-
});
|
|
38
|
-
const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
|
|
39
|
-
describe('getUnstagedFiles', () => {
|
|
40
|
-
it('should split lines and remove empty', async () => {
|
|
41
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
|
|
42
|
-
stdout: 'conflicting-file.txt\nconflicting-file2.txt\n',
|
|
43
|
-
stderr: '',
|
|
44
|
-
code: 0,
|
|
45
|
-
cmdArgs: [],
|
|
46
|
-
});
|
|
47
|
-
const options = {
|
|
48
|
-
repoOwner: 'elastic',
|
|
49
|
-
repoName: 'kibana',
|
|
50
|
-
};
|
|
51
|
-
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([
|
|
52
|
-
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
53
|
-
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file2.txt',
|
|
54
|
-
]);
|
|
55
|
-
});
|
|
56
|
-
it('should not error on empty', async () => {
|
|
57
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValueOnce({
|
|
58
|
-
stdout: '',
|
|
59
|
-
stderr: '',
|
|
60
|
-
code: 0,
|
|
61
|
-
cmdArgs: [],
|
|
62
|
-
});
|
|
63
|
-
const options = {
|
|
64
|
-
repoOwner: 'elastic',
|
|
65
|
-
repoName: 'kibana',
|
|
66
|
-
};
|
|
67
|
-
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe('getLocalConfigFileCommitDate', () => {
|
|
71
|
-
it('returns a timestamp the file exists', async () => {
|
|
72
|
-
const res = {
|
|
73
|
-
stdout: 'Wed Dec 16 10:10:39 2020 -0800\n',
|
|
74
|
-
stderr: '',
|
|
75
|
-
code: 0,
|
|
76
|
-
cmdArgs: [],
|
|
77
|
-
};
|
|
78
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
79
|
-
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(1608142239000);
|
|
80
|
-
});
|
|
81
|
-
it('returns empty when file does not exists', async () => {
|
|
82
|
-
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
83
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
84
|
-
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
85
|
-
});
|
|
86
|
-
it('handles errors', async () => {
|
|
87
|
-
const err = {
|
|
88
|
-
killed: false,
|
|
89
|
-
code: 128,
|
|
90
|
-
signal: null,
|
|
91
|
-
cmd: 'any command...',
|
|
92
|
-
stdout: '',
|
|
93
|
-
stderr: 'any error',
|
|
94
|
-
};
|
|
95
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
96
|
-
expect(await (0, git_1.getLocalConfigFileCommitDate)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
describe('isLocalConfigFileUntracked', () => {
|
|
100
|
-
it('returns "false" if file does not exist', async () => {
|
|
101
|
-
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
102
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
103
|
-
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(false);
|
|
104
|
-
});
|
|
105
|
-
it('returns "true" if file is untracked', async () => {
|
|
106
|
-
const res = {
|
|
107
|
-
stdout: '.backportrc.json\n',
|
|
108
|
-
stderr: '',
|
|
109
|
-
code: 0,
|
|
110
|
-
cmdArgs: [],
|
|
111
|
-
};
|
|
112
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
113
|
-
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(true);
|
|
114
|
-
});
|
|
115
|
-
it('handles errors', async () => {
|
|
116
|
-
const err = {
|
|
117
|
-
killed: false,
|
|
118
|
-
code: 128,
|
|
119
|
-
signal: null,
|
|
120
|
-
cmd: 'any command...',
|
|
121
|
-
stdout: '',
|
|
122
|
-
stderr: 'any error',
|
|
123
|
-
};
|
|
124
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
125
|
-
expect(await (0, git_1.isLocalConfigFileUntracked)({ cwd: 'foo/bar' })).toEqual(undefined);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('isLocalConfigFileModified', () => {
|
|
129
|
-
it('returns "false" if file does not exist', async () => {
|
|
130
|
-
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
131
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
132
|
-
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
133
|
-
});
|
|
134
|
-
it('returns "false" if file is untracked', async () => {
|
|
135
|
-
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
136
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
137
|
-
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(false);
|
|
138
|
-
});
|
|
139
|
-
it('returns "true" if file is staged', async () => {
|
|
140
|
-
const res = {
|
|
141
|
-
stdout: '.backportrc.json\n',
|
|
142
|
-
stderr: '',
|
|
143
|
-
code: 0,
|
|
144
|
-
cmdArgs: [],
|
|
145
|
-
};
|
|
146
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
147
|
-
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toEqual(true);
|
|
148
|
-
});
|
|
149
|
-
it('handles errors', async () => {
|
|
150
|
-
const err = {
|
|
151
|
-
killed: false,
|
|
152
|
-
code: 128,
|
|
153
|
-
signal: null,
|
|
154
|
-
cmd: 'any command...',
|
|
155
|
-
stdout: '',
|
|
156
|
-
stderr: 'any error',
|
|
157
|
-
};
|
|
158
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
159
|
-
expect(await (0, git_1.isLocalConfigFileModified)({ cwd: 'foo/bar' })).toBe(false);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe('getRepoInfoFromGitRemotes', () => {
|
|
163
|
-
it('returns repoName and repoOwner ssh remotes', async () => {
|
|
164
|
-
const res = {
|
|
165
|
-
stdout: 'john.doe\tgit@github.com:john.doe/kibana (fetch)\n' +
|
|
166
|
-
'john.doe\tgit@github.com:john.doe/kibana (push)\n' +
|
|
167
|
-
'elastic\tgit@github.com:elastic/kibana.git (fetch)\n' +
|
|
168
|
-
'elastic\tgit@github.com:elastic/kibana.git (push)\n' +
|
|
169
|
-
'peter\tgit@github.com:peter/kibana (fetch)\n' +
|
|
170
|
-
'peter\tgit@github.com:peter/kibana (push)\n' +
|
|
171
|
-
'sqren\tgit@github.com:sqren/kibana.git (fetch)\n' +
|
|
172
|
-
'sqren\tgit@github.com:sqren/kibana.git (push)\n',
|
|
173
|
-
stderr: '',
|
|
174
|
-
code: 0,
|
|
175
|
-
cmdArgs: [],
|
|
176
|
-
};
|
|
177
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
178
|
-
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
179
|
-
{ repoName: 'kibana', repoOwner: 'john.doe' },
|
|
180
|
-
{ repoName: 'kibana', repoOwner: 'elastic' },
|
|
181
|
-
{ repoName: 'kibana', repoOwner: 'peter' },
|
|
182
|
-
{ repoName: 'kibana', repoOwner: 'sqren' },
|
|
183
|
-
]);
|
|
184
|
-
});
|
|
185
|
-
it('returns repoName and repoOwner https remotes', async () => {
|
|
186
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue({
|
|
187
|
-
stdout: 'origin\thttps://github.com/shay/elasticsearch.git (fetch)\n' +
|
|
188
|
-
'origin\thttps://github.com/shay/elasticsearch.git (push)\n',
|
|
189
|
-
stderr: '',
|
|
190
|
-
code: 0,
|
|
191
|
-
cmdArgs: [],
|
|
192
|
-
});
|
|
193
|
-
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([
|
|
194
|
-
{ repoName: 'elasticsearch', repoOwner: 'shay' },
|
|
195
|
-
]);
|
|
196
|
-
});
|
|
197
|
-
it('returns undefined when no remotes exist', async () => {
|
|
198
|
-
const res = { stdout: '', stderr: '', code: 0, cmdArgs: [] };
|
|
199
|
-
jest.spyOn(childProcess, 'spawnPromise').mockResolvedValue(res);
|
|
200
|
-
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
201
|
-
});
|
|
202
|
-
it('handles errors', async () => {
|
|
203
|
-
const err = {
|
|
204
|
-
killed: false,
|
|
205
|
-
code: 128,
|
|
206
|
-
signal: null,
|
|
207
|
-
cmd: 'git ls-files .backportrc.js* --exclude-standard --others',
|
|
208
|
-
stdout: '',
|
|
209
|
-
stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
|
|
210
|
-
};
|
|
211
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
212
|
-
expect(await (0, git_1.getRepoInfoFromGitRemotes)({ cwd: 'foo/bar' })).toEqual([]);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
describe('getConflictingFiles', () => {
|
|
216
|
-
it('should split by linebreak and remove empty and duplicate items', async () => {
|
|
217
|
-
const err = new childProcess.SpawnError({
|
|
218
|
-
code: 2,
|
|
219
|
-
cmdArgs: ['--no-pager', 'diff', '--check'],
|
|
220
|
-
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
221
|
-
stderr: '',
|
|
222
|
-
});
|
|
223
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
224
|
-
const options = {
|
|
225
|
-
repoOwner: 'elastic',
|
|
226
|
-
repoName: 'kibana',
|
|
227
|
-
};
|
|
228
|
-
expect(await (0, git_1.getConflictingFiles)(options)).toEqual([
|
|
229
|
-
{
|
|
230
|
-
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
231
|
-
relative: 'conflicting-file.txt',
|
|
232
|
-
},
|
|
233
|
-
]);
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
describe('createBackportBranch', () => {
|
|
237
|
-
const options = {
|
|
238
|
-
repoOwner: 'elastic',
|
|
239
|
-
repoName: 'kibana',
|
|
240
|
-
};
|
|
241
|
-
const targetBranch = '4.x';
|
|
242
|
-
const backportBranch = 'backport/4.x/commit-72f94e76';
|
|
243
|
-
it(`should handle "couldn't find remote ref" error`, async () => {
|
|
244
|
-
expect.assertions(1);
|
|
245
|
-
const err = new childProcess.SpawnError({
|
|
246
|
-
code: 128,
|
|
247
|
-
cmdArgs: [],
|
|
248
|
-
stdout: 'HEAD is now at 72f94e7 Create "conflicting-file.txt" in master\n',
|
|
249
|
-
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
250
|
-
});
|
|
251
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
252
|
-
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
253
|
-
});
|
|
254
|
-
it('should throw "Invalid refspec" error', async () => {
|
|
255
|
-
expect.assertions(1);
|
|
256
|
-
const err = new childProcess.SpawnError({
|
|
257
|
-
code: 128,
|
|
258
|
-
cmdArgs: [],
|
|
259
|
-
stdout: '',
|
|
260
|
-
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
261
|
-
});
|
|
262
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
263
|
-
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
264
|
-
});
|
|
265
|
-
it('should rethrow normal error', async () => {
|
|
266
|
-
expect.assertions(1);
|
|
267
|
-
const err = new Error('just a normal error');
|
|
268
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
269
|
-
expect.assertions(1);
|
|
270
|
-
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
describe('deleteRemote', () => {
|
|
274
|
-
const remoteName = 'my-remote';
|
|
275
|
-
const options = {
|
|
276
|
-
repoOwner: 'elastic',
|
|
277
|
-
repoName: 'kibana',
|
|
278
|
-
};
|
|
279
|
-
it('should swallow SpawnError error', async () => {
|
|
280
|
-
const err = new childProcess.SpawnError({
|
|
281
|
-
code: 128,
|
|
282
|
-
cmdArgs: [],
|
|
283
|
-
stdout: '',
|
|
284
|
-
stderr: "fatal: No such remote: 'origin'\n",
|
|
285
|
-
});
|
|
286
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
287
|
-
await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
|
|
288
|
-
});
|
|
289
|
-
it('should rethrow normal error', async () => {
|
|
290
|
-
const err = new Error('just a normal error');
|
|
291
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
292
|
-
expect.assertions(1);
|
|
293
|
-
await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
describe('cherrypick', () => {
|
|
297
|
-
const options = {
|
|
298
|
-
repoOwner: 'elastic',
|
|
299
|
-
repoName: 'kibana',
|
|
300
|
-
};
|
|
301
|
-
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
302
|
-
jest
|
|
303
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
304
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
305
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
306
|
-
expect(await (0, git_1.cherrypick)({
|
|
307
|
-
options,
|
|
308
|
-
sha: 'abcd',
|
|
309
|
-
commitAuthor,
|
|
310
|
-
})).toEqual({
|
|
311
|
-
conflictingFiles: [],
|
|
312
|
-
unstagedFiles: [],
|
|
313
|
-
needsResolving: false,
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
it('should use mainline option when specified', async () => {
|
|
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(...)
|
|
321
|
-
await (0, git_1.cherrypick)({
|
|
322
|
-
options: { ...options, mainline: 1 },
|
|
323
|
-
sha: 'abcd',
|
|
324
|
-
commitAuthor,
|
|
325
|
-
});
|
|
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
|
-
]);
|
|
342
|
-
});
|
|
343
|
-
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
344
|
-
jest
|
|
345
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
346
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
347
|
-
// mock `git cherrypick`
|
|
348
|
-
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
349
|
-
code: 128,
|
|
350
|
-
cmdArgs: ['cherry-pick', '-x', 'abcd'],
|
|
351
|
-
stdout: '',
|
|
352
|
-
stderr: '',
|
|
353
|
-
}))
|
|
354
|
-
// mock getConflictingFiles
|
|
355
|
-
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
356
|
-
code: 2,
|
|
357
|
-
cmdArgs: ['--no-pager', 'diff', '--check'],
|
|
358
|
-
stdout: 'conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n',
|
|
359
|
-
stderr: '',
|
|
360
|
-
}))
|
|
361
|
-
// mock getUnstagedFiles
|
|
362
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
363
|
-
expect(await (0, git_1.cherrypick)({
|
|
364
|
-
options,
|
|
365
|
-
sha: 'abcd',
|
|
366
|
-
commitAuthor,
|
|
367
|
-
})).toEqual({
|
|
368
|
-
conflictingFiles: [
|
|
369
|
-
{
|
|
370
|
-
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
371
|
-
relative: 'conflicting-file.txt',
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
needsResolving: true,
|
|
375
|
-
unstagedFiles: [],
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
379
|
-
jest
|
|
380
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
381
|
-
// mock getIsMergeCommit(...)
|
|
382
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
383
|
-
// mock cherry pick command
|
|
384
|
-
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
385
|
-
code: 128,
|
|
386
|
-
cmdArgs: ['cherry-pick', '381c7b604110257437a289b1f1742685eb8d79c5'],
|
|
387
|
-
stdout: '',
|
|
388
|
-
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
389
|
-
}));
|
|
390
|
-
await expect((0, git_1.cherrypick)({
|
|
391
|
-
options,
|
|
392
|
-
sha: 'abcd',
|
|
393
|
-
commitAuthor,
|
|
394
|
-
})).rejects
|
|
395
|
-
.toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
|
|
396
|
-
|
|
397
|
-
> backport --mainline
|
|
398
|
-
|
|
399
|
-
or:
|
|
400
|
-
|
|
401
|
-
> backport --mainline <parent-number>
|
|
402
|
-
|
|
403
|
-
Or refer to the git documentation for more information: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt---mainlineparent-number`);
|
|
404
|
-
});
|
|
405
|
-
it('should gracefully handle empty commits', async () => {
|
|
406
|
-
jest
|
|
407
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
408
|
-
// mock getIsMergeCommit(...)
|
|
409
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
410
|
-
// mock cherry pick command
|
|
411
|
-
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
412
|
-
code: 1,
|
|
413
|
-
cmdArgs: ['cherry-pick', 'fe6b13b83cc010f722548cd5a0a8c2d5341a20dd'],
|
|
414
|
-
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
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",
|
|
416
|
-
}));
|
|
417
|
-
await expect((0, git_1.cherrypick)({
|
|
418
|
-
options,
|
|
419
|
-
sha: 'abcd',
|
|
420
|
-
commitAuthor,
|
|
421
|
-
})).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
|
|
422
|
-
});
|
|
423
|
-
it('should re-throw non-cherrypick errors', async () => {
|
|
424
|
-
jest
|
|
425
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
426
|
-
// mock getIsMergeCommit(...)
|
|
427
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
428
|
-
// mock cherry pick command
|
|
429
|
-
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
430
|
-
// getConflictingFiles
|
|
431
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] })
|
|
432
|
-
// getUnstagedFiles
|
|
433
|
-
.mockResolvedValueOnce({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
434
|
-
await expect((0, git_1.cherrypick)({
|
|
435
|
-
options,
|
|
436
|
-
sha: 'abcd',
|
|
437
|
-
commitAuthor,
|
|
438
|
-
})).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
describe('commitChanges', () => {
|
|
442
|
-
const options = {
|
|
443
|
-
repoOwner: 'elastic',
|
|
444
|
-
repoName: 'kibana',
|
|
445
|
-
};
|
|
446
|
-
const commit = {
|
|
447
|
-
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
448
|
-
sourceCommit: {
|
|
449
|
-
message: 'The original commit message',
|
|
450
|
-
committedDate: '2020',
|
|
451
|
-
sha: 'abc',
|
|
452
|
-
},
|
|
453
|
-
sourceBranch: 'master',
|
|
454
|
-
expectedTargetPullRequests: [],
|
|
455
|
-
};
|
|
456
|
-
it('should return when changes committed successfully', async () => {
|
|
457
|
-
jest
|
|
458
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
459
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
460
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
461
|
-
});
|
|
462
|
-
it('should swallow error if changes have already been committed manaully', async () => {
|
|
463
|
-
const err = new childProcess.SpawnError({
|
|
464
|
-
code: 1,
|
|
465
|
-
cmdArgs: ['commit', '--no-edit'],
|
|
466
|
-
stdout: 'On branch backport/7.x/commit-913afb3b\nnothing to commit, working tree clean\n',
|
|
467
|
-
stderr: '',
|
|
468
|
-
});
|
|
469
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
470
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
471
|
-
});
|
|
472
|
-
describe('when commit fails due to empty message', () => {
|
|
473
|
-
let spy;
|
|
474
|
-
let res;
|
|
475
|
-
beforeEach(async () => {
|
|
476
|
-
const err = new childProcess.SpawnError({
|
|
477
|
-
code: 1,
|
|
478
|
-
cmdArgs: ['commit', '--no-edit', '--no-verify'],
|
|
479
|
-
stdout: '',
|
|
480
|
-
stderr: 'Aborting commit due to empty commit message.\n',
|
|
481
|
-
});
|
|
482
|
-
spy = jest
|
|
483
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
484
|
-
.mockRejectedValueOnce(err)
|
|
485
|
-
.mockResolvedValueOnce({
|
|
486
|
-
stderr: '',
|
|
487
|
-
stdout: '',
|
|
488
|
-
code: 0,
|
|
489
|
-
cmdArgs: [],
|
|
490
|
-
});
|
|
491
|
-
res = await (0, git_1.commitChanges)(commit, options);
|
|
492
|
-
});
|
|
493
|
-
it('should manually set the commit message', () => {
|
|
494
|
-
expect(spy).toHaveBeenCalledTimes(2);
|
|
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));
|
|
497
|
-
});
|
|
498
|
-
it('should handle the error and resolve successfully', async () => {
|
|
499
|
-
await expect(res).toBe(undefined);
|
|
500
|
-
});
|
|
501
|
-
});
|
|
502
|
-
it('should re-throw other errors', async () => {
|
|
503
|
-
const err = new Error('another error');
|
|
504
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
505
|
-
expect.assertions(1);
|
|
506
|
-
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
describe('addRemote', () => {
|
|
510
|
-
const options = {
|
|
511
|
-
accessToken: 'myAccessToken',
|
|
512
|
-
repoOwner: 'elastic',
|
|
513
|
-
repoName: 'kibana',
|
|
514
|
-
gitHostname: 'github.com',
|
|
515
|
-
};
|
|
516
|
-
it('add correct origin remote', async () => {
|
|
517
|
-
const spy = jest
|
|
518
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
519
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
520
|
-
await (0, git_1.addRemote)(options, 'elastic');
|
|
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');
|
|
527
|
-
});
|
|
528
|
-
it('add correct user remote', async () => {
|
|
529
|
-
const spy = jest
|
|
530
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
531
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
532
|
-
await (0, git_1.addRemote)(options, 'sqren');
|
|
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');
|
|
539
|
-
});
|
|
540
|
-
it('allows custom github url', async () => {
|
|
541
|
-
const spy = jest
|
|
542
|
-
.spyOn(childProcess, 'spawnPromise')
|
|
543
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
544
|
-
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
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');
|
|
551
|
-
});
|
|
552
|
-
});
|
|
553
|
-
describe('pushBackportBranch', () => {
|
|
554
|
-
const options = {
|
|
555
|
-
authenticatedUsername: 'sqren_authenticated',
|
|
556
|
-
fork: true,
|
|
557
|
-
repoForkOwner: 'the_fork_owner',
|
|
558
|
-
repoName: 'kibana',
|
|
559
|
-
repoOwner: 'elastic',
|
|
560
|
-
};
|
|
561
|
-
const backportBranch = 'backport/7.x/pr-2';
|
|
562
|
-
it('should handle missing fork error', async () => {
|
|
563
|
-
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(new childProcess.SpawnError({
|
|
564
|
-
code: 128,
|
|
565
|
-
cmdArgs: [
|
|
566
|
-
'push',
|
|
567
|
-
'sqren',
|
|
568
|
-
'backport/7.x/pr-2:backport/7.x/pr-2',
|
|
569
|
-
'--force',
|
|
570
|
-
],
|
|
571
|
-
stdout: '',
|
|
572
|
-
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
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
|
-
`);
|
|
579
|
-
});
|
|
580
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stripPullNumber = exports.getFirstLine = exports.getShortSha = void 0;
|
|
4
|
-
function getShortSha(sha) {
|
|
5
|
-
return sha.slice(0, 8);
|
|
6
|
-
}
|
|
7
|
-
exports.getShortSha = getShortSha;
|
|
8
|
-
function getFirstLine(message) {
|
|
9
|
-
return message.split('\n')[0];
|
|
10
|
-
}
|
|
11
|
-
exports.getFirstLine = getFirstLine;
|
|
12
|
-
function stripPullNumber(message) {
|
|
13
|
-
const firstMessageLine = getFirstLine(message);
|
|
14
|
-
const messageWithoutPullNumber = firstMessageLine.replace(/( \(#\d+\))$/, '');
|
|
15
|
-
return messageWithoutPullNumber;
|
|
16
|
-
}
|
|
17
|
-
exports.stripPullNumber = stripPullNumber;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const commitFormatters_1 = require("./commitFormatters");
|
|
4
|
-
describe('getFirstCommitMessageLine', () => {
|
|
5
|
-
it('should only return the first line of the message', () => {
|
|
6
|
-
expect((0, commitFormatters_1.getFirstLine)('My commit message (#1234)\n\n Additional commit message body')).toEqual('My commit message (#1234)');
|
|
7
|
-
});
|
|
8
|
-
it('should return the commit message as-is', () => {
|
|
9
|
-
expect((0, commitFormatters_1.getFirstLine)('My commit message')).toEqual('My commit message');
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addAssigneesToPullRequest = void 0;
|
|
4
|
-
const rest_1 = require("@octokit/rest");
|
|
5
|
-
const ora_1 = require("../../../ui/ora");
|
|
6
|
-
const logger_1 = require("../../logger");
|
|
7
|
-
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }, pullNumber, assignees) {
|
|
8
|
-
const text = autoAssign
|
|
9
|
-
? `Self-assigning to #${pullNumber}`
|
|
10
|
-
: `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
|
|
11
|
-
logger_1.logger.info(text);
|
|
12
|
-
const spinner = (0, ora_1.ora)(ci, text).start();
|
|
13
|
-
try {
|
|
14
|
-
const octokit = new rest_1.Octokit({
|
|
15
|
-
auth: accessToken,
|
|
16
|
-
baseUrl: githubApiBaseUrlV3,
|
|
17
|
-
log: logger_1.logger,
|
|
18
|
-
});
|
|
19
|
-
await octokit.issues.addAssignees({
|
|
20
|
-
owner: repoOwner,
|
|
21
|
-
repo: repoName,
|
|
22
|
-
issue_number: pullNumber,
|
|
23
|
-
assignees: assignees,
|
|
24
|
-
});
|
|
25
|
-
spinner.succeed();
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
spinner.fail();
|
|
29
|
-
logger_1.logger.info(`Could not add assignees to PR ${pullNumber}`, e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.addAssigneesToPullRequest = addAssigneesToPullRequest;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|