diff --git a/package-lock.json b/package-lock.json index c722c37c6..bd0ebd6ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "undici": "5.28.4" }, "devDependencies": { + "@octokit/webhooks-types": "^3.67.3", "@types/jest": "^29.5.12", "@typescript-eslint/eslint-plugin": "^7.16.1", "@typescript-eslint/parser": "^7.18.0", @@ -1432,6 +1433,12 @@ "@octokit/openapi-types": "^19.0.0" } }, + "node_modules/@octokit/webhooks-types": { + "version": "3.77.1", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-3.77.1.tgz", + "integrity": "sha512-6V2KdgvUler6ANmWt05p0jzOoZWvG36IHmcYmMqwYNNCu9asL2HjQgj3aP3EVf2foBzzRjp+1j0BKz48C6kohw==", + "dev": true + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -6325,6 +6332,12 @@ "@octokit/openapi-types": "^19.0.0" } }, + "@octokit/webhooks-types": { + "version": "3.77.1", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-3.77.1.tgz", + "integrity": "sha512-6V2KdgvUler6ANmWt05p0jzOoZWvG36IHmcYmMqwYNNCu9asL2HjQgj3aP3EVf2foBzzRjp+1j0BKz48C6kohw==", + "dev": true + }, "@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", diff --git a/package.json b/package.json index 33313a82a..4c299d985 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "undici": "5.28.4" }, "devDependencies": { + "@octokit/webhooks-types": "^3.67.3", "@types/jest": "^29.5.12", "@typescript-eslint/eslint-plugin": "^7.16.1", "@typescript-eslint/parser": "^7.18.0", diff --git a/src/buildExec.ts b/src/buildExec.ts index 77c4cd494..6c8d6d328 100644 --- a/src/buildExec.ts +++ b/src/buildExec.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; +import {type PullRequestEvent} from '@octokit/webhooks-types'; import {setFailure} from './helpers'; @@ -31,10 +32,7 @@ const getGitService = (): string => { const isPullRequestFromFork = (): boolean => { core.info(`evenName: ${context.eventName}`); - if ( - `${context.eventName}` !== 'pull_request' && - `${context.eventName}` !== 'pull_request_target' - ) { + if (!['pull_request', 'pull_request_target'].includes(context.eventName)) { return false; } @@ -42,7 +40,7 @@ const isPullRequestFromFork = (): boolean => { const headLabel = context.payload.pull_request.head.label; core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`); - return (baseLabel.split(':')[0] !== headLabel.split(':')[0]); + return baseLabel.split(':')[0] !== headLabel.split(':')[0]; }; const getToken = async (): Promise => { @@ -87,9 +85,9 @@ const buildCommitExec = async (): Promise<{ const workingDir = core.getInput('working-directory'); const commitCommand = 'create-commit'; - const commitExecArgs = []; + const commitExecArgs: string[] = []; - const commitOptions:any = {}; + const commitOptions: any = {}; commitOptions.env = Object.assign(process.env, { GITHUB_ACTION: process.env.GITHUB_ACTION, GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, @@ -99,35 +97,33 @@ const buildCommitExec = async (): Promise<{ GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '', }); - if (token) { commitOptions.env.CODECOV_TOKEN = token; } if (commitParent) { - commitExecArgs.push('--parent-sha', `${commitParent}`); + commitExecArgs.push('--parent-sha', commitParent); } - commitExecArgs.push('--git-service', `${gitService}`); + commitExecArgs.push('--git-service', gitService); if (overrideBranch) { - commitExecArgs.push('-B', `${overrideBranch}`); + commitExecArgs.push('-B', overrideBranch); } if (overrideCommit) { - commitExecArgs.push('-C', `${overrideCommit}`); + commitExecArgs.push('-C', overrideCommit); } else if ( - `${context.eventName}` == 'pull_request' || - `${context.eventName}` == 'pull_request_target' + ['pull_request', 'pull_request_target'].includes(context.eventName) ) { - commitExecArgs.push('-C', `${context.payload.pull_request.head.sha}`); + const payload = context.payload as PullRequestEvent; + commitExecArgs.push('-C', payload.pull_request.head.sha); } if (overridePr) { - commitExecArgs.push('--pr', `${overridePr}`); - } else if ( - `${context.eventName}` == 'pull_request_target' - ) { - commitExecArgs.push('--pr', `${context.payload.number}`); + commitExecArgs.push('--pr', overridePr); + } else if (context.eventName === 'pull_request_target') { + const payload = context.payload as PullRequestEvent; + commitExecArgs.push('--pr', payload.number.toString()); } if (slug) { - commitExecArgs.push('--slug', `${slug}`); + commitExecArgs.push('--slug', slug); } if (failCi) { commitExecArgs.push('-Z'); @@ -136,7 +132,6 @@ const buildCommitExec = async (): Promise<{ commitOptions.cwd = workingDir; } - return {commitExecArgs, commitOptions, commitCommand}; }; @@ -150,10 +145,10 @@ const buildGeneralExec = (): { const args = []; if (codecovYmlPath) { - args.push('--codecov-yml-path', `${codecovYmlPath}`); + args.push('--codecov-yml-path', codecovYmlPath); } if (url) { - args.push('--enterprise-url', `${url}`); + args.push('--enterprise-url', url); } if (verbose) { args.push('-v'); @@ -174,11 +169,10 @@ const buildReportExec = async (): Promise<{ const failCi = isTrue(core.getInput('fail_ci_if_error')); const workingDir = core.getInput('working-directory'); - const reportCommand = 'create-report'; - const reportExecArgs = []; + const reportExecArgs: string[] = []; - const reportOptions:any = {}; + const reportOptions: any = {}; reportOptions.env = Object.assign(process.env, { GITHUB_ACTION: process.env.GITHUB_ACTION, GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, @@ -188,29 +182,27 @@ const buildReportExec = async (): Promise<{ GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '', }); - if (token) { reportOptions.env.CODECOV_TOKEN = token; } - reportExecArgs.push('--git-service', `${gitService}`); + reportExecArgs.push('--git-service', gitService); if (overrideCommit) { - reportExecArgs.push('-C', `${overrideCommit}`); + reportExecArgs.push('-C', overrideCommit); } else if ( - `${context.eventName}` == 'pull_request' || - `${context.eventName}` == 'pull_request_target' + ['pull_request', 'pull_request_target'].includes(context.eventName) ) { - reportExecArgs.push('-C', `${context.payload.pull_request.head.sha}`); + const payload = context.payload as PullRequestEvent; + reportExecArgs.push('-C', payload.pull_request.head.sha); } if (overridePr) { - reportExecArgs.push('-P', `${overridePr}`); - } else if ( - `${context.eventName}` == 'pull_request_target' - ) { - reportExecArgs.push('-P', `${context.payload.number}`); + reportExecArgs.push('-P', overridePr); + } else if (context.eventName == 'pull_request_target') { + const payload = context.payload as PullRequestEvent; + reportExecArgs.push('-P', payload.number.toString()); } if (slug) { - reportExecArgs.push('--slug', `${slug}`); + reportExecArgs.push('--slug', slug); } if (failCi) { reportExecArgs.push('-Z'); @@ -266,9 +258,9 @@ const buildUploadExec = async (): Promise<{ ); const workingDir = core.getInput('working-directory'); - const uploadExecArgs = []; + const uploadExecArgs: string[] = []; const uploadCommand = 'do-upload'; - const uploadOptions:any = {}; + const uploadOptions: any = {}; uploadOptions.env = Object.assign(process.env, { GITHUB_ACTION: process.env.GITHUB_ACTION, GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, @@ -302,85 +294,94 @@ const buildUploadExec = async (): Promise<{ uploadExecArgs.push('-e', envVarsArg.join(',')); } if (exclude) { - uploadExecArgs.push('--exclude', `${exclude}`); + uploadExecArgs.push('--exclude', exclude); } if (failCi) { uploadExecArgs.push('-Z'); } if (file) { - uploadExecArgs.push('-f', `${file}`); + uploadExecArgs.push('-f', file); } if (files) { - files.split(',').map((f) => f.trim()).forEach((f) => { - if (f.length > 0) { // this handles trailing commas - uploadExecArgs.push('-f', `${f}`); - } - }); + files + .split(',') + .map((f) => f.trim()) + .forEach((f) => { + if (f.length > 0) { + // this handles trailing commas + uploadExecArgs.push('-f', f); + } + }); } if (flags) { - flags.split(',').map((f) => f.trim()).forEach((f) => { - uploadExecArgs.push('-F', `${f}`); - }); - } - uploadExecArgs.push('--git-service', `${gitService}`); + flags + .split(',') + .map((f) => f.trim()) + .forEach((f) => { + uploadExecArgs.push('-F', f); + }); + } + uploadExecArgs.push('--git-service', gitService); if (handleNoReportsFound) { uploadExecArgs.push('--handle-no-reports-found'); } if (jobCode) { - uploadExecArgs.push('--job-code', `${jobCode}`); + uploadExecArgs.push('--job-code', jobCode); } if (name) { - uploadExecArgs.push('-n', `${name}`); + uploadExecArgs.push('-n', name); } if (networkFilter) { - uploadExecArgs.push('--network-filter', `${networkFilter}`); + uploadExecArgs.push('--network-filter', networkFilter); } if (networkPrefix) { - uploadExecArgs.push('--network-prefix', `${networkPrefix}`); + uploadExecArgs.push('--network-prefix', networkPrefix); } if (overrideBranch) { - uploadExecArgs.push('-B', `${overrideBranch}`); + uploadExecArgs.push('-B', overrideBranch); } if (overrideBuild) { - uploadExecArgs.push('-b', `${overrideBuild}`); + uploadExecArgs.push('-b', overrideBuild); } if (overrideBuildUrl) { - uploadExecArgs.push('--build-url', `${overrideBuildUrl}`); + uploadExecArgs.push('--build-url', overrideBuildUrl); } if (overrideCommit) { - uploadExecArgs.push('-C', `${overrideCommit}`); + uploadExecArgs.push('-C', overrideCommit); } else if ( - `${context.eventName}` == 'pull_request' || - `${context.eventName}` == 'pull_request_target' + ['pull_request', 'pull_request_target'].includes(context.eventName) ) { - uploadExecArgs.push('-C', `${context.payload.pull_request.head.sha}`); + const payload = context.payload as PullRequestEvent; + uploadExecArgs.push('-C', payload.pull_request.head.sha); } if (overridePr) { - uploadExecArgs.push('-P', `${overridePr}`); - } else if ( - `${context.eventName}` == 'pull_request_target' - ) { - uploadExecArgs.push('-P', `${context.payload.number}`); + uploadExecArgs.push('-P', overridePr); + } else if (context.eventName == 'pull_request_target') { + const payload = context.payload as PullRequestEvent; + uploadExecArgs.push('-P', payload.number.toString()); } if (plugin) { - uploadExecArgs.push('--plugin', `${plugin}`); + uploadExecArgs.push('--plugin', plugin); } if (plugins) { - plugins.split(',').map((p) => p.trim()).forEach((p) => { - uploadExecArgs.push('--plugin', `${p}`); - }); + plugins + .split(',') + .map((p) => p.trim()) + .forEach((p) => { + uploadExecArgs.push('--plugin', p); + }); } if (reportCode) { - uploadExecArgs.push('--report-code', `${reportCode}`); + uploadExecArgs.push('--report-code', reportCode); } if (rootDir) { - uploadExecArgs.push('--network-root-folder', `${rootDir}`); + uploadExecArgs.push('--network-root-folder', rootDir); } if (searchDir) { - uploadExecArgs.push('-s', `${searchDir}`); + uploadExecArgs.push('-s', searchDir); } if (slug) { - uploadExecArgs.push('-r', `${slug}`); + uploadExecArgs.push('-r', slug); } if (workingDir) { uploadOptions.cwd = workingDir; @@ -403,10 +404,4 @@ const buildUploadExec = async (): Promise<{ }; }; - -export { - buildCommitExec, - buildGeneralExec, - buildReportExec, - buildUploadExec, -}; +export {buildCommitExec, buildGeneralExec, buildReportExec, buildUploadExec};