diff --git a/dist/index.js b/dist/index.js index 199be5a..a0424b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28934,15 +28934,6 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.retrieve = void 0; const github = __importStar(__nccwpck_require__(5438)); @@ -28954,73 +28945,67 @@ const github = __importStar(__nccwpck_require__(5438)); * * @returns string[] */ -function retrieve(inputs, token) { +async function retrieve(inputs, token) { var _a, _b; - return __awaiter(this, void 0, void 0, function* () { - const result = []; - switch (github.context.eventName) { - case 'pull_request': { - const pullRequest = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request; - if (pullRequest) { - return extractMessagesFromPullRequest( - // Action payloads are the same as WebHook payloads, so cast is safe. - pullRequest, inputs, token); - } - else { - throw new Error(`No pull_request found in the payload.`); - } - break; + const result = []; + switch (github.context.eventName) { + case 'pull_request': { + const pullRequest = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request; + if (pullRequest) { + return extractMessagesFromPullRequest( + // Action payloads are the same as WebHook payloads, so cast is safe. + pullRequest, inputs, token); } - case 'push': { - const commits = (_b = github.context.payload) === null || _b === void 0 ? void 0 : _b.commits; - if (commits) { - for (const commit of commits) { - if (commit.message) { - result.push(commit.message); - } + else { + throw new Error(`No pull_request found in the payload.`); + } + break; + } + case 'push': { + const commits = (_b = github.context.payload) === null || _b === void 0 ? void 0 : _b.commits; + if (commits) { + for (const commit of commits) { + if (commit.message) { + result.push(commit.message); } } - if (result.length === 0) { - throw new Error(`No commits found in the payload.`); - } - break; } - default: { - throw new Error(`Unhandled event: ${github.context.eventName}`); + if (result.length === 0) { + throw new Error(`No commits found in the payload.`); } + break; } - return result; - }); + default: { + throw new Error(`Unhandled event: ${github.context.eventName}`); + } + } + return result; } exports.retrieve = retrieve; -function extractMessagesFromPullRequest(pullRequest, inputs, token) { - return __awaiter(this, void 0, void 0, function* () { - if (!inputs.validatePullRequestCommits) { - let msg = pullRequest.title; - if (pullRequest.body) { - msg = msg.concat('\n\n', pullRequest.body); - } - return [msg]; +async function extractMessagesFromPullRequest(pullRequest, inputs, token) { + if (!inputs.validatePullRequestCommits) { + let msg = pullRequest.title; + if (pullRequest.body) { + msg = msg.concat('\n\n', pullRequest.body); } - return getCommits(pullRequest, token); - }); + return [msg]; + } + return getCommits(pullRequest, token); } -function getCommits(pullRequest, token) { +async function getCommits(pullRequest, token) { var _a; - return __awaiter(this, void 0, void 0, function* () { - // Head repository where commits are registered. Value is null when the PR within a single repository, - // in which use base repository instead. - const repo = (_a = pullRequest.head.repo) !== null && _a !== void 0 ? _a : pullRequest.base.repo; - if (repo.private && token === undefined) { - throw new Error('GitHub token is required to validate pull request commits on private repository.'); - } - const octokit = github.getOctokit(token !== null && token !== void 0 ? token : ''); - const commits = yield octokit.request({ - method: 'GET', - url: pullRequest.commits_url, - }); - return commits.data.map(({ commit }) => commit.message); + // Head repository where commits are registered. Value is null when the PR within a single repository, + // in which use base repository instead. + const repo = (_a = pullRequest.head.repo) !== null && _a !== void 0 ? _a : pullRequest.base.repo; + if (repo.private && token === undefined) { + throw new Error('GitHub token is required to validate pull request commits on private repository.'); + } + const octokit = github.getOctokit(token !== null && token !== void 0 ? token : ''); + const commits = await octokit.request({ + method: 'GET', + url: pullRequest.commits_url, }); + return commits.data.map(({ commit }) => commit.message); } @@ -29547,15 +29532,6 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = void 0; const core = __importStar(__nccwpck_require__(2186)); @@ -29563,97 +29539,93 @@ const commitMessages = __importStar(__nccwpck_require__(8611)); const inspection = __importStar(__nccwpck_require__(7647)); const represent = __importStar(__nccwpck_require__(4478)); const input = __importStar(__nccwpck_require__(6747)); -function runWithExceptions() { - return __awaiter(this, void 0, void 0, function* () { - //// - // Parse inputs - //// - const additionalVerbsInput = core.getInput('additional-verbs', { - required: false, - }); - const pathToAdditionalVerbsInput = core.getInput('path-to-additional-verbs', { - required: false, - }); - const allowOneLinersInput = core.getInput('allow-one-liners', { - required: false, - }); - const maxSubjectLengthInput = core.getInput('max-subject-line-length', { - required: false, - }); - const maxBodyLineLengthInput = core.getInput('max-body-line-length', { - required: false, - }); - const enforceSignOffInput = core.getInput('enforce-sign-off', { - required: false, - }); - const validatePullRequestCommitsInput = core.getInput('validate-pull-request-commits', { - required: false, - }); - const skipBodyCheckInput = core.getInput('skip-body-check', { - required: false, - }); - const ignoreMergeCommitsInput = core.getInput('ignore-merge-commits', { - required: false, - }); - const ignorePatternsInput = core.getInput('ignore-patterns', { - required: false, - }); - const maybeInputs = input.parseInputs({ - additionalVerbsInput, - pathToAdditionalVerbsInput, - allowOneLinersInput, - maxSubjectLengthInput, - maxBodyLineLengthInput, - enforceSignOffInput, - validatePullRequestCommitsInput, - skipBodyCheckInput, - ignoreMergeCommitsInput, - ignorePatternsInput, - }); - if (maybeInputs.error !== null) { - core.error(maybeInputs.error); - core.setFailed(maybeInputs.error); - return; - } - const inputs = maybeInputs.mustInputs(); - const messages = yield commitMessages.retrieve(inputs, core.getInput('github-token', { required: false })); - //// - // Inspect - //// - // Parts of the error message to be concatenated with '\n' - const parts = []; - for (const [messageIndex, message] of messages.entries()) { - const errors = inspection.check(message, inputs); - if (errors.length > 0) { - const repr = represent.formatErrors(message, messageIndex, errors); - parts.push(repr); - } - else { - core.info(`The message is OK:\n---\n${message}\n---`); - } +async function runWithExceptions() { + //// + // Parse inputs + //// + const additionalVerbsInput = core.getInput('additional-verbs', { + required: false, + }); + const pathToAdditionalVerbsInput = core.getInput('path-to-additional-verbs', { + required: false, + }); + const allowOneLinersInput = core.getInput('allow-one-liners', { + required: false, + }); + const maxSubjectLengthInput = core.getInput('max-subject-line-length', { + required: false, + }); + const maxBodyLineLengthInput = core.getInput('max-body-line-length', { + required: false, + }); + const enforceSignOffInput = core.getInput('enforce-sign-off', { + required: false, + }); + const validatePullRequestCommitsInput = core.getInput('validate-pull-request-commits', { + required: false, + }); + const skipBodyCheckInput = core.getInput('skip-body-check', { + required: false, + }); + const ignoreMergeCommitsInput = core.getInput('ignore-merge-commits', { + required: false, + }); + const ignorePatternsInput = core.getInput('ignore-patterns', { + required: false, + }); + const maybeInputs = input.parseInputs({ + additionalVerbsInput, + pathToAdditionalVerbsInput, + allowOneLinersInput, + maxSubjectLengthInput, + maxBodyLineLengthInput, + enforceSignOffInput, + validatePullRequestCommitsInput, + skipBodyCheckInput, + ignoreMergeCommitsInput, + ignorePatternsInput, + }); + if (maybeInputs.error !== null) { + core.error(maybeInputs.error); + core.setFailed(maybeInputs.error); + return; + } + const inputs = maybeInputs.mustInputs(); + const messages = await commitMessages.retrieve(inputs, core.getInput('github-token', { required: false })); + //// + // Inspect + //// + // Parts of the error message to be concatenated with '\n' + const parts = []; + for (const [messageIndex, message] of messages.entries()) { + const errors = inspection.check(message, inputs); + if (errors.length > 0) { + const repr = represent.formatErrors(message, messageIndex, errors); + parts.push(repr); } - const errorMessage = parts.join('\n'); - if (errorMessage.length > 0) { - core.setFailed(errorMessage); + else { + core.info(`The message is OK:\n---\n${message}\n---`); } - }); + } + const errorMessage = parts.join('\n'); + if (errorMessage.length > 0) { + core.setFailed(errorMessage); + } } /** * Main function */ -function run() { - return __awaiter(this, void 0, void 0, function* () { - return runWithExceptions().catch(error => { - if (error instanceof Error) { - core.error(error); - core.setFailed(error.message); - } - else { - const message = `Unexpected error value: ${error}`; - core.error(message); - core.setFailed(message); - } - }); +async function run() { + return runWithExceptions().catch(error => { + if (error instanceof Error) { + core.error(error); + core.setFailed(error.message); + } + else { + const message = `Unexpected error value: ${error}`; + core.error(message); + core.setFailed(message); + } }); } exports.run = run; diff --git a/tsconfig.json b/tsconfig.json index aaf5824..188af16 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "outDir": "./lib", /* Redirect output structure to the directory. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */