backport 7.2.0-beta.2 → 7.3.0-beta.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 +10 -5
- package/dist/entrypoint.cli.d.ts +0 -1
- package/dist/entrypoint.cli.js +0 -1
- package/dist/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +47 -0
- package/dist/options/ConfigOptions.d.ts +2 -0
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +182 -0
- package/dist/options/config/config.d.ts +2 -0
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/config/readConfigFile.d.ts +2 -0
- package/dist/options/options.d.ts +2 -0
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +384 -0
- package/dist/runSequentially.js +2 -2
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +243 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.d.ts +11 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +286 -0
- package/dist/services/git.js +34 -16
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +543 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +377 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +396 -0
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +109 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +94 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +135 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +117 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +104 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +139 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -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.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/cli.private.test.js +215 -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/cli.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/cli.e2e.private.test.js +433 -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.d.ts +1 -0
- package/dist/test/e2e/module.e2e.private.test.js +369 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +56 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +36 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +63 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +469 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +331 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +200 -0
- package/dist/ui/maybeSetupRepo.js +7 -3
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +238 -0
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/ui/setupRepo.d.ts +3 -0
- package/dist/ui/setupRepo.js +88 -0
- package/dist/ui/setupRepo.test.d.ts +1 -0
- package/dist/ui/setupRepo.test.js +288 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +6 -6
- package/yarn.lock +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
26
|
+
const globalConfig = __importStar(require("../options/config/globalConfig"));
|
|
27
|
+
const logger = __importStar(require("../services/logger"));
|
|
28
|
+
const postinstall_1 = require("./postinstall");
|
|
29
|
+
describe('postinstall', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
});
|
|
36
|
+
it("should create global config if it doesn't exist", async () => {
|
|
37
|
+
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
38
|
+
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
39
|
+
.mockResolvedValueOnce(true);
|
|
40
|
+
await (0, postinstall_1.postinstall)();
|
|
41
|
+
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
42
|
+
expect(logger.consoleLog).toBeCalledWith('Global config successfully created in /myHomeDir/.backport/config.json');
|
|
43
|
+
});
|
|
44
|
+
it('should not create global config if it already exists', async () => {
|
|
45
|
+
const consoleSpy = jest.spyOn(console, 'log');
|
|
46
|
+
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
47
|
+
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
48
|
+
.mockResolvedValueOnce(false);
|
|
49
|
+
await (0, postinstall_1.postinstall)();
|
|
50
|
+
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
51
|
+
expect(consoleSpy).toBeCalledTimes(0);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const os_1 = __importDefault(require("os"));
|
|
7
|
+
const env_1 = require("../services/env");
|
|
8
|
+
describe('env', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
11
|
+
});
|
|
12
|
+
it('getGlobalConfigPath', () => {
|
|
13
|
+
expect((0, env_1.getGlobalConfigPath)()).toBe('/myHomeDir/.backport/config.json');
|
|
14
|
+
});
|
|
15
|
+
it('getRepoPath', () => {
|
|
16
|
+
expect((0, env_1.getRepoPath)({
|
|
17
|
+
repoOwner: 'elastic',
|
|
18
|
+
repoName: 'kibana',
|
|
19
|
+
})).toBe('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
20
|
+
});
|
|
21
|
+
});
|
package/dist/services/git.d.ts
CHANGED
|
@@ -21,9 +21,7 @@ export declare function getRepoInfoFromGitRemotes({ cwd }: {
|
|
|
21
21
|
repoOwner: string;
|
|
22
22
|
repoName: string;
|
|
23
23
|
}[]>;
|
|
24
|
-
export declare function
|
|
25
|
-
cwd: string;
|
|
26
|
-
}): Promise<string | undefined>;
|
|
24
|
+
export declare function getGitProjectRootPath(dir: string): Promise<string | undefined>;
|
|
27
25
|
export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
|
|
28
26
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
29
27
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
@@ -49,6 +47,15 @@ export declare function setCommitAuthor(options: ValidConfigOptions, author: str
|
|
|
49
47
|
stdout: string;
|
|
50
48
|
stderr: string;
|
|
51
49
|
}>;
|
|
50
|
+
export declare function getGitConfig({ dir, key, }: {
|
|
51
|
+
dir: string;
|
|
52
|
+
key: 'user.name' | 'user.email';
|
|
53
|
+
}): Promise<string | undefined>;
|
|
54
|
+
export declare function setGitConfig({ dir, key, value, }: {
|
|
55
|
+
dir: string;
|
|
56
|
+
key: 'user.name' | 'user.email';
|
|
57
|
+
value: string;
|
|
58
|
+
}): Promise<void>;
|
|
52
59
|
export declare function createBackportBranch({ options, targetBranch, backportBranch, }: {
|
|
53
60
|
options: ValidConfigOptions;
|
|
54
61
|
targetBranch: string;
|
|
@@ -69,4 +76,4 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
|
|
|
69
76
|
stdout: string;
|
|
70
77
|
stderr: string;
|
|
71
78
|
}>;
|
|
72
|
-
export declare function
|
|
79
|
+
export declare function getLocalRepoPath(options: ValidConfigOptions): Promise<string | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const promises_1 = require("fs/promises");
|
|
26
|
+
const make_dir_1 = __importDefault(require("make-dir"));
|
|
27
|
+
const sandbox_1 = require("../test/sandbox");
|
|
28
|
+
const childProcess = __importStar(require("./child-process-promisified"));
|
|
29
|
+
const git_1 = require("./git");
|
|
30
|
+
const commitFormatters_1 = require("./github/commitFormatters");
|
|
31
|
+
jest.unmock('del');
|
|
32
|
+
jest.unmock('make-dir');
|
|
33
|
+
describe('git.integration', () => {
|
|
34
|
+
describe('getIsCommitInBranch', () => {
|
|
35
|
+
let firstSha;
|
|
36
|
+
let secondSha;
|
|
37
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
38
|
+
filename: __filename,
|
|
39
|
+
specname: 'getIsCommitInBranch',
|
|
40
|
+
});
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
43
|
+
const execOpts = { cwd: sandboxPath };
|
|
44
|
+
// create and commit first file
|
|
45
|
+
await childProcess.exec('git init', execOpts);
|
|
46
|
+
firstSha = await createAndCommitFile({
|
|
47
|
+
filename: 'foo.md',
|
|
48
|
+
content: 'My first file',
|
|
49
|
+
execOpts,
|
|
50
|
+
});
|
|
51
|
+
// create 7.x branch (but stay on `main` branch)
|
|
52
|
+
await childProcess.exec('git branch 7.x', execOpts);
|
|
53
|
+
// create and commit second file
|
|
54
|
+
secondSha = await createAndCommitFile({
|
|
55
|
+
filename: 'bar.md',
|
|
56
|
+
content: 'My second file',
|
|
57
|
+
execOpts,
|
|
58
|
+
});
|
|
59
|
+
// checkout 7.x
|
|
60
|
+
await childProcess.exec('git checkout 7.x', execOpts);
|
|
61
|
+
});
|
|
62
|
+
it('should contain the first commit', async () => {
|
|
63
|
+
const isFirstCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: sandboxPath }, firstSha);
|
|
64
|
+
expect(isFirstCommitInBranch).toEqual(true);
|
|
65
|
+
});
|
|
66
|
+
it('should not contain the second commit', async () => {
|
|
67
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: sandboxPath }, secondSha);
|
|
68
|
+
expect(isSecondCommitInBranch).toEqual(false);
|
|
69
|
+
});
|
|
70
|
+
it('should not contain a random commit', async () => {
|
|
71
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: sandboxPath }, 'abcdefg');
|
|
72
|
+
expect(isSecondCommitInBranch).toEqual(false);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('cherrypick', () => {
|
|
76
|
+
let firstSha;
|
|
77
|
+
let secondSha;
|
|
78
|
+
let fourthSha;
|
|
79
|
+
let execOpts;
|
|
80
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
81
|
+
filename: __filename,
|
|
82
|
+
specname: 'cherrypick',
|
|
83
|
+
});
|
|
84
|
+
beforeEach(async () => {
|
|
85
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
86
|
+
execOpts = { cwd: sandboxPath };
|
|
87
|
+
// create and commit first file
|
|
88
|
+
await childProcess.exec('git init', execOpts);
|
|
89
|
+
firstSha = await createAndCommitFile({
|
|
90
|
+
filename: 'foo.md',
|
|
91
|
+
content: 'Creating first file',
|
|
92
|
+
execOpts,
|
|
93
|
+
});
|
|
94
|
+
// create 7.x branch (but stay on `main` branch)
|
|
95
|
+
await childProcess.exec('git branch 7.x', execOpts);
|
|
96
|
+
// create and commit second file
|
|
97
|
+
secondSha = await createAndCommitFile({
|
|
98
|
+
filename: 'bar.md',
|
|
99
|
+
content: 'Creating second file\nHello',
|
|
100
|
+
execOpts,
|
|
101
|
+
});
|
|
102
|
+
// edit first file
|
|
103
|
+
await createAndCommitFile({
|
|
104
|
+
filename: 'foo.md',
|
|
105
|
+
content: 'Changing first file',
|
|
106
|
+
execOpts,
|
|
107
|
+
});
|
|
108
|
+
// edit first file
|
|
109
|
+
fourthSha = await createAndCommitFile({
|
|
110
|
+
filename: 'foo.md',
|
|
111
|
+
content: 'Some more changes to the first file',
|
|
112
|
+
execOpts,
|
|
113
|
+
});
|
|
114
|
+
// checkout 7.x
|
|
115
|
+
await childProcess.exec('git checkout 7.x', execOpts);
|
|
116
|
+
});
|
|
117
|
+
it('should not cherrypick commit that already exists', async () => {
|
|
118
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
|
|
119
|
+
return expect(() => (0, git_1.cherrypick)({ dir: sandboxPath }, firstSha)).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
120
|
+
});
|
|
121
|
+
it('should cherrypick commit cleanly', async () => {
|
|
122
|
+
const res = await (0, git_1.cherrypick)({
|
|
123
|
+
cherrypickRef: false,
|
|
124
|
+
dir: sandboxPath,
|
|
125
|
+
}, secondSha);
|
|
126
|
+
expect(res).toEqual({
|
|
127
|
+
conflictingFiles: [],
|
|
128
|
+
needsResolving: false,
|
|
129
|
+
unstagedFiles: [],
|
|
130
|
+
});
|
|
131
|
+
const message = await getCurrentMessage(execOpts);
|
|
132
|
+
expect(message).toEqual(`Update bar.md`);
|
|
133
|
+
});
|
|
134
|
+
it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
|
|
135
|
+
const res = await (0, git_1.cherrypick)({
|
|
136
|
+
cherrypickRef: true,
|
|
137
|
+
dir: sandboxPath,
|
|
138
|
+
}, secondSha);
|
|
139
|
+
expect(res).toEqual({
|
|
140
|
+
conflictingFiles: [],
|
|
141
|
+
needsResolving: false,
|
|
142
|
+
unstagedFiles: [],
|
|
143
|
+
});
|
|
144
|
+
const message = await getCurrentMessage(execOpts);
|
|
145
|
+
expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
|
|
146
|
+
});
|
|
147
|
+
it('should cherrypick commit with conflicts', async () => {
|
|
148
|
+
const res = await (0, git_1.cherrypick)({ dir: sandboxPath }, fourthSha);
|
|
149
|
+
expect(res).toEqual({
|
|
150
|
+
needsResolving: true,
|
|
151
|
+
conflictingFiles: [
|
|
152
|
+
{
|
|
153
|
+
absolute: `${sandboxPath}/foo.md`,
|
|
154
|
+
relative: 'foo.md',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
unstagedFiles: [`${sandboxPath}/foo.md`],
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('cloneRepo', () => {
|
|
162
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
163
|
+
filename: __filename,
|
|
164
|
+
specname: 'cloneRepo',
|
|
165
|
+
});
|
|
166
|
+
const sourceRepo = `${sandboxPath}/source-repo`;
|
|
167
|
+
const backportRepo = `${sandboxPath}/backport-repo`;
|
|
168
|
+
beforeEach(async () => {
|
|
169
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
170
|
+
await (0, make_dir_1.default)(sourceRepo);
|
|
171
|
+
const execOpts = { cwd: sourceRepo };
|
|
172
|
+
await childProcess.exec(`git init`, execOpts);
|
|
173
|
+
await childProcess.exec(`git remote add origin git@github.com:elastic/kibana.git`, execOpts);
|
|
174
|
+
await createAndCommitFile({
|
|
175
|
+
filename: 'my-file.txt',
|
|
176
|
+
content: 'Hello!',
|
|
177
|
+
execOpts,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
it('clones the repo', async () => {
|
|
181
|
+
// file should not exist before clone
|
|
182
|
+
await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).rejects.toThrowError();
|
|
183
|
+
await (0, git_1.cloneRepo)({ sourcePath: sourceRepo, targetPath: backportRepo }, () => null);
|
|
184
|
+
//file should exist after clone
|
|
185
|
+
await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).not.toThrowError();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('getLocalRepoPath', () => {
|
|
189
|
+
let sandboxPath;
|
|
190
|
+
beforeEach(async () => {
|
|
191
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
192
|
+
filename: __filename,
|
|
193
|
+
specname: 'getLocalRepoPath',
|
|
194
|
+
});
|
|
195
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
196
|
+
const execOpts = { cwd: sandboxPath };
|
|
197
|
+
await childProcess.exec(`git init`, execOpts);
|
|
198
|
+
await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
|
|
199
|
+
await childProcess.exec(`git remote add elastic git@github.com:elastic/kibana.git`, execOpts);
|
|
200
|
+
});
|
|
201
|
+
it('returns local source repo, when one remote matches', async () => {
|
|
202
|
+
const options = {
|
|
203
|
+
repoName: 'kibana',
|
|
204
|
+
repoOwner: 'elastic',
|
|
205
|
+
cwd: sandboxPath,
|
|
206
|
+
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
207
|
+
};
|
|
208
|
+
expect(await (0, git_1.getLocalRepoPath)(options)).toBe(sandboxPath);
|
|
209
|
+
});
|
|
210
|
+
it('returns undefined when no remotes match', async () => {
|
|
211
|
+
const options = {
|
|
212
|
+
repoName: 'kibana',
|
|
213
|
+
repoOwner: 'not-a-match',
|
|
214
|
+
cwd: sandboxPath,
|
|
215
|
+
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
216
|
+
};
|
|
217
|
+
expect(await (0, git_1.getLocalRepoPath)(options)).toBe(undefined);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe('when cloning "backport-org/different-merge-strategies"', () => {
|
|
221
|
+
const MERGE_COMMIT_HASH_1 = 'bdc5a17f81e5f32129e27b05c742e055c650bc54';
|
|
222
|
+
const MERGE_COMMIT_HASH_2 = '0db7f1ac1233461563d8708511d1c14adbab46da';
|
|
223
|
+
const SQUASH_COMMIT_HASH = '74a76fa64b34e3ffe8f2a3f73840e1b42fd07299';
|
|
224
|
+
const REBASE_COMMIT_HASH = '9059ae0ca31caa2eebc035f2542842d6c2fde83b';
|
|
225
|
+
let sandboxPath;
|
|
226
|
+
beforeAll(async () => {
|
|
227
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
228
|
+
filename: __filename,
|
|
229
|
+
specname: 'different-merge-strategies',
|
|
230
|
+
});
|
|
231
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
232
|
+
await childProcess.exec('git clone https://github.com/backport-org/different-merge-strategies.git ./', { cwd: sandboxPath });
|
|
233
|
+
});
|
|
234
|
+
describe('getIsMergeCommit', () => {
|
|
235
|
+
it('returns true for first merge commit', async () => {
|
|
236
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
|
|
237
|
+
expect(res).toBe(true);
|
|
238
|
+
});
|
|
239
|
+
it('returns true for second merge commit', async () => {
|
|
240
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_2);
|
|
241
|
+
expect(res).toBe(true);
|
|
242
|
+
});
|
|
243
|
+
it('returns false for rebased commits', async () => {
|
|
244
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, REBASE_COMMIT_HASH);
|
|
245
|
+
expect(res).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
it('returns false for squashed commits', async () => {
|
|
248
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
|
|
249
|
+
expect(res).toBe(false);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
describe('getCommitsInMergeCommit', () => {
|
|
253
|
+
it('returns a list of commit hashes - excluding the merge hash itself', async () => {
|
|
254
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
|
|
255
|
+
expect(res).not.toContain(MERGE_COMMIT_HASH_1);
|
|
256
|
+
expect(res).toEqual([
|
|
257
|
+
'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
|
|
258
|
+
'7b92e29e88266004485ce0fae0260605b01df887',
|
|
259
|
+
'a1facf8c006fb815d6a6ecd1b2907e6e64f29576',
|
|
260
|
+
'b8d4bcfb0fd875be4ab0230f6db40ddf72f45378',
|
|
261
|
+
'6f224054db5f7772b04f23f17659070216bae84c',
|
|
262
|
+
'7fed54cbd1ba9cb973462670ff82ac80bf8a79f8',
|
|
263
|
+
'78c24d0058859e7d511d10ce91ebf279c7b58ac2',
|
|
264
|
+
'709ccf707d443dd8c001b3c3ae40fdf037bb43f5',
|
|
265
|
+
]);
|
|
266
|
+
});
|
|
267
|
+
it('returns empty for squash commits', async () => {
|
|
268
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
|
|
269
|
+
expect(res).toEqual([]);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
async function createAndCommitFile({ filename, content, execOpts, }) {
|
|
275
|
+
await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
|
|
276
|
+
await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
|
|
277
|
+
return getCurrentSha(execOpts);
|
|
278
|
+
}
|
|
279
|
+
async function getCurrentSha(execOpts) {
|
|
280
|
+
const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
|
|
281
|
+
return stdout.trim();
|
|
282
|
+
}
|
|
283
|
+
async function getCurrentMessage(execOpts) {
|
|
284
|
+
const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
|
|
285
|
+
return stdout.trim();
|
|
286
|
+
}
|
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.setGitConfig = exports.getGitConfig = exports.setCommitAuthor = 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,9 +98,11 @@ 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
|
-
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
103
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
104
|
+
cwd: dir,
|
|
105
|
+
});
|
|
105
106
|
return stdout.trim();
|
|
106
107
|
}
|
|
107
108
|
catch (e) {
|
|
@@ -109,7 +110,7 @@ async function getGitProjectRoot({ cwd }) {
|
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
exports.
|
|
113
|
+
exports.getGitProjectRootPath = getGitProjectRootPath;
|
|
113
114
|
async function getIsCommitInBranch(options, commitSha) {
|
|
114
115
|
try {
|
|
115
116
|
await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
|
|
@@ -318,6 +319,26 @@ async function setCommitAuthor(options, author) {
|
|
|
318
319
|
}
|
|
319
320
|
}
|
|
320
321
|
exports.setCommitAuthor = setCommitAuthor;
|
|
322
|
+
async function getGitConfig({ dir, key, }) {
|
|
323
|
+
try {
|
|
324
|
+
const res = await (0, child_process_promisified_1.exec)(`git config ${key}`, { cwd: dir });
|
|
325
|
+
return res.stdout;
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.getGitConfig = getGitConfig;
|
|
332
|
+
async function setGitConfig({ dir, key, value, }) {
|
|
333
|
+
try {
|
|
334
|
+
await (0, child_process_promisified_1.exec)(`git config ${key} ${value}`, { cwd: dir });
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
logger_1.logger.error(`Could not set git config: ${key}=${value}`, e);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
exports.setGitConfig = setGitConfig;
|
|
321
342
|
// How the commit flows:
|
|
322
343
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
323
344
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
@@ -369,14 +390,11 @@ async function pushBackportBranch({ options, backportBranch, }) {
|
|
|
369
390
|
}
|
|
370
391
|
}
|
|
371
392
|
exports.pushBackportBranch = pushBackportBranch;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
? (await getGitProjectRoot(options)) ?? remoteUrl
|
|
379
|
-
: remoteUrl;
|
|
380
|
-
return sourcePath;
|
|
393
|
+
// retrieve path to local repo (cwd) if it matches `repoName` / `repoOwner`
|
|
394
|
+
async function getLocalRepoPath(options) {
|
|
395
|
+
const remotes = await getRepoInfoFromGitRemotes({ cwd: options.cwd });
|
|
396
|
+
const hasMatchingGitRemote = remotes.some((remote) => remote.repoName === options.repoName &&
|
|
397
|
+
remote.repoOwner === options.repoOwner);
|
|
398
|
+
return hasMatchingGitRemote ? getGitProjectRootPath(options.cwd) : undefined;
|
|
381
399
|
}
|
|
382
|
-
exports.
|
|
400
|
+
exports.getLocalRepoPath = getLocalRepoPath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|