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/logger.js
CHANGED
|
@@ -22,9 +22,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.initLogger = exports.
|
|
25
|
+
exports.initLogger = exports.redactAccessToken = exports.updateLogger = exports.logger = exports.consoleLog = void 0;
|
|
26
26
|
const dedent_1 = __importDefault(require("dedent"));
|
|
27
|
-
const
|
|
27
|
+
const lodash_1 = require("lodash");
|
|
28
28
|
const safe_json_stringify_1 = __importDefault(require("safe-json-stringify"));
|
|
29
29
|
const winston_1 = __importStar(require("winston"));
|
|
30
30
|
const env_1 = require("./env");
|
|
@@ -33,70 +33,70 @@ let winstonInstance;
|
|
|
33
33
|
// wrapper around console.log
|
|
34
34
|
function consoleLog(message) {
|
|
35
35
|
// eslint-disable-next-line no-console
|
|
36
|
-
console.log(
|
|
36
|
+
console.log(redactAccessToken(message));
|
|
37
37
|
//process.stdout.write(message);
|
|
38
38
|
}
|
|
39
39
|
exports.consoleLog = consoleLog;
|
|
40
40
|
exports.logger = {
|
|
41
41
|
error: (message, meta) => {
|
|
42
|
-
winstonInstance.error(message, { meta });
|
|
42
|
+
winstonInstance.error(message, null, { meta });
|
|
43
43
|
},
|
|
44
44
|
warn: (message, meta) => {
|
|
45
|
-
winstonInstance.warn(message, { meta });
|
|
45
|
+
winstonInstance.warn(message, null, { meta });
|
|
46
46
|
},
|
|
47
47
|
info: (message, meta) => {
|
|
48
|
-
winstonInstance.info(message, { meta });
|
|
48
|
+
winstonInstance.info(message, null, { meta });
|
|
49
49
|
},
|
|
50
50
|
verbose: (message, meta) => {
|
|
51
|
-
winstonInstance.verbose(message, { meta });
|
|
51
|
+
winstonInstance.verbose(message, null, { meta });
|
|
52
52
|
},
|
|
53
53
|
debug: (message, meta) => {
|
|
54
|
-
winstonInstance.debug(message, { meta });
|
|
54
|
+
winstonInstance.debug(message, null, { meta });
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
|
-
let
|
|
57
|
+
let accessToken;
|
|
58
58
|
function updateLogger(options) {
|
|
59
|
-
|
|
59
|
+
accessToken = options.accessToken;
|
|
60
60
|
// set log level
|
|
61
|
-
|
|
62
|
-
winstonInstance.level = 'debug';
|
|
63
|
-
}
|
|
61
|
+
winstonInstance.level = options.verbose ? 'debug' : 'info';
|
|
64
62
|
// output logs to console in ci env
|
|
65
63
|
if (options.ci) {
|
|
66
64
|
winstonInstance.add(new winston_1.default.transports.Console());
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
exports.updateLogger = updateLogger;
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
function redactAccessToken(str) {
|
|
69
|
+
// `redactAccessToken` might be called before access token is set
|
|
70
|
+
if (accessToken) {
|
|
71
|
+
return str.replace(new RegExp(accessToken, 'g'), '<REDACTED>');
|
|
73
72
|
}
|
|
74
73
|
return str;
|
|
75
74
|
}
|
|
76
|
-
exports.
|
|
75
|
+
exports.redactAccessToken = redactAccessToken;
|
|
77
76
|
function initLogger() {
|
|
78
77
|
winstonInstance = winston_1.default.createLogger({
|
|
79
78
|
transports: [
|
|
80
79
|
// log to file
|
|
81
80
|
new winston_1.default.transports.File({
|
|
82
|
-
|
|
81
|
+
level: 'debug',
|
|
82
|
+
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
83
83
|
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
84
84
|
}), winston_1.format.printf((info) => {
|
|
85
85
|
// format without metadata
|
|
86
86
|
if (!info.metadata.meta) {
|
|
87
|
-
return
|
|
87
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
88
88
|
}
|
|
89
89
|
// format when metadata is a string
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
90
|
+
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
91
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
92
92
|
}
|
|
93
93
|
if (info.metadata.meta.stack) {
|
|
94
|
-
return
|
|
94
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
95
95
|
}
|
|
96
96
|
// format when metadata is an object
|
|
97
|
-
return
|
|
97
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
98
98
|
})),
|
|
99
|
-
filename: env_1.getLogfilePath(),
|
|
99
|
+
filename: (0, env_1.getLogfilePath)(),
|
|
100
100
|
}),
|
|
101
101
|
],
|
|
102
102
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
7
|
+
const prompts_1 = require("./prompts");
|
|
8
|
+
describe('prompt', () => {
|
|
9
|
+
describe('getChoicesForCommitPrompt', () => {
|
|
10
|
+
it('should display status badges via `expectedTargetPullRequests`', () => {
|
|
11
|
+
const commits = [
|
|
12
|
+
{
|
|
13
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
14
|
+
originalMessage: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
15
|
+
pullNumber: 119700,
|
|
16
|
+
expectedTargetPullRequests: [
|
|
17
|
+
{ number: 120178, branch: '8.0', state: 'MERGED' },
|
|
18
|
+
{ number: 120179, branch: '7.16', state: 'MERGED' },
|
|
19
|
+
{ number: 120179, branch: '7.15', state: 'MISSING' },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
|
|
24
|
+
expect(choices).toEqual([
|
|
25
|
+
{
|
|
26
|
+
name: '1. [APM] Remove log-log descriptions from correlation charts (#119700) 8.0, 7.16, 7.15',
|
|
27
|
+
short: '#119700 (ae9d51b7)',
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
it('should list choices', () => {
|
|
32
|
+
const commits = [
|
|
33
|
+
{
|
|
34
|
+
committedDate: '',
|
|
35
|
+
sourceBranch: 'master',
|
|
36
|
+
sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
|
|
37
|
+
originalMessage: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
38
|
+
pullNumber: 120694,
|
|
39
|
+
expectedTargetPullRequests: [],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
committedDate: '',
|
|
43
|
+
sourceBranch: 'master',
|
|
44
|
+
sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
|
|
45
|
+
originalMessage: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
46
|
+
pullNumber: 120106,
|
|
47
|
+
expectedTargetPullRequests: [],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
committedDate: '',
|
|
51
|
+
sourceBranch: 'master',
|
|
52
|
+
sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
|
|
53
|
+
originalMessage: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
54
|
+
pullNumber: 119915,
|
|
55
|
+
expectedTargetPullRequests: [],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
committedDate: '',
|
|
59
|
+
sourceBranch: 'master',
|
|
60
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
61
|
+
originalMessage: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
62
|
+
pullNumber: 119700,
|
|
63
|
+
expectedTargetPullRequests: [],
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
|
|
67
|
+
expect(choices).toEqual([
|
|
68
|
+
{
|
|
69
|
+
name: '1. [APM] Prefer service.name for logs correlation (#120694) ',
|
|
70
|
+
short: '#120694 (b1b49195)',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: '2. [APM] Disable telemetry in agent config endpoint (#120106) ',
|
|
74
|
+
short: '#120106 (b1bb4a93)',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: '3. [APM] Remove index_pattern.json and add custom field formatters (#119915) ',
|
|
78
|
+
short: '#119915 (434f6e6a)',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: '4. [APM] Remove log-log descriptions from correlation charts (#119700) ',
|
|
82
|
+
short: '#119700 (ae9d51b7)',
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Commit } from '
|
|
3
|
-
export declare function
|
|
1
|
+
import { TargetBranchChoice } from '../options/ConfigOptions';
|
|
2
|
+
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
3
|
+
export declare function getChoicesForCommitPrompt(commits: Commit[], showDetails: boolean): {
|
|
4
|
+
name: string;
|
|
5
|
+
short: string;
|
|
6
|
+
value: Commit;
|
|
7
|
+
}[];
|
|
8
|
+
export declare function promptForCommits({ commitChoices, isMultipleChoice, showDetails, }: {
|
|
4
9
|
commitChoices: Commit[];
|
|
5
10
|
isMultipleChoice: boolean;
|
|
11
|
+
showDetails: boolean;
|
|
6
12
|
}): Promise<Commit[]>;
|
|
7
13
|
export declare function promptForTargetBranches({ targetBranchChoices, isMultipleChoice, }: {
|
|
8
|
-
targetBranchChoices:
|
|
14
|
+
targetBranchChoices: TargetBranchChoice[];
|
|
9
15
|
isMultipleChoice: boolean;
|
|
10
16
|
}): Promise<string[]>;
|
|
11
17
|
export declare function confirmPrompt(message: string): Promise<boolean>;
|
package/dist/services/prompts.js
CHANGED
|
@@ -3,10 +3,11 @@ 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.confirmPrompt = exports.promptForTargetBranches = exports.promptForCommits = void 0;
|
|
6
|
+
exports.confirmPrompt = exports.promptForTargetBranches = exports.promptForCommits = exports.getChoicesForCommitPrompt = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
-
const
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
10
11
|
const commitFormatters_1 = require("./github/commitFormatters");
|
|
11
12
|
async function prompt(options) {
|
|
12
13
|
const { promptResult } = (await inquirer_1.default.prompt([
|
|
@@ -14,33 +15,95 @@ async function prompt(options) {
|
|
|
14
15
|
]));
|
|
15
16
|
return promptResult;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
function getPrStateIcon(state) {
|
|
19
|
+
if (state === 'MERGED') {
|
|
20
|
+
return '🟢';
|
|
21
|
+
}
|
|
22
|
+
if (state === 'MISSING') {
|
|
23
|
+
return '🔴';
|
|
24
|
+
}
|
|
25
|
+
if (state === 'OPEN') {
|
|
26
|
+
return '🔵';
|
|
27
|
+
}
|
|
28
|
+
// unknown state
|
|
29
|
+
return '🔴';
|
|
30
|
+
}
|
|
31
|
+
function getPrStateText(state) {
|
|
32
|
+
if (state === 'MERGED') {
|
|
33
|
+
return chalk_1.default.gray('Merged');
|
|
34
|
+
}
|
|
35
|
+
if (state === 'MISSING') {
|
|
36
|
+
return chalk_1.default.gray('Backport missing');
|
|
37
|
+
}
|
|
38
|
+
if (state === 'OPEN') {
|
|
39
|
+
return chalk_1.default.gray('Open, not merged');
|
|
40
|
+
}
|
|
41
|
+
return chalk_1.default.gray('Unknown state');
|
|
42
|
+
}
|
|
43
|
+
function getPrLink(number, url) {
|
|
44
|
+
return url ? `(${(0, terminal_link_1.default)(`#${number}`, url)})` : '';
|
|
45
|
+
}
|
|
46
|
+
function getDetailedPullStatus(c) {
|
|
47
|
+
const items = c.expectedTargetPullRequests.map((pr) => {
|
|
48
|
+
const prLink = getPrLink(pr.number, pr.url);
|
|
49
|
+
return ` └ ${getPrStateIcon(pr.state)} ${pr.branch} ${prLink} ${getPrStateText(pr.state)}`;
|
|
33
50
|
});
|
|
51
|
+
const list = items.length > 0
|
|
52
|
+
? `\n${chalk_1.default.reset(items.join('\n'))}`
|
|
53
|
+
: `\n └ ${chalk_1.default.gray('No backports expected')}`;
|
|
54
|
+
return `${list}\n`;
|
|
55
|
+
}
|
|
56
|
+
function getSimplePullStatus(c) {
|
|
57
|
+
return c.expectedTargetPullRequests
|
|
58
|
+
.map(({ state, branch }) => {
|
|
59
|
+
if (state === 'MERGED') {
|
|
60
|
+
return chalk_1.default.green(branch);
|
|
61
|
+
}
|
|
62
|
+
if (state === 'MISSING') {
|
|
63
|
+
return chalk_1.default.red(branch);
|
|
64
|
+
}
|
|
65
|
+
if (state === 'OPEN') {
|
|
66
|
+
return chalk_1.default.gray(branch);
|
|
67
|
+
}
|
|
68
|
+
return chalk_1.default.gray('Unknown state');
|
|
69
|
+
})
|
|
70
|
+
.join(', ');
|
|
71
|
+
}
|
|
72
|
+
function getChoicesForCommitPrompt(commits, showDetails) {
|
|
73
|
+
return commits.map((c, i) => {
|
|
74
|
+
const leadingWhitespace = (0, lodash_1.repeat)(' ', 2 - (i + 1).toString().length);
|
|
75
|
+
const position = chalk_1.default.gray(`${i + 1}.${leadingWhitespace}`);
|
|
76
|
+
let name;
|
|
77
|
+
if (showDetails) {
|
|
78
|
+
const message = (0, commitFormatters_1.stripPullNumber)(c.originalMessage);
|
|
79
|
+
const prLink = c.pullUrl ? ` ` + getPrLink(c.pullNumber, c.pullUrl) : '';
|
|
80
|
+
const detailsList = getDetailedPullStatus(c);
|
|
81
|
+
name = `${position}${message}${prLink}${detailsList}`;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const message = (0, commitFormatters_1.getFirstLine)(c.originalMessage);
|
|
85
|
+
const pullStates = getSimplePullStatus(c);
|
|
86
|
+
name = `${position}${message} ${pullStates}`;
|
|
87
|
+
}
|
|
88
|
+
const short = c.pullNumber
|
|
89
|
+
? `#${c.pullNumber} (${(0, commitFormatters_1.getShortSha)(c.sha)})`
|
|
90
|
+
: (0, commitFormatters_1.getShortSha)(c.sha);
|
|
91
|
+
return { name, short, value: c };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.getChoicesForCommitPrompt = getChoicesForCommitPrompt;
|
|
95
|
+
async function promptForCommits({ commitChoices, isMultipleChoice, showDetails, }) {
|
|
96
|
+
const choices = getChoicesForCommitPrompt(commitChoices, showDetails);
|
|
34
97
|
const res = await prompt({
|
|
35
98
|
loop: false,
|
|
36
|
-
pageSize:
|
|
99
|
+
pageSize: 30,
|
|
37
100
|
choices: choices,
|
|
38
101
|
message: 'Select commit',
|
|
39
102
|
type: isMultipleChoice ? 'checkbox' : 'list',
|
|
40
103
|
});
|
|
41
104
|
const selectedCommits = Array.isArray(res) ? res.reverse() : [res];
|
|
42
|
-
return
|
|
43
|
-
? promptForCommits({ commitChoices
|
|
105
|
+
return (0, lodash_1.isEmpty)(selectedCommits)
|
|
106
|
+
? promptForCommits({ commitChoices, isMultipleChoice, showDetails })
|
|
44
107
|
: selectedCommits;
|
|
45
108
|
}
|
|
46
109
|
exports.promptForCommits = promptForCommits;
|
|
@@ -53,7 +116,7 @@ async function promptForTargetBranches({ targetBranchChoices, isMultipleChoice,
|
|
|
53
116
|
type: isMultipleChoice ? 'checkbox' : 'list',
|
|
54
117
|
});
|
|
55
118
|
const selectedBranches = Array.isArray(res) ? res : [res];
|
|
56
|
-
return
|
|
119
|
+
return (0, lodash_1.isEmpty)(selectedBranches)
|
|
57
120
|
? promptForTargetBranches({
|
|
58
121
|
targetBranchChoices,
|
|
59
122
|
isMultipleChoice,
|
|
@@ -0,0 +1,9 @@
|
|
|
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' | 'MISSING';
|
|
8
|
+
};
|
|
9
|
+
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
|
|
8
|
+
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
9
|
+
// if there is no source pull request the commit was pushed directly to the source branch
|
|
10
|
+
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
11
|
+
if (!sourcePullRequest) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
15
|
+
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
16
|
+
if (!branchLabelMapping) {
|
|
17
|
+
return existingTargetPullRequests;
|
|
18
|
+
}
|
|
19
|
+
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
20
|
+
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
21
|
+
}
|
|
22
|
+
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
23
|
+
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
24
|
+
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
25
|
+
return sourcePullRequest.timelineItems.edges
|
|
26
|
+
.filter(filterEmpty_1.filterNil)
|
|
27
|
+
.filter(filterPullRequests)
|
|
28
|
+
.filter((item) => {
|
|
29
|
+
const { targetPullRequest } = item.node;
|
|
30
|
+
// ignore closed PRs
|
|
31
|
+
if (targetPullRequest.state === 'CLOSED') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
35
|
+
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
36
|
+
const { targetCommit } = commitEdge.node;
|
|
37
|
+
const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
|
|
38
|
+
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
39
|
+
targetCommit.repository.owner.login;
|
|
40
|
+
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
41
|
+
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
42
|
+
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
43
|
+
});
|
|
44
|
+
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
45
|
+
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
46
|
+
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
47
|
+
})
|
|
48
|
+
.map((item) => {
|
|
49
|
+
const { targetPullRequest } = item.node;
|
|
50
|
+
return {
|
|
51
|
+
url: targetPullRequest.url,
|
|
52
|
+
number: targetPullRequest.number,
|
|
53
|
+
branch: targetPullRequest.baseRefName,
|
|
54
|
+
state: targetPullRequest.state,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
59
|
+
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
60
|
+
const targetBranchesFromLabels = labels
|
|
61
|
+
.map((label) => getTargetBranchForLabel({ branchLabelMapping, label }))
|
|
62
|
+
.filter(filterEmpty_1.filterNil)
|
|
63
|
+
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
64
|
+
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
65
|
+
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
66
|
+
return expected
|
|
67
|
+
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
68
|
+
.map((branch) => {
|
|
69
|
+
return { branch, state: 'MISSING' };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
73
|
+
function filterPullRequests(item) {
|
|
74
|
+
const { targetPullRequest } = item.node;
|
|
75
|
+
return targetPullRequest.__typename === 'PullRequest';
|
|
76
|
+
}
|
|
77
|
+
function getTargetBranchForLabel({ branchLabelMapping, label, }) {
|
|
78
|
+
// only get first match
|
|
79
|
+
const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
|
|
80
|
+
const regex = new RegExp(labelPattern);
|
|
81
|
+
const isMatch = label.match(regex) !== null;
|
|
82
|
+
return isMatch;
|
|
83
|
+
});
|
|
84
|
+
if (result) {
|
|
85
|
+
const [labelPattern, targetBranchPattern] = result;
|
|
86
|
+
const regex = new RegExp(labelPattern);
|
|
87
|
+
const targetBranch = label.replace(regex, targetBranchPattern);
|
|
88
|
+
if (targetBranch) {
|
|
89
|
+
return targetBranch;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|