backport 5.6.4 → 6.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 +166 -41
- package/dist/entrypoint.cli.js +3 -1
- package/dist/entrypoint.module.d.ts +18 -5
- package/dist/entrypoint.module.js +42 -12
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +33 -0
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -25
- package/dist/options/ConfigOptions.d.ts +56 -39
- package/dist/options/cliArgs.d.ts +38 -45
- package/dist/options/cliArgs.js +123 -104
- package/dist/options/cliArgs.test.js +106 -119
- package/dist/options/config/config.d.ts +56 -2
- package/dist/options/config/config.js +12 -6
- package/dist/options/config/config.test.js +11 -6
- package/dist/options/config/getOptionsFromGit.d.ts +4 -0
- package/dist/options/config/getOptionsFromGit.js +8 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- package/dist/options/config/globalConfig.js +9 -12
- package/dist/options/config/globalConfig.test.js +7 -5
- package/dist/options/config/projectConfig.d.ts +2 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +54 -17
- package/dist/options/config/readConfigFile.d.ts +53 -2
- package/dist/options/config/readConfigFile.js +31 -5
- package/dist/options/options.d.ts +67 -35
- package/dist/options/options.js +99 -16
- package/dist/options/options.test.js +214 -67
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +68 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +122 -0
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +192 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +2 -2
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +23 -5
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +133 -60
- package/dist/services/git.test.js +160 -53
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +32 -26
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +78 -0
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
- package/dist/services/github/v4/apiRequestV4.js +9 -11
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -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.d.ts +10 -2
- package/dist/services/github/v4/fetchAuthorId.js +6 -7
- package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +63 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +24 -24
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +105 -61
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +317 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +3 -3
- package/dist/test/nockHelpers.js +7 -11
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -51
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +333 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +3 -2
- package/dist/ui/getTargetBranches.js +33 -18
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +11 -10
- package/dist/ui/maybeSetupRepo.test.js +54 -4
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +37 -51
- package/yarn.lock +2416 -2987
package/dist/services/git.js
CHANGED
|
@@ -3,11 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.addRemote = exports.deleteRemote = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
|
|
6
|
+
exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getRepoOwnerAndNameFromGitRemote = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const del_1 = __importDefault(require("del"));
|
|
9
|
-
const
|
|
10
|
-
const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
11
10
|
const ora_1 = __importDefault(require("ora"));
|
|
12
11
|
const HandledError_1 = require("./HandledError");
|
|
13
12
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
@@ -17,7 +16,7 @@ const commitFormatters_1 = require("./github/commitFormatters");
|
|
|
17
16
|
const logger_1 = require("./logger");
|
|
18
17
|
async function folderExists(path) {
|
|
19
18
|
try {
|
|
20
|
-
const stats = await fs_promisified_1.stat(path);
|
|
19
|
+
const stats = await (0, fs_promisified_1.stat)(path);
|
|
21
20
|
return stats.isDirectory();
|
|
22
21
|
}
|
|
23
22
|
catch (e) {
|
|
@@ -28,15 +27,15 @@ async function folderExists(path) {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
function repoExists(options) {
|
|
31
|
-
return folderExists(env_1.getRepoPath(options));
|
|
30
|
+
return folderExists((0, env_1.getRepoPath)(options));
|
|
32
31
|
}
|
|
33
32
|
exports.repoExists = repoExists;
|
|
34
33
|
function deleteRepo(options) {
|
|
35
|
-
const repoPath = env_1.getRepoPath(options);
|
|
36
|
-
return del_1.default(repoPath);
|
|
34
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
35
|
+
return (0, del_1.default)(repoPath);
|
|
37
36
|
}
|
|
38
37
|
exports.deleteRepo = deleteRepo;
|
|
39
|
-
function getRemoteUrl({ repoName, accessToken, gitHostname }, repoOwner) {
|
|
38
|
+
function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, repoOwner) {
|
|
40
39
|
return `https://x-access-token:${accessToken}@${gitHostname}/${repoOwner}/${repoName}.git`;
|
|
41
40
|
}
|
|
42
41
|
exports.getRemoteUrl = getRemoteUrl;
|
|
@@ -50,7 +49,7 @@ function cloneRepo(options, callback) {
|
|
|
50
49
|
resolve();
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
|
-
const execProcess = child_process_promisified_1.execAsCallback(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: env_1.getRepoOwnerPath(options), maxBuffer: 100 * 1024 * 1024 }, cb);
|
|
52
|
+
const execProcess = (0, child_process_promisified_1.execAsCallback)(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: (0, env_1.getRepoOwnerPath)(options), maxBuffer: 100 * 1024 * 1024 }, cb);
|
|
54
53
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
55
54
|
if (execProcess.stderr) {
|
|
56
55
|
execProcess.stderr.on('data', (data) => {
|
|
@@ -64,9 +63,75 @@ function cloneRepo(options, callback) {
|
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
exports.cloneRepo = cloneRepo;
|
|
66
|
+
async function getLocalConfigFileCommitDate() {
|
|
67
|
+
try {
|
|
68
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=%cd .backportrc.js*', {});
|
|
69
|
+
const timestamp = Date.parse(stdout);
|
|
70
|
+
if (timestamp > 0) {
|
|
71
|
+
return timestamp;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
|
|
79
|
+
async function isLocalConfigFileUntracked() {
|
|
80
|
+
try {
|
|
81
|
+
// list untracked files
|
|
82
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git ls-files .backportrc.js* --exclude-standard --others', {});
|
|
83
|
+
return !!stdout;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
|
|
90
|
+
async function isLocalConfigFileModified() {
|
|
91
|
+
try {
|
|
92
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager diff HEAD --name-only .backportrc.js*', {});
|
|
93
|
+
return !!stdout;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.isLocalConfigFileModified = isLocalConfigFileModified;
|
|
100
|
+
async function getRepoOwnerAndNameFromGitRemote() {
|
|
101
|
+
try {
|
|
102
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git remote --verbose', {});
|
|
103
|
+
const matches = stdout.match(/github.com[:/]{1}(.*).git/);
|
|
104
|
+
if (matches !== null) {
|
|
105
|
+
const [repoOwner, repoName] = matches[1].split('/');
|
|
106
|
+
return { repoOwner, repoName };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.getRepoOwnerAndNameFromGitRemote = getRepoOwnerAndNameFromGitRemote;
|
|
114
|
+
async function getIsCommitInBranch(options, commitSha) {
|
|
115
|
+
try {
|
|
116
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
117
|
+
await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
|
|
118
|
+
cwd,
|
|
119
|
+
});
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
const isExecError = e.cmd && e.code > 0;
|
|
124
|
+
// re-throw if error is not an exec related error
|
|
125
|
+
if (!isExecError) {
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.getIsCommitInBranch = getIsCommitInBranch;
|
|
67
132
|
async function deleteRemote(options, remoteName) {
|
|
68
133
|
try {
|
|
69
|
-
await child_process_promisified_1.exec(`git remote rm ${remoteName}`, { cwd: env_1.getRepoPath(options) });
|
|
134
|
+
await (0, child_process_promisified_1.exec)(`git remote rm ${remoteName}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
70
135
|
}
|
|
71
136
|
catch (e) {
|
|
72
137
|
const isExecError = e.cmd && e.code > 0;
|
|
@@ -79,7 +144,7 @@ async function deleteRemote(options, remoteName) {
|
|
|
79
144
|
exports.deleteRemote = deleteRemote;
|
|
80
145
|
async function addRemote(options, remoteName) {
|
|
81
146
|
try {
|
|
82
|
-
await child_process_promisified_1.exec(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: env_1.getRepoPath(options) });
|
|
147
|
+
await (0, child_process_promisified_1.exec)(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
83
148
|
}
|
|
84
149
|
catch (e) {
|
|
85
150
|
// note: swallowing error
|
|
@@ -87,13 +152,19 @@ async function addRemote(options, remoteName) {
|
|
|
87
152
|
}
|
|
88
153
|
}
|
|
89
154
|
exports.addRemote = addRemote;
|
|
90
|
-
async function
|
|
91
|
-
await child_process_promisified_1.exec(`git fetch ${options.repoOwner} ${
|
|
92
|
-
|
|
93
|
-
|
|
155
|
+
async function fetchBranch(options, branch) {
|
|
156
|
+
await (0, child_process_promisified_1.exec)(`git fetch ${options.repoOwner} ${branch}:${branch} --force`, {
|
|
157
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
exports.fetchBranch = fetchBranch;
|
|
161
|
+
async function cherrypick(options, sha) {
|
|
162
|
+
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
163
|
+
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
164
|
+
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
|
|
94
165
|
try {
|
|
95
|
-
await child_process_promisified_1.exec(cmd, { cwd: env_1.getRepoPath(options) });
|
|
96
|
-
return { needsResolving: false };
|
|
166
|
+
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
167
|
+
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
97
168
|
}
|
|
98
169
|
catch (e) {
|
|
99
170
|
// missing `mainline` option
|
|
@@ -102,21 +173,24 @@ async function cherrypick(options, commit) {
|
|
|
102
173
|
}
|
|
103
174
|
// commit was already backported
|
|
104
175
|
if (e.message.includes('The previous cherry-pick is now empty')) {
|
|
105
|
-
const shortSha = commitFormatters_1.getShortSha(
|
|
176
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
106
177
|
throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
107
178
|
}
|
|
108
179
|
// git info missing
|
|
109
180
|
if (e.message.includes('Please tell me who you are')) {
|
|
110
181
|
throw new HandledError_1.HandledError(`Cherrypick failed:\n${e.message}`);
|
|
111
182
|
}
|
|
112
|
-
if (e.message.includes(`bad object ${
|
|
113
|
-
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${
|
|
183
|
+
if (e.message.includes(`bad object ${sha}`)) {
|
|
184
|
+
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
|
|
114
185
|
}
|
|
115
186
|
const isCherryPickError = e.cmd === cmd;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
187
|
+
if (isCherryPickError) {
|
|
188
|
+
const [conflictingFiles, unstagedFiles] = await Promise.all([
|
|
189
|
+
getConflictingFiles(options),
|
|
190
|
+
getUnstagedFiles(options),
|
|
191
|
+
]);
|
|
192
|
+
if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
|
|
193
|
+
return { conflictingFiles, unstagedFiles, needsResolving: true };
|
|
120
194
|
}
|
|
121
195
|
// re-throw error if there are no conflicts to solve
|
|
122
196
|
throw e;
|
|
@@ -124,23 +198,22 @@ async function cherrypick(options, commit) {
|
|
|
124
198
|
}
|
|
125
199
|
exports.cherrypick = cherrypick;
|
|
126
200
|
async function commitChanges(commit, options) {
|
|
127
|
-
|
|
128
|
-
const noVerify = options.noVerify ? ` --no-verify` : '';
|
|
201
|
+
const noVerifyFlag = options.noVerify ? ` --no-verify` : '';
|
|
129
202
|
try {
|
|
130
|
-
await child_process_promisified_1.exec(`git commit --no-edit${
|
|
131
|
-
cwd: env_1.getRepoPath(options),
|
|
203
|
+
await (0, child_process_promisified_1.exec)(`git commit --no-edit${noVerifyFlag}`, {
|
|
204
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
132
205
|
});
|
|
133
206
|
}
|
|
134
207
|
catch (e) {
|
|
135
|
-
if (
|
|
208
|
+
if (e.stdout?.includes('nothing to commit')) {
|
|
136
209
|
logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
|
|
137
210
|
return;
|
|
138
211
|
}
|
|
139
212
|
// manually set the commit message if the inferred commit message is empty
|
|
140
213
|
// this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
|
|
141
|
-
if (
|
|
142
|
-
await child_process_promisified_1.exec(`git commit -m "${commit.originalMessage}" ${
|
|
143
|
-
cwd: env_1.getRepoPath(options),
|
|
214
|
+
if (e.stderr?.includes('Aborting commit due to empty commit message')) {
|
|
215
|
+
await (0, child_process_promisified_1.exec)(`git commit -m "${commit.originalMessage}" ${noVerifyFlag}`, {
|
|
216
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
144
217
|
});
|
|
145
218
|
return;
|
|
146
219
|
}
|
|
@@ -150,9 +223,9 @@ async function commitChanges(commit, options) {
|
|
|
150
223
|
}
|
|
151
224
|
exports.commitChanges = commitChanges;
|
|
152
225
|
async function getConflictingFiles(options) {
|
|
153
|
-
const repoPath = env_1.getRepoPath(options);
|
|
226
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
154
227
|
try {
|
|
155
|
-
await child_process_promisified_1.exec(`git --no-pager diff --check`, { cwd: repoPath });
|
|
228
|
+
await (0, child_process_promisified_1.exec)(`git --no-pager diff --check`, { cwd: repoPath });
|
|
156
229
|
return [];
|
|
157
230
|
}
|
|
158
231
|
catch (e) {
|
|
@@ -164,9 +237,15 @@ async function getConflictingFiles(options) {
|
|
|
164
237
|
.map((line) => {
|
|
165
238
|
const posSeparator = line.indexOf(':');
|
|
166
239
|
const filename = line.slice(0, posSeparator).trim();
|
|
167
|
-
return
|
|
240
|
+
return filename;
|
|
241
|
+
});
|
|
242
|
+
const uniqueFiles = (0, lodash_1.uniq)(files);
|
|
243
|
+
return uniqueFiles.map((file) => {
|
|
244
|
+
return {
|
|
245
|
+
absolute: (0, path_1.resolve)(repoPath, file),
|
|
246
|
+
relative: file,
|
|
247
|
+
};
|
|
168
248
|
});
|
|
169
|
-
return lodash_uniq_1.default(files);
|
|
170
249
|
}
|
|
171
250
|
// rethrow error since it's unrelated
|
|
172
251
|
throw e;
|
|
@@ -175,21 +254,21 @@ async function getConflictingFiles(options) {
|
|
|
175
254
|
exports.getConflictingFiles = getConflictingFiles;
|
|
176
255
|
// retrieve the list of files that could not be cleanly merged
|
|
177
256
|
async function getUnstagedFiles(options) {
|
|
178
|
-
const repoPath = env_1.getRepoPath(options);
|
|
179
|
-
const res = await child_process_promisified_1.exec(`git --no-pager diff --name-only`, {
|
|
257
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
258
|
+
const res = await (0, child_process_promisified_1.exec)(`git --no-pager diff --name-only`, {
|
|
180
259
|
cwd: repoPath,
|
|
181
260
|
});
|
|
182
261
|
const files = res.stdout
|
|
183
262
|
.split('\n')
|
|
184
263
|
.filter((file) => !!file)
|
|
185
|
-
.map((file) => path_1.resolve(repoPath, file));
|
|
186
|
-
return
|
|
264
|
+
.map((file) => (0, path_1.resolve)(repoPath, file));
|
|
265
|
+
return (0, lodash_1.uniq)(files);
|
|
187
266
|
}
|
|
188
267
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
189
|
-
async function setCommitAuthor(options,
|
|
190
|
-
const spinner = ora_1.default(`Changing author to "${
|
|
268
|
+
async function setCommitAuthor(options, author) {
|
|
269
|
+
const spinner = (0, ora_1.default)(`Changing author to "${author}"`).start();
|
|
191
270
|
try {
|
|
192
|
-
const res = await child_process_promisified_1.exec(`git commit --amend --no-edit --author "${
|
|
271
|
+
const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
193
272
|
spinner.succeed();
|
|
194
273
|
return res;
|
|
195
274
|
}
|
|
@@ -203,16 +282,16 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
203
282
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
204
283
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
205
284
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
206
|
-
|
|
207
|
-
const spinner = ora_1.default('Pulling latest changes').start();
|
|
285
|
+
const spinner = (0, ora_1.default)('Pulling latest changes').start();
|
|
208
286
|
try {
|
|
209
|
-
const res = await child_process_promisified_1.exec(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: env_1.getRepoPath(options) });
|
|
287
|
+
const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
210
288
|
spinner.succeed();
|
|
211
289
|
return res;
|
|
212
290
|
}
|
|
213
291
|
catch (e) {
|
|
214
292
|
spinner.fail();
|
|
215
|
-
const isBranchInvalid =
|
|
293
|
+
const isBranchInvalid = e.stderr?.toLowerCase().includes(`couldn't find remote ref`) ||
|
|
294
|
+
e.stderr?.toLowerCase().includes(`invalid refspec`);
|
|
216
295
|
if (isBranchInvalid) {
|
|
217
296
|
throw new HandledError_1.HandledError(`The branch "${targetBranch}" is invalid or doesn't exist`);
|
|
218
297
|
}
|
|
@@ -221,8 +300,8 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
221
300
|
}
|
|
222
301
|
exports.createBackportBranch = createBackportBranch;
|
|
223
302
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
224
|
-
const spinner = ora_1.default().start();
|
|
225
|
-
await child_process_promisified_1.exec(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: env_1.getRepoPath(options) });
|
|
303
|
+
const spinner = (0, ora_1.default)().start();
|
|
304
|
+
await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
226
305
|
spinner.stop();
|
|
227
306
|
}
|
|
228
307
|
exports.deleteBackportBranch = deleteBackportBranch;
|
|
@@ -230,27 +309,21 @@ exports.deleteBackportBranch = deleteBackportBranch;
|
|
|
230
309
|
* Returns the repo owner of the forked repo or the source repo
|
|
231
310
|
*/
|
|
232
311
|
function getRepoForkOwner(options) {
|
|
233
|
-
return options.fork ? options.
|
|
312
|
+
return options.fork ? options.authenticatedUsername : options.repoOwner;
|
|
234
313
|
}
|
|
235
314
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
236
315
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
237
|
-
var _a;
|
|
238
316
|
const repoForkOwner = getRepoForkOwner(options);
|
|
239
|
-
const
|
|
240
|
-
const spinner = ora_1.default(spinnerText).start();
|
|
241
|
-
if (options.dryRun) {
|
|
242
|
-
spinner.succeed(`Dry run: ${spinnerText}`);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
317
|
+
const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
245
318
|
try {
|
|
246
|
-
const res = await child_process_promisified_1.exec(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: env_1.getRepoPath(options) });
|
|
319
|
+
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
247
320
|
spinner.succeed();
|
|
248
321
|
return res;
|
|
249
322
|
}
|
|
250
323
|
catch (e) {
|
|
251
324
|
spinner.fail();
|
|
252
|
-
if (
|
|
253
|
-
throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode "--fork
|
|
325
|
+
if (e.stderr?.toLowerCase().includes(`repository not found`)) {
|
|
326
|
+
throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode "--no-fork". Read more about "fork mode" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork`);
|
|
254
327
|
}
|
|
255
328
|
throw e;
|
|
256
329
|
}
|