backport 7.3.6 → 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 +16 -21
- package/dist/backportRun.d.ts +18 -6
- package/dist/backportRun.js +70 -50
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +17 -19
- package/dist/entrypoint.module.private.test.js +129 -330
- 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 +6 -4
- package/dist/options/cliArgs.d.ts +16 -9
- package/dist/options/cliArgs.js +54 -28
- package/dist/options/cliArgs.test.js +128 -4
- package/dist/options/config/config.d.ts +7 -6
- package/dist/options/config/config.js +5 -7
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +5 -3
- package/dist/options/config/globalConfig.js +17 -14
- package/dist/options/config/projectConfig.d.ts +2 -2
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +19 -7
- package/dist/options/config/readConfigFile.d.ts +9 -7
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +44 -9
- package/dist/options/options.js +22 -27
- package/dist/options/options.test.js +119 -58
- package/dist/runSequentially.d.ts +14 -7
- package/dist/runSequentially.js +26 -11
- package/dist/scripts/postinstall.js +4 -3
- package/dist/scripts/postinstall.test.js +6 -2
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +7 -3
- package/dist/services/HandledError.js +13 -13
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +189 -127
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -158
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +4 -2
- package/dist/services/github/v3/createStatusComment.js +17 -17
- package/dist/services/github/v3/createStatusComment.test.js +22 -9
- package/dist/services/github/v4/apiRequestV4.js +8 -11
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.d.ts +1 -4
- package/dist/services/logger.js +14 -19
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
- package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +450 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +27 -28
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +12 -10
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +17 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -7
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +3 -3
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +17 -17
- package/yarn.lock +461 -695
package/dist/services/git.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = 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");
|
|
7
7
|
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
8
|
-
const
|
|
8
|
+
const BackportError_1 = require("./BackportError");
|
|
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");
|
|
@@ -16,37 +16,47 @@ function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, rep
|
|
|
16
16
|
exports.getRemoteUrl = getRemoteUrl;
|
|
17
17
|
async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const subprocess = (0, child_process_promisified_1.spawnOriginal)('git', [
|
|
20
|
+
'clone',
|
|
21
|
+
sourcePath,
|
|
22
|
+
targetPath,
|
|
23
|
+
'--progress',
|
|
24
|
+
]);
|
|
22
25
|
const progress = {
|
|
23
26
|
fileUpdate: 0,
|
|
24
27
|
objectReceive: 0,
|
|
25
28
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
subprocess.on('error', (err) => reject(err));
|
|
30
|
+
subprocess.stderr.on('data', (data) => {
|
|
31
|
+
logger_1.logger.verbose(data);
|
|
32
|
+
const [, objectReceiveProgress] = data.toString().match(/^Receiving objects:\s+(\d+)%/) || [];
|
|
33
|
+
if (objectReceiveProgress) {
|
|
34
|
+
progress.objectReceive = parseInt(objectReceiveProgress, 10);
|
|
35
|
+
}
|
|
36
|
+
const [, fileUpdateProgress] = data.toString().match(/^Updating files:\s+(\d+)%/) || [];
|
|
37
|
+
if (fileUpdateProgress) {
|
|
38
|
+
progress.objectReceive = 100;
|
|
39
|
+
progress.fileUpdate = parseInt(fileUpdateProgress, 10);
|
|
40
|
+
}
|
|
41
|
+
const progressSum = Math.round(progress.fileUpdate * 0.1 + progress.objectReceive * 0.9);
|
|
42
|
+
if (progressSum > 0) {
|
|
43
|
+
onProgress(progressSum);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
subprocess.on('close', (code) => {
|
|
47
|
+
if (code === 0 || code === null) {
|
|
48
|
+
resolve();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
reject(new Error(`Git clone failed with exit code: ${code}`));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
44
54
|
});
|
|
45
55
|
}
|
|
46
56
|
exports.cloneRepo = cloneRepo;
|
|
47
57
|
async function getLocalConfigFileCommitDate({ cwd }) {
|
|
48
58
|
try {
|
|
49
|
-
const { stdout } = await (0, child_process_promisified_1.
|
|
59
|
+
const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', '-1', '--format=%cd', '.backportrc.json'], cwd);
|
|
50
60
|
const timestamp = Date.parse(stdout);
|
|
51
61
|
if (timestamp > 0) {
|
|
52
62
|
return timestamp;
|
|
@@ -60,7 +70,7 @@ exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
|
|
|
60
70
|
async function isLocalConfigFileUntracked({ cwd }) {
|
|
61
71
|
try {
|
|
62
72
|
// list untracked files
|
|
63
|
-
const { stdout } = await (0, child_process_promisified_1.
|
|
73
|
+
const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['ls-files', '.backportrc.json', '--exclude-standard', '--others'], cwd);
|
|
64
74
|
return !!stdout;
|
|
65
75
|
}
|
|
66
76
|
catch (e) {
|
|
@@ -70,17 +80,17 @@ async function isLocalConfigFileUntracked({ cwd }) {
|
|
|
70
80
|
exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
|
|
71
81
|
async function isLocalConfigFileModified({ cwd }) {
|
|
72
82
|
try {
|
|
73
|
-
const { stdout } = await (0, child_process_promisified_1.
|
|
83
|
+
const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', 'HEAD', '--name-only', '.backportrc.json'], cwd);
|
|
74
84
|
return !!stdout;
|
|
75
85
|
}
|
|
76
86
|
catch (e) {
|
|
77
|
-
return;
|
|
87
|
+
return false;
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
exports.isLocalConfigFileModified = isLocalConfigFileModified;
|
|
81
91
|
async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
82
92
|
try {
|
|
83
|
-
const { stdout } = await (0, child_process_promisified_1.
|
|
93
|
+
const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['remote', '--verbose'], cwd);
|
|
84
94
|
const remotes = stdout
|
|
85
95
|
.split('\n')
|
|
86
96
|
.map((line) => {
|
|
@@ -100,9 +110,8 @@ async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
|
100
110
|
exports.getRepoInfoFromGitRemotes = getRepoInfoFromGitRemotes;
|
|
101
111
|
async function getGitProjectRootPath(dir) {
|
|
102
112
|
try {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
});
|
|
113
|
+
const cwd = dir;
|
|
114
|
+
const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-parse', '--show-toplevel'], cwd);
|
|
106
115
|
return stdout.trim();
|
|
107
116
|
}
|
|
108
117
|
catch (e) {
|
|
@@ -113,37 +122,45 @@ async function getGitProjectRootPath(dir) {
|
|
|
113
122
|
exports.getGitProjectRootPath = getGitProjectRootPath;
|
|
114
123
|
async function getIsCommitInBranch(options, commitSha) {
|
|
115
124
|
try {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
125
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
126
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['merge-base', '--is-ancestor', commitSha, 'HEAD'], cwd);
|
|
119
127
|
return true;
|
|
120
128
|
}
|
|
121
129
|
catch (e) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
131
|
+
if (isSpawnError) {
|
|
132
|
+
const commitNotInBranch = e.context.code === 1 && e.context.stderr === '';
|
|
133
|
+
const commitNotExist = e.context.code === 128 &&
|
|
134
|
+
e.context.stderr.includes('Not a valid object name');
|
|
135
|
+
if (commitNotInBranch || commitNotExist) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
126
138
|
}
|
|
127
|
-
|
|
139
|
+
throw e;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
142
|
exports.getIsCommitInBranch = getIsCommitInBranch;
|
|
131
143
|
async function deleteRemote(options, remoteName) {
|
|
132
144
|
try {
|
|
133
|
-
|
|
145
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
146
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['remote', 'rm', remoteName], cwd);
|
|
134
147
|
}
|
|
135
148
|
catch (e) {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
150
|
+
if (isSpawnError &&
|
|
151
|
+
e.context.code > 0 &&
|
|
152
|
+
e.context.stderr.includes('No such remote')) {
|
|
153
|
+
return;
|
|
140
154
|
}
|
|
155
|
+
// re-throw
|
|
156
|
+
throw e;
|
|
141
157
|
}
|
|
142
158
|
}
|
|
143
159
|
exports.deleteRemote = deleteRemote;
|
|
144
160
|
async function addRemote(options, remoteName) {
|
|
145
161
|
try {
|
|
146
|
-
|
|
162
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
163
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['remote', 'add', remoteName, getRemoteUrl(options, remoteName)], cwd);
|
|
147
164
|
}
|
|
148
165
|
catch (e) {
|
|
149
166
|
// note: swallowing error
|
|
@@ -152,111 +169,131 @@ async function addRemote(options, remoteName) {
|
|
|
152
169
|
}
|
|
153
170
|
exports.addRemote = addRemote;
|
|
154
171
|
async function fetchBranch(options, branch) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
172
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
173
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['fetch', options.repoOwner, `${branch}:${branch}`, '--force'], cwd);
|
|
158
174
|
}
|
|
159
175
|
exports.fetchBranch = fetchBranch;
|
|
160
176
|
async function getIsMergeCommit(options, sha) {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
});
|
|
177
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
178
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-list', '-1', '--merges', `${sha}~1..${sha}`], cwd);
|
|
164
179
|
return res.stdout !== '';
|
|
165
180
|
}
|
|
166
181
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
167
182
|
async function getCommitsInMergeCommit(options, sha) {
|
|
168
183
|
try {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
});
|
|
184
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
185
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', `${sha}^1..${sha}^2`, '--pretty=format:%H'], cwd);
|
|
172
186
|
return res.stdout.split('\n');
|
|
173
187
|
}
|
|
174
188
|
catch (e) {
|
|
189
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
175
190
|
// swallow error
|
|
176
|
-
if (e.code === 128) {
|
|
191
|
+
if (isSpawnError && e.context.code === 128) {
|
|
177
192
|
return [];
|
|
178
193
|
}
|
|
179
194
|
throw e;
|
|
180
195
|
}
|
|
181
196
|
}
|
|
182
197
|
exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
|
|
183
|
-
async function
|
|
184
|
-
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
185
|
-
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
186
|
-
let shaOrRange = sha;
|
|
198
|
+
async function getShaOrRange(options, sha) {
|
|
187
199
|
if (!options.mainline) {
|
|
188
200
|
try {
|
|
189
201
|
const isMergeCommit = await getIsMergeCommit(options, sha);
|
|
190
202
|
if (isMergeCommit) {
|
|
191
203
|
const shas = await getCommitsInMergeCommit(options, sha);
|
|
192
|
-
|
|
204
|
+
return `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
|
|
193
205
|
}
|
|
194
206
|
}
|
|
195
207
|
catch (e) {
|
|
196
|
-
|
|
197
|
-
//
|
|
198
|
-
|
|
208
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
209
|
+
// swallow error if it's a 128 exit code
|
|
210
|
+
// exit 128 happens when the cherrypicked commit is empty which is handled below
|
|
211
|
+
// (128 also applies to many other types of errors)
|
|
212
|
+
if (!isSpawnError || e.context.code !== 128) {
|
|
199
213
|
throw e;
|
|
200
214
|
}
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
|
-
|
|
217
|
+
return sha;
|
|
218
|
+
}
|
|
219
|
+
async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
|
|
220
|
+
const shaOrRange = await getShaOrRange(options, sha);
|
|
221
|
+
const cmdArgs = [
|
|
222
|
+
'-c',
|
|
223
|
+
`user.name="${commitAuthor.name}"`,
|
|
224
|
+
'-c',
|
|
225
|
+
`user.email="${commitAuthor.email}"`,
|
|
226
|
+
`cherry-pick`,
|
|
227
|
+
...(options.mainline != undefined
|
|
228
|
+
? ['--mainline', `${options.mainline}`]
|
|
229
|
+
: []),
|
|
230
|
+
...(options.cherrypickRef === false ? [] : ['-x']),
|
|
231
|
+
shaOrRange,
|
|
232
|
+
];
|
|
204
233
|
try {
|
|
205
|
-
|
|
234
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
235
|
+
await (0, child_process_promisified_1.spawnPromise)('git', cmdArgs, cwd);
|
|
206
236
|
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
207
237
|
}
|
|
208
238
|
catch (e) {
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return { conflictingFiles, unstagedFiles, needsResolving: true };
|
|
239
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
240
|
+
if (isSpawnError) {
|
|
241
|
+
// missing `mainline` option
|
|
242
|
+
if (e.message.includes('is a merge but no -m option was given')) {
|
|
243
|
+
throw new BackportError_1.BackportError('Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the `mainline` argument:\n\n> backport --mainline\n\nor:\n\n> backport --mainline <parent-number>\n\nOr refer to the git documentation for more information: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt---mainlineparent-number');
|
|
244
|
+
}
|
|
245
|
+
// commit was already backported
|
|
246
|
+
if (e.message.includes('The previous cherry-pick is now empty')) {
|
|
247
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
248
|
+
throw new BackportError_1.BackportError(`Cherrypick failed because the selected commit (${shortSha}) is empty. ${mergedTargetPullRequest?.url
|
|
249
|
+
? `It looks like the commit was already backported in ${mergedTargetPullRequest.url}`
|
|
250
|
+
: 'Did you already backport this commit? '}`);
|
|
251
|
+
}
|
|
252
|
+
if (e.message.includes(`bad object ${sha}`)) {
|
|
253
|
+
throw new BackportError_1.BackportError(`Cherrypick failed because commit "${sha}" was not found`);
|
|
254
|
+
}
|
|
255
|
+
const isCherryPickError = e.context.cmdArgs.includes('cherry-pick') && e.context.code > 0;
|
|
256
|
+
if (isCherryPickError) {
|
|
257
|
+
const [conflictingFiles, unstagedFiles] = await Promise.all([
|
|
258
|
+
getConflictingFiles(options),
|
|
259
|
+
getUnstagedFiles(options),
|
|
260
|
+
]);
|
|
261
|
+
if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
|
|
262
|
+
return { conflictingFiles, unstagedFiles, needsResolving: true };
|
|
263
|
+
}
|
|
235
264
|
}
|
|
236
|
-
// re-throw error if
|
|
265
|
+
// re-throw error if it didn't match the handled cases above
|
|
237
266
|
throw e;
|
|
238
267
|
}
|
|
239
268
|
}
|
|
240
269
|
exports.cherrypick = cherrypick;
|
|
241
270
|
async function commitChanges(commit, options) {
|
|
242
|
-
const noVerifyFlag = options.noVerify ?
|
|
271
|
+
const noVerifyFlag = options.noVerify ? ['--no-verify'] : [];
|
|
272
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
243
273
|
try {
|
|
244
|
-
await (0, child_process_promisified_1.
|
|
245
|
-
|
|
246
|
-
|
|
274
|
+
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
275
|
+
'commit',
|
|
276
|
+
'--no-edit',
|
|
277
|
+
...noVerifyFlag, // bypass pre-commit and commit-msg hooks
|
|
278
|
+
], cwd);
|
|
247
279
|
}
|
|
248
280
|
catch (e) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
281
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
282
|
+
if (isSpawnError) {
|
|
283
|
+
if (e.context.stdout.includes('nothing to commit')) {
|
|
284
|
+
logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
// manually set the commit message if the inferred commit message is empty
|
|
288
|
+
// this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
|
|
289
|
+
if (e.context.stderr.includes('Aborting commit due to empty commit message')) {
|
|
290
|
+
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
291
|
+
'commit',
|
|
292
|
+
`--message=${commit.sourceCommit.message}`,
|
|
293
|
+
...noVerifyFlag, // bypass pre-commit and commit-msg hooks
|
|
294
|
+
], cwd);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
260
297
|
}
|
|
261
298
|
// rethrow error if it can't be handled
|
|
262
299
|
throw e;
|
|
@@ -266,13 +303,15 @@ exports.commitChanges = commitChanges;
|
|
|
266
303
|
async function getConflictingFiles(options) {
|
|
267
304
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
268
305
|
try {
|
|
269
|
-
|
|
306
|
+
const cwd = repoPath;
|
|
307
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', '--check'], cwd);
|
|
270
308
|
return [];
|
|
271
309
|
}
|
|
272
310
|
catch (e) {
|
|
273
|
-
const
|
|
311
|
+
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
312
|
+
const isConflictError = isSpawnError && e.context.code === 2;
|
|
274
313
|
if (isConflictError) {
|
|
275
|
-
const files = e.stdout
|
|
314
|
+
const files = e.context.stdout
|
|
276
315
|
.split('\n')
|
|
277
316
|
.filter((line) => !!line.trim() && !line.startsWith('+') && !line.startsWith('-'))
|
|
278
317
|
.map((line) => {
|
|
@@ -296,9 +335,8 @@ exports.getConflictingFiles = getConflictingFiles;
|
|
|
296
335
|
// retrieve the list of files that could not be cleanly merged
|
|
297
336
|
async function getUnstagedFiles(options) {
|
|
298
337
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
});
|
|
338
|
+
const cwd = repoPath;
|
|
339
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', '--name-only'], cwd);
|
|
302
340
|
const files = res.stdout
|
|
303
341
|
.split('\n')
|
|
304
342
|
.filter((file) => !!file)
|
|
@@ -308,8 +346,9 @@ async function getUnstagedFiles(options) {
|
|
|
308
346
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
309
347
|
async function getGitConfig({ dir, key, }) {
|
|
310
348
|
try {
|
|
311
|
-
const
|
|
312
|
-
|
|
349
|
+
const cwd = dir;
|
|
350
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['config', key], cwd);
|
|
351
|
+
return res.stdout.trim();
|
|
313
352
|
}
|
|
314
353
|
catch (e) {
|
|
315
354
|
return;
|
|
@@ -322,16 +361,30 @@ exports.getGitConfig = getGitConfig;
|
|
|
322
361
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
323
362
|
const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
|
|
324
363
|
try {
|
|
325
|
-
const
|
|
364
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
365
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['reset', '--hard'], cwd);
|
|
366
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['clean', '-d', '--force'], cwd);
|
|
367
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['fetch', options.repoOwner, targetBranch], cwd);
|
|
368
|
+
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
369
|
+
'checkout',
|
|
370
|
+
'-B',
|
|
371
|
+
backportBranch,
|
|
372
|
+
`${options.repoOwner}/${targetBranch}`,
|
|
373
|
+
'--no-track',
|
|
374
|
+
], cwd);
|
|
326
375
|
spinner.succeed();
|
|
327
|
-
return res;
|
|
328
376
|
}
|
|
329
377
|
catch (e) {
|
|
330
378
|
spinner.fail();
|
|
331
|
-
|
|
332
|
-
e.stderr
|
|
333
|
-
|
|
334
|
-
|
|
379
|
+
if (e instanceof child_process_promisified_1.SpawnError) {
|
|
380
|
+
const isBranchInvalid = e.context.stderr.toLowerCase().includes(`couldn't find remote ref`) ||
|
|
381
|
+
e.context.stderr.toLowerCase().includes(`invalid refspec`) ||
|
|
382
|
+
e.context.stderr
|
|
383
|
+
.toLowerCase()
|
|
384
|
+
.includes(`is not a commit and a branch '${backportBranch}' cannot be created from it`);
|
|
385
|
+
if (isBranchInvalid) {
|
|
386
|
+
throw new BackportError_1.BackportError(`The branch "${targetBranch}" is invalid or doesn't exist`);
|
|
387
|
+
}
|
|
335
388
|
}
|
|
336
389
|
throw e;
|
|
337
390
|
}
|
|
@@ -339,7 +392,10 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
339
392
|
exports.createBackportBranch = createBackportBranch;
|
|
340
393
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
341
394
|
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
342
|
-
|
|
395
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
396
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['reset', '--hard'], cwd);
|
|
397
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['checkout', options.sourceBranch], cwd);
|
|
398
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['branch', '--delete', '--force', backportBranch], cwd);
|
|
343
399
|
spinner.stop();
|
|
344
400
|
}
|
|
345
401
|
exports.deleteBackportBranch = deleteBackportBranch;
|
|
@@ -354,24 +410,30 @@ async function pushBackportBranch({ options, backportBranch, }) {
|
|
|
354
410
|
const repoForkOwner = getRepoForkOwner(options);
|
|
355
411
|
const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
356
412
|
try {
|
|
357
|
-
const
|
|
413
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
414
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['push', repoForkOwner, `${backportBranch}:${backportBranch}`, '--force'], cwd);
|
|
358
415
|
spinner.succeed();
|
|
359
416
|
return res;
|
|
360
417
|
}
|
|
361
418
|
catch (e) {
|
|
362
419
|
spinner.fail();
|
|
363
|
-
if (e
|
|
364
|
-
|
|
420
|
+
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
421
|
+
e.context.stderr.toLowerCase().includes(`repository not found`)) {
|
|
422
|
+
throw new BackportError_1.BackportError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode via "--no-fork".\nRead more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/configuration.md#fork`);
|
|
423
|
+
}
|
|
424
|
+
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
425
|
+
e.context.stderr.includes(`could not read Username for`)) {
|
|
426
|
+
throw new BackportError_1.BackportError(`Invalid credentials: ${e.message}`);
|
|
365
427
|
}
|
|
366
428
|
throw e;
|
|
367
429
|
}
|
|
368
430
|
}
|
|
369
431
|
exports.pushBackportBranch = pushBackportBranch;
|
|
370
432
|
// retrieve path to local repo (cwd) if it matches `repoName` / `repoOwner`
|
|
371
|
-
async function
|
|
433
|
+
async function getLocalSourceRepoPath(options) {
|
|
372
434
|
const remotes = await getRepoInfoFromGitRemotes({ cwd: options.cwd });
|
|
373
435
|
const hasMatchingGitRemote = remotes.some((remote) => remote.repoName === options.repoName &&
|
|
374
436
|
remote.repoOwner === options.repoOwner);
|
|
375
437
|
return hasMatchingGitRemote ? getGitProjectRootPath(options.cwd) : undefined;
|
|
376
438
|
}
|
|
377
|
-
exports.
|
|
439
|
+
exports.getLocalSourceRepoPath = getLocalSourceRepoPath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|