backport 8.0.0 → 8.1.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 +4 -4
- package/dist/backportRun.d.ts +5 -4
- package/dist/backportRun.js +41 -42
- package/dist/entrypoint.cli.js +3 -7
- package/dist/entrypoint.module.d.ts +7 -5
- package/dist/entrypoint.module.js +11 -9
- package/dist/entrypoint.module.private.test.js +4 -4
- 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 +13 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -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 +58 -0
- package/dist/lib/env.d.ts +7 -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 +206 -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 +136 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +461 -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/logger.d.ts +9 -0
- package/dist/lib/logger.js +74 -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 +15 -12
- package/dist/options/cliArgs.js +34 -19
- package/dist/options/cliArgs.test.js +125 -1
- 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 +3 -1
- package/dist/options/config/globalConfig.js +5 -5
- package/dist/options/config/readConfigFile.d.ts +9 -7
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +43 -7
- package/dist/options/options.js +20 -24
- package/dist/options/options.test.js +112 -54
- package/dist/runSequentially.d.ts +10 -7
- package/dist/runSequentially.js +5 -5
- package/dist/scripts/postinstall.js +3 -3
- package/dist/scripts/postinstall.test.js +1 -1
- 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 +1 -1
- package/dist/services/HandledError.js +5 -5
- package/dist/services/git.js +7 -7
- package/dist/services/github/v3/createPullRequest.js +2 -2
- package/dist/services/github/v3/createStatusComment.js +2 -2
- package/dist/services/github/v3/createStatusComment.test.js +5 -4
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- 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 +26 -24
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
- 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 +2 -2
- package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
- package/dist/test/setupFiles/automatic-mocks.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/setupRepo.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +12 -12
- package/yarn.lock +112 -65
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupRepo = void 0;
|
|
4
|
+
const del = require("del");
|
|
5
|
+
const BackportError_1 = require("./BackportError");
|
|
6
|
+
const env_1 = require("./env");
|
|
7
|
+
const git_1 = require("./git");
|
|
8
|
+
const ora_1 = require("./ora");
|
|
9
|
+
async function setupRepo(options) {
|
|
10
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
11
|
+
const isAlreadyCloned = await getIsRepoCloned(options);
|
|
12
|
+
if (options.cwd.includes(repoPath)) {
|
|
13
|
+
throw new BackportError_1.BackportError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
|
|
14
|
+
}
|
|
15
|
+
// clone repo if folder does not already exists
|
|
16
|
+
if (!isAlreadyCloned) {
|
|
17
|
+
const spinner = (0, ora_1.ora)(options.interactive).start();
|
|
18
|
+
try {
|
|
19
|
+
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
20
|
+
const remoteRepoPath = (0, git_1.getRemoteUrl)(options, options.repoOwner);
|
|
21
|
+
const sourcePath = localRepoPath ? localRepoPath : remoteRepoPath;
|
|
22
|
+
// show the full path for local repos, but only the host name for remote repos (to avoid showing the access token)
|
|
23
|
+
const sourcePathHumanReadable = !localRepoPath
|
|
24
|
+
? options.gitHostname
|
|
25
|
+
: sourcePath;
|
|
26
|
+
const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
|
|
27
|
+
spinner.text = `0% ${spinnerCloneText}`;
|
|
28
|
+
await del(repoPath, { force: true });
|
|
29
|
+
await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
|
|
30
|
+
spinner.text = `${progress}% ${spinnerCloneText}`;
|
|
31
|
+
});
|
|
32
|
+
spinner.succeed(`100% ${spinnerCloneText}`);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
spinner.fail();
|
|
36
|
+
await del(repoPath, { force: true });
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// delete default "origin" remote to avoid confusion
|
|
41
|
+
await (0, git_1.deleteRemote)(options, 'origin');
|
|
42
|
+
// ensure remote are setup with latest accessToken
|
|
43
|
+
await (0, git_1.deleteRemote)(options, options.repoForkOwner);
|
|
44
|
+
await (0, git_1.addRemote)(options, options.repoForkOwner);
|
|
45
|
+
// add remote for non-fork repo (if the above is a fork)
|
|
46
|
+
if (options.repoForkOwner !== options.repoOwner) {
|
|
47
|
+
await (0, git_1.deleteRemote)(options, options.repoOwner);
|
|
48
|
+
await (0, git_1.addRemote)(options, options.repoOwner);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.setupRepo = setupRepo;
|
|
52
|
+
async function getIsRepoCloned(options) {
|
|
53
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
54
|
+
const projectRoot = await (0, git_1.getGitProjectRootPath)(repoPath);
|
|
55
|
+
return repoPath === projectRoot;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,278 @@
|
|
|
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 del_1 = __importDefault(require("del"));
|
|
31
|
+
const mocks_1 = require("../test/mocks");
|
|
32
|
+
const childProcess = __importStar(require("./child-process-promisified"));
|
|
33
|
+
const gitModule = __importStar(require("./git"));
|
|
34
|
+
const setupRepo_1 = require("./setupRepo");
|
|
35
|
+
describe('setupRepo', () => {
|
|
36
|
+
let spawnSpy;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
39
|
+
spawnSpy = jest
|
|
40
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
41
|
+
.mockResolvedValue({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
jest.restoreAllMocks();
|
|
45
|
+
});
|
|
46
|
+
describe('if an error occurs while cloning', () => {
|
|
47
|
+
it('should delete repo', async () => {
|
|
48
|
+
expect.assertions(2);
|
|
49
|
+
jest
|
|
50
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
51
|
+
.mockImplementation((cmd, cmdArgs) => {
|
|
52
|
+
if (cmdArgs.includes('clone')) {
|
|
53
|
+
throw new Error('Simulated git clone failure');
|
|
54
|
+
}
|
|
55
|
+
throw new Error('unknown error');
|
|
56
|
+
});
|
|
57
|
+
await expect((0, setupRepo_1.setupRepo)({
|
|
58
|
+
repoName: 'kibana',
|
|
59
|
+
repoOwner: 'elastic',
|
|
60
|
+
cwd: '/path/to/source/repo',
|
|
61
|
+
interactive: true,
|
|
62
|
+
})).rejects.toThrowError('Simulated git clone failure');
|
|
63
|
+
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('while cloning the repo', () => {
|
|
67
|
+
it('updates the progress', async () => {
|
|
68
|
+
let onClose;
|
|
69
|
+
let onData;
|
|
70
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
71
|
+
const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
|
|
72
|
+
const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
73
|
+
jest
|
|
74
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
75
|
+
.mockResolvedValue(undefined);
|
|
76
|
+
jest
|
|
77
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
78
|
+
//@ts-expect-error
|
|
79
|
+
.mockImplementation(() => {
|
|
80
|
+
return {
|
|
81
|
+
on: (name, cb) => {
|
|
82
|
+
if (name === 'close') {
|
|
83
|
+
onClose = cb;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
stderr: {
|
|
87
|
+
on: (name, handler) => {
|
|
88
|
+
if (name === 'data') {
|
|
89
|
+
onData = handler;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
onData('Receiving objects: 1%');
|
|
97
|
+
onData('Receiving objects: 10%');
|
|
98
|
+
onData('Receiving objects: 20%');
|
|
99
|
+
onData('Receiving objects: 100%');
|
|
100
|
+
onData('Updating files: 1%');
|
|
101
|
+
onData('Updating files: 10%');
|
|
102
|
+
onData('Updating files: 20%');
|
|
103
|
+
onData('Updating files: 100%');
|
|
104
|
+
onClose(0);
|
|
105
|
+
}, 50);
|
|
106
|
+
await (0, setupRepo_1.setupRepo)({
|
|
107
|
+
repoName: 'kibana',
|
|
108
|
+
repoOwner: 'elastic',
|
|
109
|
+
gitHostname: 'github.com',
|
|
110
|
+
cwd: '/path/to/source/repo',
|
|
111
|
+
interactive: true,
|
|
112
|
+
});
|
|
113
|
+
expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
|
|
114
|
+
.toMatchInlineSnapshot(`
|
|
115
|
+
Array [
|
|
116
|
+
"0% Cloning repository from github.com (one-time operation)",
|
|
117
|
+
"1% Cloning repository from github.com (one-time operation)",
|
|
118
|
+
"9% Cloning repository from github.com (one-time operation)",
|
|
119
|
+
"18% Cloning repository from github.com (one-time operation)",
|
|
120
|
+
"90% Cloning repository from github.com (one-time operation)",
|
|
121
|
+
"90% Cloning repository from github.com (one-time operation)",
|
|
122
|
+
"91% Cloning repository from github.com (one-time operation)",
|
|
123
|
+
"92% Cloning repository from github.com (one-time operation)",
|
|
124
|
+
"100% Cloning repository from github.com (one-time operation)",
|
|
125
|
+
]
|
|
126
|
+
`);
|
|
127
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('if repo is already cloned', () => {
|
|
131
|
+
function mockGitProjectRootPath(value) {
|
|
132
|
+
return (jest
|
|
133
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
134
|
+
//@ts-expect-error
|
|
135
|
+
.mockImplementationOnce(async (cmd, cmdArgs) => {
|
|
136
|
+
if (cmdArgs.includes('rev-parse')) {
|
|
137
|
+
return {
|
|
138
|
+
stdout: value,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
beforeEach(async () => {
|
|
144
|
+
jest.clearAllMocks();
|
|
145
|
+
mockGitProjectRootPath('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
146
|
+
jest.spyOn(gitModule, 'cloneRepo');
|
|
147
|
+
await (0, setupRepo_1.setupRepo)({
|
|
148
|
+
accessToken: 'myAccessToken',
|
|
149
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
150
|
+
cwd: '/path/to/source/repo',
|
|
151
|
+
fork: true,
|
|
152
|
+
repoForkOwner: 'sqren',
|
|
153
|
+
repoName: 'kibana',
|
|
154
|
+
repoOwner: 'elastic',
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
it('should not delete the existing repo', () => {
|
|
158
|
+
expect(del_1.default).not.toHaveBeenCalled();
|
|
159
|
+
});
|
|
160
|
+
it('should not clone repo', () => {
|
|
161
|
+
expect(gitModule.cloneRepo).not.toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
it('should re-create remotes for both source repo and fork', () => {
|
|
164
|
+
expect(spawnSpy.mock.calls.map(([cmd, cmdArgs, cwd]) => ({
|
|
165
|
+
cmd: `${cmd} ${cmdArgs.join(' ')}`,
|
|
166
|
+
cwd,
|
|
167
|
+
}))).toEqual([
|
|
168
|
+
{
|
|
169
|
+
cmd: 'git rev-parse --show-toplevel',
|
|
170
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
cmd: 'git remote rm origin',
|
|
174
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
cmd: 'git remote rm sqren',
|
|
178
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
cmd: 'git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
|
|
182
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
cmd: 'git remote rm elastic',
|
|
186
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
190
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
191
|
+
},
|
|
192
|
+
]);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
function mockGitClone() {
|
|
196
|
+
jest
|
|
197
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
198
|
+
//@ts-expect-error
|
|
199
|
+
.mockImplementation((cmd, cmdArgs) => {
|
|
200
|
+
if (cmdArgs.includes('clone')) {
|
|
201
|
+
return {
|
|
202
|
+
on: (name, cb) => {
|
|
203
|
+
if (name === 'close') {
|
|
204
|
+
//@ts-expect-error
|
|
205
|
+
cb(0);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
stderr: { on: () => null },
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
describe('if repo does not exists locally', () => {
|
|
214
|
+
let spinnerSuccessSpy;
|
|
215
|
+
beforeEach(async () => {
|
|
216
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
217
|
+
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
218
|
+
mockGitClone();
|
|
219
|
+
await (0, setupRepo_1.setupRepo)({
|
|
220
|
+
accessToken: 'myAccessToken',
|
|
221
|
+
gitHostname: 'github.com',
|
|
222
|
+
repoName: 'kibana',
|
|
223
|
+
repoOwner: 'elastic',
|
|
224
|
+
cwd: '/path/to/source/repo',
|
|
225
|
+
interactive: true,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('should clone it from github.com', async () => {
|
|
229
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
230
|
+
expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
|
|
231
|
+
'clone',
|
|
232
|
+
'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
233
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
234
|
+
'--progress',
|
|
235
|
+
]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('if repo exists locally', () => {
|
|
239
|
+
let spinnerSuccessSpy;
|
|
240
|
+
beforeEach(async () => {
|
|
241
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
242
|
+
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
243
|
+
jest
|
|
244
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
245
|
+
.mockResolvedValue('/path/to/source/repo');
|
|
246
|
+
jest
|
|
247
|
+
.spyOn(gitModule, 'getGitConfig')
|
|
248
|
+
.mockResolvedValue('email-or-username');
|
|
249
|
+
mockGitClone();
|
|
250
|
+
await (0, setupRepo_1.setupRepo)({
|
|
251
|
+
repoName: 'kibana',
|
|
252
|
+
repoOwner: 'elastic',
|
|
253
|
+
cwd: '/path/to/source/repo',
|
|
254
|
+
interactive: true,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
it('should clone it from local folder', async () => {
|
|
258
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
|
|
259
|
+
expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
|
|
260
|
+
'clone',
|
|
261
|
+
'/path/to/source/repo',
|
|
262
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
263
|
+
'--progress',
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe('if `repoPath` is a parent of current working directory (cwd)', () => {
|
|
268
|
+
it('should clone it from local folder', async () => {
|
|
269
|
+
await expect(() => (0, setupRepo_1.setupRepo)({
|
|
270
|
+
repoName: 'kibana',
|
|
271
|
+
repoOwner: 'elastic',
|
|
272
|
+
cwd: '/myHomeDir/.backport/repositories/owner/repo/foo',
|
|
273
|
+
dir: '/myHomeDir/.backport/repositories/owner/repo',
|
|
274
|
+
interactive: true,
|
|
275
|
+
})).rejects.toThrowError('Refusing to clone repo into "/myHomeDir/.backport/repositories/owner/repo" when current working directory is "/myHomeDir/.backport/repositories/owner/repo/foo". Please change backport directory via `--dir` option or run backport from another location');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../options/options';
|
|
2
|
+
import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
3
|
+
export declare type ExpectedTargetPullRequest = {
|
|
4
|
+
url?: string;
|
|
5
|
+
number?: number;
|
|
6
|
+
branch: string;
|
|
7
|
+
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'NOT_CREATED';
|
|
8
|
+
mergeCommit?: {
|
|
9
|
+
sha: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }: {
|
|
14
|
+
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
15
|
+
latestBranchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
16
|
+
}): ExpectedTargetPullRequest[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExpectedTargetPullRequests = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const filterEmpty_1 = require("../../utils/filterEmpty");
|
|
6
|
+
const commitFormatters_1 = require("../github/commitFormatters");
|
|
7
|
+
const remoteConfig_1 = require("../remoteConfig");
|
|
8
|
+
function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }) {
|
|
9
|
+
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
+
const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
|
|
11
|
+
const branchLabelMapping = (remoteConfig && (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping) ??
|
|
12
|
+
latestBranchLabelMapping;
|
|
13
|
+
// if there is no source pull request the commit was pushed directly to the source branch
|
|
14
|
+
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
15
|
+
if (!sourcePullRequest) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
19
|
+
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
20
|
+
if (!branchLabelMapping) {
|
|
21
|
+
return existingTargetPullRequests;
|
|
22
|
+
}
|
|
23
|
+
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
24
|
+
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
25
|
+
}
|
|
26
|
+
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
27
|
+
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
28
|
+
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
29
|
+
return sourcePullRequest.timelineItems.edges
|
|
30
|
+
.filter(filterEmpty_1.filterNil)
|
|
31
|
+
.filter(filterPullRequests)
|
|
32
|
+
.filter((item) => {
|
|
33
|
+
const { targetPullRequest } = item.node;
|
|
34
|
+
// ignore closed PRs
|
|
35
|
+
if (targetPullRequest.state === 'CLOSED') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
39
|
+
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
40
|
+
const { targetCommit } = commitEdge.node;
|
|
41
|
+
const matchingRepoName = sourceCommit.repository.name === targetPullRequest.repository.name;
|
|
42
|
+
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
43
|
+
targetPullRequest.repository.owner.login;
|
|
44
|
+
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
45
|
+
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
46
|
+
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
47
|
+
});
|
|
48
|
+
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
49
|
+
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
50
|
+
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
51
|
+
})
|
|
52
|
+
.map((item) => {
|
|
53
|
+
const { targetPullRequest } = item.node;
|
|
54
|
+
return {
|
|
55
|
+
url: targetPullRequest.url,
|
|
56
|
+
number: targetPullRequest.number,
|
|
57
|
+
branch: targetPullRequest.baseRefName,
|
|
58
|
+
state: targetPullRequest.state,
|
|
59
|
+
mergeCommit: targetPullRequest.targetMergeCommit
|
|
60
|
+
? {
|
|
61
|
+
sha: targetPullRequest.targetMergeCommit.sha,
|
|
62
|
+
message: targetPullRequest.targetMergeCommit.message,
|
|
63
|
+
}
|
|
64
|
+
: undefined,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
69
|
+
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
70
|
+
const targetBranchesFromLabels = labels
|
|
71
|
+
.map((label) => getTargetBranchForLabel({ branchLabelMapping, label }))
|
|
72
|
+
.filter(filterEmpty_1.filterNil)
|
|
73
|
+
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
74
|
+
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
75
|
+
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
76
|
+
return expected
|
|
77
|
+
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
78
|
+
.map((branch) => {
|
|
79
|
+
return { branch, state: 'NOT_CREATED' };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
83
|
+
function filterPullRequests(item) {
|
|
84
|
+
const { targetPullRequest } = item.node;
|
|
85
|
+
return targetPullRequest.__typename === 'PullRequest';
|
|
86
|
+
}
|
|
87
|
+
function getTargetBranchForLabel({ branchLabelMapping, label, }) {
|
|
88
|
+
// only get first match
|
|
89
|
+
const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
|
|
90
|
+
const regex = new RegExp(labelPattern);
|
|
91
|
+
const isMatch = label.match(regex) !== null;
|
|
92
|
+
return isMatch;
|
|
93
|
+
});
|
|
94
|
+
if (result) {
|
|
95
|
+
const [labelPattern, targetBranchPattern] = result;
|
|
96
|
+
const regex = new RegExp(labelPattern);
|
|
97
|
+
const targetBranch = label.replace(regex, targetBranchPattern);
|
|
98
|
+
if (targetBranch) {
|
|
99
|
+
return targetBranch;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|