Skip to content

Commit

Permalink
update build
Browse files Browse the repository at this point in the history
  • Loading branch information
YajJackson committed Mar 20, 2024
1 parent bc3c967 commit b621e40
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 52 deletions.
50 changes: 30 additions & 20 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30106,7 +30106,8 @@ var Report = object({
summary: object({
errorCount: number(),
warningCount: number(),
informationCount: number()
informationCount: number(),
filesAnalyzed: number()
})
});
function parseReport(v) {
Expand All @@ -30116,19 +30117,24 @@ function parseReport(v) {
// src/helpers.ts
var isEmptyPosition = (p) => p.line === 0 && p.character === 0;
var isEmptyRange = (r) => isEmptyPosition(r.start) && isEmptyPosition(r.end);
var diagnosticToString = (diag) => {
let message = "";
if (diag.file) {
message += `${diag.file}:`;
var getSeverityIcon = (severity) => {
switch (severity) {
case "error":
return "\u274C";
case "warning":
return "\u26A0\uFE0F";
default:
return "";
}
if (diag.range && !isEmptyRange(diag.range)) {
};
var diagnosticToString = (diag, fileName) => {
let message = `${fileName}:`;
if (diag.range && !isEmptyRange(diag.range))
message += `${diag.range.start.line + 1}:${diag.range.start.character + 1} -`;
}
message += ` ${diag.severity}: `;
message += diag.message;
if (diag.rule) {
message += ` ${getSeverityIcon(diag.severity)} ${diag.severity}: `;
message += diag.message.replace(/"/g, "`");
if (diag.rule)
message += ` (${diag.rule})`;
}
return message;
};
var getRelativePath = (file, repoName) => {
Expand Down Expand Up @@ -31470,9 +31476,8 @@ async function getPullRequestData(runInfo) {
repo: context2.repo.repo,
pull_number: context2.issue.number
};
core.info("requestParams: " + JSON.stringify(requestParams));
const { data: pullRequestData } = await octokit.rest.pulls.get(requestParams);
return pullRequestData;
const { data } = await octokit.rest.pulls.get(requestParams);
return data;
}
async function installPyright() {
await (0, import_exec.exec)("npm", ["install", "-g", "pyright"]);
Expand All @@ -31488,9 +31493,7 @@ async function runPyright(files) {
},
ignoreReturnCode: true
};
core.info("Running: " + pyrightCommand);
await (0, import_exec.exec)(pyrightCommand, [], options);
core.info("Pyright output: " + output);
return parseReport(JSON.parse(output));
}
async function commentOnPR(runInfo, report, pullRequest) {
Expand Down Expand Up @@ -31520,7 +31523,7 @@ async function commentOnPR(runInfo, report, pullRequest) {

`;
for (const diagnostic of fileDiagnostics) {
body += diagnosticToString(diagnostic) + "\n";
body += "- " + diagnosticToString(diagnostic, relativePath) + "\n";
}
await octokit.rest.pulls.createReviewComment({
owner: context2.repo.owner,
Expand All @@ -31534,9 +31537,16 @@ async function commentOnPR(runInfo, report, pullRequest) {
});
}
core.info("Creating summary comment.");
const summary = `## Pyright Summary
**\u274C Errors**: ${report.summary.errorCount}
**\u26A0\uFE0F Warnings**: ${report.summary.warningCount}`;
let summary = `## Pyright Summary
**\u{1F4DD} Files Analyzed**: ${report.summary.filesAnalyzed}
`;
if (report.summary.errorCount > 0)
summary += `**\u274C Errors**: ${report.summary.errorCount}
`;
if (report.summary.warningCount > 0)
summary += `**\u26A0\uFE0F Warnings**: ${report.summary.warningCount}`;
if (report.summary.errorCount === 0 && report.summary.warningCount === 0)
summary += `\u2705 No errors or warnings found.`;
await octokit.rest.issues.createComment({
owner: context2.repo.owner,
repo: context2.repo.repo,
Expand Down
24 changes: 12 additions & 12 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ async function getPullRequestData(runInfo: ReturnType<typeof getRunInfo>) {
repo: context.repo.repo,
pull_number: context.issue.number,
};
core.info("requestParams: " + JSON.stringify(requestParams));

const { data: pullRequestData } =
await octokit.rest.pulls.get(requestParams);
return pullRequestData;
const { data } = await octokit.rest.pulls.get(requestParams);
return data;
}

async function installPyright() {
Expand All @@ -85,9 +82,7 @@ async function runPyright(files: string[]): Promise<Report> {
ignoreReturnCode: true,
};

core.info("Running: " + pyrightCommand);
await exec(pyrightCommand, [], options);
core.info("Pyright output: " + output);
return parseReport(JSON.parse(output));
}

Expand Down Expand Up @@ -128,7 +123,7 @@ async function commentOnPR(
let body = `### Pyright Issues\n\n`;

for (const diagnostic of fileDiagnostics) {
body += diagnosticToString(diagnostic) + "\n";
body += "- " + diagnosticToString(diagnostic, relativePath) + "\n";
}

await octokit.rest.pulls.createReviewComment({
Expand All @@ -143,12 +138,17 @@ async function commentOnPR(
});
}

// Create a comment on the PR with a summary of the issues
core.info("Creating summary comment.");
const summary =
let summary =
`## Pyright Summary \n` +
`**❌ Errors**: ${report.summary.errorCount}\n` +
`**⚠️ Warnings**: ${report.summary.warningCount}`;
`**📝 Files Analyzed**: ${report.summary.filesAnalyzed}\n`;

if (report.summary.errorCount > 0)
summary += `**❌ Errors**: ${report.summary.errorCount}\n`;
if (report.summary.warningCount > 0)
summary += `**⚠️ Warnings**: ${report.summary.warningCount}`;
if (report.summary.errorCount === 0 && report.summary.warningCount === 0)
summary += `✅ No errors or warnings found.`;

await octokit.rest.issues.createComment({
owner: context.repo.owner,
Expand Down
33 changes: 21 additions & 12 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ const isEmptyPosition = (p: Position) => p.line === 0 && p.character === 0;
const isEmptyRange = (r: Range) =>
isEmptyPosition(r.start) && isEmptyPosition(r.end);

export const diagnosticToString = (diag: Diagnostic): string => {
let message = "";

if (diag.file) {
message += `${diag.file}:`;
const getSeverityIcon = (severity: string) => {
switch (severity) {
case "error":
return "❌";
case "warning":
return "⚠️";
default:
return "";
}
if (diag.range && !isEmptyRange(diag.range)) {
};

export const diagnosticToString = (
diag: Diagnostic,
fileName: string,
): string => {
let message = `${fileName}:`;

if (diag.range && !isEmptyRange(diag.range))
message += `${diag.range.start.line + 1}:${
diag.range.start.character + 1
} -`;
}
message += ` ${diag.severity}: `;

message += diag.message;
message += ` ${getSeverityIcon(diag.severity)} ${diag.severity}: `;

if (diag.rule) {
message += ` (${diag.rule})`;
}
message += diag.message.replace(/"/g, "`");

if (diag.rule) message += ` (${diag.rule})`;

return message;
};
Expand Down
9 changes: 1 addition & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ const Position = v.object({
character: v.number(),
});

function isEmptyPosition(p: Position) {
return p.line === 0 && p.character === 0;
}

export type Range = v.Infer<typeof Range>;
const Range = v.object({
start: Position,
end: Position,
});

export function isEmptyRange(r: Range) {
return isEmptyPosition(r.start) && isEmptyPosition(r.end);
}

export type Diagnostic = v.Infer<typeof Diagnostic>;
const Diagnostic = v.object({
file: v.string(),
Expand All @@ -40,6 +32,7 @@ const Report = v.object({
errorCount: v.number(),
warningCount: v.number(),
informationCount: v.number(),
filesAnalyzed: v.number(),
}),
});

Expand Down

0 comments on commit b621e40

Please sign in to comment.