diff --git a/action.yaml b/action.yaml index 868d2b0..13f0374 100644 --- a/action.yaml +++ b/action.yaml @@ -10,6 +10,12 @@ inputs: description: "GitHub Token" required: true + # Optional + include-file-comments: + description: "Include file comments in the output." + required: false + default: "true" + runs: using: "node20" main: "build/index.js" diff --git a/build/index.js b/build/index.js index 0da3783..10da68e 100644 --- a/build/index.js +++ b/build/index.js @@ -18737,7 +18737,7 @@ var require_core = __commonJS({ return inputs.map((input) => input.trim()); } exports2.getMultilineInput = getMultilineInput; - function getBooleanInput(name, options) { + function getBooleanInput2(name, options) { const trueValue = ["true", "True", "TRUE"]; const falseValue = ["false", "False", "FALSE"]; const val = getInput2(name, options); @@ -18748,7 +18748,7 @@ var require_core = __commonJS({ throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name} Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); } - exports2.getBooleanInput = getBooleanInput; + exports2.getBooleanInput = getBooleanInput2; function setOutput(name, value) { const filePath = process.env["GITHUB_OUTPUT"] || ""; if (filePath) { @@ -26962,14 +26962,14 @@ var require_commonjs = __commonJS({ * Find a value for which the supplied fn method returns a truthy value, * similar to Array.find(). fn is called as fn(value, key, cache). */ - find(fn, getOptions = {}) { + find(fn, getOptions2 = {}) { for (const i of this.#indexes()) { const v = this.#valList[i]; const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v; if (value === void 0) continue; if (fn(value, this.#keyList[i], this)) { - return this.get(this.#keyList[i], getOptions); + return this.get(this.#keyList[i], getOptions2); } } } @@ -27489,8 +27489,8 @@ var require_commonjs = __commonJS({ * * If the key is not found, get() will return `undefined`. */ - get(k, getOptions = {}) { - const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions; + get(k, getOptions2 = {}) { + const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions2; const index = this.#keyMap.get(k); if (index !== void 0) { const value = this.#valList[index]; @@ -31461,14 +31461,15 @@ async function run() { runInfo, pullRequestData ); - core.info("pythonFiles: " + JSON.stringify(pythonFiles)); if (pythonFiles.length === 0) { core.info("No Python files have changed."); return; } await installPyright(); const pyrightReport = await runPyright(pythonFiles); - await commentOnPR(runInfo, pyrightReport, pullRequestData); + if (runInfo.options.includeFileComments) + await addFileComments(runInfo, pyrightReport, pullRequestData); + await addSummaryComment(runInfo, pyrightReport, pullRequestData); } catch (error) { core.setFailed(`Action failed with error: ${error}`); } @@ -31477,7 +31478,12 @@ var getRunInfo = () => { const token = core.getInput("github-token", { required: true }); const octokit = new Octokit2({ auth: token }); const context2 = github.context; - return { token, octokit, context: context2 }; + const options = getOptions(); + return { token, octokit, context: context2, options }; +}; +var getOptions = () => { + const includeFileComments = core.getBooleanInput("include-file-comments") ?? true; + return { includeFileComments }; }; async function getChangedPythonFiles(runInfo, pullRequest) { const { octokit, context: context2 } = runInfo; @@ -31515,7 +31521,8 @@ async function runPyright(files) { await (0, import_exec.exec)(pyrightCommand, [], options); return parseReport(JSON.parse(output)); } -async function commentOnPR(runInfo, report, pullRequest) { +async function addFileComments(runInfo, report, pullRequest) { + core.info("Generating file comments."); const { octokit, context: context2 } = runInfo; const diagnostics = report.generalDiagnostics; const { data: existingReviewComments } = await octokit.rest.pulls.listReviewComments({ @@ -31608,7 +31615,10 @@ async function commentOnPR(runInfo, report, pullRequest) { comment_id: comment.id }); } +} +async function addSummaryComment(runInfo, report, pullRequest) { core.info("Generating summary."); + const { octokit, context: context2 } = runInfo; let summary = `## Pyright Summary **\u{1F4DD} Files Analyzed**: ${report.summary.filesAnalyzed} `; diff --git a/src/action.ts b/src/action.ts index e3d4c46..d1875a6 100644 --- a/src/action.ts +++ b/src/action.ts @@ -20,7 +20,6 @@ export async function run() { runInfo, pullRequestData, ); - core.info("pythonFiles: " + JSON.stringify(pythonFiles)); if (pythonFiles.length === 0) { core.info("No Python files have changed."); return; @@ -28,7 +27,10 @@ export async function run() { await installPyright(); const pyrightReport = await runPyright(pythonFiles); - await commentOnPR(runInfo, pyrightReport, pullRequestData); + + if (runInfo.options.includeFileComments) + await addFileComments(runInfo, pyrightReport, pullRequestData); + await addSummaryComment(runInfo, pyrightReport, pullRequestData); } catch (error) { core.setFailed(`Action failed with error: ${error}`); } @@ -38,7 +40,14 @@ const getRunInfo = () => { const token = core.getInput("github-token", { required: true }); const octokit = new Octokit({ auth: token }); const context = github.context; - return { token, octokit, context }; + const options = getOptions(); + return { token, octokit, context, options }; +}; + +const getOptions = () => { + const includeFileComments = + core.getBooleanInput("include-file-comments") ?? true; + return { includeFileComments }; }; async function getChangedPythonFiles( @@ -93,11 +102,13 @@ async function runPyright(files: string[]): Promise { return parseReport(JSON.parse(output)); } -async function commentOnPR( +async function addFileComments( runInfo: ReturnType, report: Report, pullRequest: Awaited>, ) { + core.info("Generating file comments."); + const { octokit, context } = runInfo; const diagnostics = report.generalDiagnostics; @@ -203,8 +214,17 @@ async function commentOnPR( comment_id: comment.id, }); } +} +async function addSummaryComment( + runInfo: ReturnType, + report: Report, + pullRequest: Awaited>, +) { core.info("Generating summary."); + + const { octokit, context } = runInfo; + let summary = `## Pyright Summary \n` + `**📝 Files Analyzed**: ${report.summary.filesAnalyzed}\n`; diff --git a/src/helpers.ts b/src/helpers.ts index 8273184..dc5dbf8 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -75,16 +75,3 @@ export const parseSummaryCommentKey = (input: string) => { const match = regex.exec(input); return match ? match[1] : null; }; - -// const exampleCommentBody = `### Pyright Issues -// -// - main.py:10:14 - ❌ error: Expression of type \`int\` cannot be assigned to declared type \`str\` -// \`int\` is incompatible with \`str\` (reportAssignmentType) -// - main.py:11:24 - ❌ error: Expression of type \`int\` cannot be assigned to declared type \`str\` -// \`int\` is incompatible with \`str\` (reportAssignmentType) -// -// -// ###### [diagnostic-key:89be8cb1cee8ef6a]`; -// -// const commentKey = parseCommentKey(exampleCommentBody); -// console.log({ commentKey });