diff --git a/src/checks/branch-checks.ts b/src/checks/branch-checks.ts index ab9b150..c66e253 100644 --- a/src/checks/branch-checks.ts +++ b/src/checks/branch-checks.ts @@ -14,7 +14,7 @@ export function runBranchChecks(settings: Settings, context: Context): CheckResu recordCheck(results, { name: "target-branch", passed: false, - message: `Target branch "${branch}" is not in the allowed list`, + message: `Target branch "${branch}" is not allowed`, }); } else if (settings.blockedTargetBranches.some((pattern) => matchBranch(branch, pattern))) { recordCheck(results, { @@ -26,7 +26,7 @@ export function runBranchChecks(settings: Settings, context: Context): CheckResu recordCheck(results, { name: "target-branch", passed: true, - message: "Target branch is allowed", + message: `Target branch "${branch}" is allowed`, }); } } @@ -41,7 +41,7 @@ export function runBranchChecks(settings: Settings, context: Context): CheckResu recordCheck(results, { name: "source-branch", passed: false, - message: `Source branch "${branch}" is not in the allowed list`, + message: `Source branch "${branch}" is not allowed`, }); } else if (settings.blockedSourceBranches.some((pattern) => matchBranch(branch, pattern))) { recordCheck(results, { @@ -53,7 +53,7 @@ export function runBranchChecks(settings: Settings, context: Context): CheckResu recordCheck(results, { name: "source-branch", passed: true, - message: "Source branch is allowed", + message: `Source branch "${branch}" is allowed`, }); } } diff --git a/src/checks/commit-checks.ts b/src/checks/commit-checks.ts index 8d8b713..9dd913b 100644 --- a/src/checks/commit-checks.ts +++ b/src/checks/commit-checks.ts @@ -94,7 +94,7 @@ export async function runCommitChecks( passed: blocked.size === 0, message: blocked.size > 0 - ? `Blocked commit author(s) found: ${[...blocked].join(", ")}` + ? `Found ${String(blocked.size)} blocked commit author(s): "${[...blocked].join('", "')}"` : "No blocked commit authors found", }); } diff --git a/src/checks/description-checks.ts b/src/checks/description-checks.ts index c4d75b0..c23e40e 100644 --- a/src/checks/description-checks.ts +++ b/src/checks/description-checks.ts @@ -35,21 +35,23 @@ export async function runDescriptionChecks( if (settings.requireDescription) { const empty = body.replace(/\s/g, "").length === 0; + const passed = !empty; recordCheck(results, { name: "description-empty", - passed: !empty, - message: empty ? "PR description is empty" : "PR description is present", + passed, + message: passed ? "PR description is present" : "PR description is empty", }); } if (settings.maxDescriptionLength > 0) { const over = body.length > settings.maxDescriptionLength; + const passed = !over; recordCheck(results, { name: "description-max-length", - passed: !over, - message: over - ? `Description is ${String(body.length)} chars, exceeds allowed maximum of ${String(settings.maxDescriptionLength)}` - : `Description is ${String(body.length)} chars, within allowed maximum of ${String(settings.maxDescriptionLength)}`, + passed, + message: passed + ? `Description is ${String(body.length)} chars, within maximum of ${String(settings.maxDescriptionLength)}` + : `Description is ${String(body.length)} chars, exceeds maximum of ${String(settings.maxDescriptionLength)}`, }); } @@ -61,47 +63,47 @@ export async function runDescriptionChecks( name: "emoji-count", passed, message: passed - ? `Found ${String(count)} emoji(s), within allowed maximum of ${String(settings.maxEmojiCount)}` - : `Found ${String(count)} emoji(s), exceeds allowed maximum of ${String(settings.maxEmojiCount)}`, + ? `Found ${String(count)} emoji(s), within maximum of ${String(settings.maxEmojiCount)}` + : `Found ${String(count)} emoji(s), exceeds maximum of ${String(settings.maxEmojiCount)}`, }); } if (settings.blockedTerms.length > 0) { const visibleBody = body.replace(//g, ""); const found = settings.blockedTerms.filter((term) => visibleBody.includes(term)); + const passed = found.length === 0; recordCheck(results, { name: "blocked-terms", - passed: found.length === 0, - message: - found.length > 0 - ? `Blocked term(s) found: ${found.join(", ")}` - : "No blocked terms found", + passed, + message: passed + ? "No blocked terms found in the description" + : `Found ${String(found.length)} blocked term(s) in the description: "${found.join('", "')}"`, }); } const issueNumbers = extractIssueNumbers(body); if (settings.requireLinkedIssue) { + const passed = issueNumbers.length > 0; recordCheck(results, { name: "linked-issue", - passed: issueNumbers.length > 0, - message: - issueNumbers.length > 0 - ? `Found ${String(issueNumbers.length)} linked issue(s) in the PR description` - : "No linked issues found in the PR description", + passed, + message: passed + ? `Found ${String(issueNumbers.length)} linked issue(s) in the PR description` + : "No linked issues found in the PR description", }); } if (settings.blockedIssueNumbers.length > 0) { const blockedNumbers = settings.blockedIssueNumbers.map((raw) => parseInt(raw)); const found = issueNumbers.filter((issueNumber) => blockedNumbers.includes(issueNumber)); + const passed = found.length === 0; recordCheck(results, { name: "blocked-issue-numbers", - passed: found.length === 0, - message: - found.length > 0 - ? `Found blocked issue number(s) in the PR description: ${found.map((issueNumber) => `#${String(issueNumber)}`).join(", ")}` - : "No blocked issue numbers found in the PR description", + passed, + message: passed + ? "No blocked issue numbers found in the description" + : `Found ${String(found.length)} blocked issue number(s) in the description: "${found.join(", ")}"`, }); } @@ -117,23 +119,24 @@ export async function runDescriptionChecks( if (!templateHeadings || templateHeadings.length === 0) { const identical = body.trim() === template.trim(); + const passed = !identical; recordCheck(results, { name: "pr-template", - passed: !identical, - message: identical - ? "PR description is identical to the template (not filled in)" - : "PR description follows the repository PR template structure", + passed, + message: passed + ? "PR description follows the repository PR template structure" + : "PR description is identical to the template (not filled in)", }); } else { const missing = templateHeadings.filter((heading) => !body.includes(heading)); core.debug(`Missing template headings: ${missing.join(", ")}`); + const passed = missing.length === 0; recordCheck(results, { name: "pr-template", - passed: missing.length === 0, - message: - missing.length > 0 - ? `PR description is missing repository PR template section(s)` - : "PR description follows the repository PR template structure", + passed, + message: passed + ? "PR description follows the repository PR template structure" + : `PR description is missing ${String(missing.length)} repository PR template section(s)`, }); } } diff --git a/src/checks/file-checks.ts b/src/checks/file-checks.ts index a511223..7ea20f4 100644 --- a/src/checks/file-checks.ts +++ b/src/checks/file-checks.ts @@ -1,3 +1,4 @@ +import * as core from "@actions/core"; import type { CheckResult, Context, Settings, Octokit } from "../types"; import { recordCheck } from "../report.ts"; @@ -32,45 +33,47 @@ export async function runFileChecks( const allowed = settings.allowedFileExtensions.map((extension) => extension.startsWith(".") ? extension.toLowerCase() : `.${extension.toLowerCase()}`, ); - const passed = files.every((file) => { + const disallowed = files.filter((file) => { const filename = file.name.split("/").pop() ?? file.name; const dot = filename.lastIndexOf("."); - return ( - dot <= 0 || // dotfiles (.gitignore) and extensionless files (Makefile) are exempt from this check - allowed.includes(filename.slice(dot).toLowerCase()) + dot > 0 && // dotfiles (.gitignore) and extensionless files (Makefile) are exempt from this check + !allowed.includes(filename.slice(dot).toLowerCase()) ); }); + const passed = disallowed.length === 0; recordCheck(results, { name: "file-extensions", passed, message: passed - ? "All file extensions are permitted" - : "Found file(s) with disallowed extension(s)", + ? "All changed files have allowed extensions" + : `Found ${String(disallowed.length)} file(s) with disallowed extensions: "${disallowed.map((file) => file.name).join('", "')}"`, }); } if (settings.allowedPaths.length > 0) { - const passed = files.every((file) => - settings.allowedPaths.some((pattern) => - pattern.endsWith("/") - ? file.name.toLowerCase().startsWith(pattern.toLowerCase()) - : file.name.toLowerCase() === pattern.toLowerCase(), - ), + const disallowed = files.filter( + (file) => + !settings.allowedPaths.some((pattern) => + pattern.endsWith("/") + ? file.name.toLowerCase().startsWith(pattern.toLowerCase()) + : file.name.toLowerCase() === pattern.toLowerCase(), + ), ); + const passed = disallowed.length === 0; recordCheck(results, { name: "allowed-paths", passed, message: passed ? "All changed files are in allowed paths" - : "Found changed file(s) outside allowed paths", + : `Found ${String(disallowed.length)} file(s) outside allowed paths: "${disallowed.map((file) => file.name).join('", "')}"`, }); } if (settings.blockedPaths.length > 0) { - const passed = !files.some((file) => + const blocked = files.filter((file) => settings.blockedPaths.some((pattern) => pattern.endsWith("/") ? file.name.toLowerCase().startsWith(pattern.toLowerCase()) @@ -78,49 +81,50 @@ export async function runFileChecks( ), ); + const passed = blocked.length === 0; recordCheck(results, { name: "blocked-paths", passed, message: passed - ? "No changes in blocked paths" - : "Found changed file(s) in blocked paths", + ? "No changed files found in blocked paths" + : `Found ${String(blocked.length)} file(s) in blocked paths: "${blocked.map((file) => file.name).join('", "')}"`, }); } if (settings.requireFinalNewline) { - const passed = ( - await Promise.all( - files - .filter((file) => file.status !== "removed") - .slice(0, 30) - .map(async (file) => { - try { - const { data } = await client.rest.repos.getContent({ - owner: context.owner, - repo: context.repo, - path: file.name, - ref: context.headBranch, - }); - if ("content" in data && typeof data.content === "string") { - const content = Buffer.from(data.content, "base64").toString( - "utf-8", - ); - return content.length === 0 || content.endsWith("\n"); - } - return true; - } catch { - return true; - } - }), - ) - ).every(Boolean); + const missing: string[] = []; + await Promise.all( + files + .filter((file) => file.status !== "removed") + .slice(0, 30) + .map(async (file) => { + try { + const { data } = await client.rest.repos.getContent({ + owner: context.owner, + repo: context.repo, + path: file.name, + ref: context.headBranch, + }); + if ("content" in data && typeof data.content === "string") { + const content = Buffer.from(data.content, "base64").toString("utf-8"); + if (content.length > 0 && !content.endsWith("\n")) { + missing.push(file.name); + } + } + } catch { + core.warning(`Error checking final newline for file ${file.name}`); + } + }), + ); + + const passed = missing.length === 0; recordCheck(results, { name: "final-newline", passed, message: passed ? "All changed files end with a newline" - : "Found file(s) missing a final newline", + : `Found ${String(missing.length)} file(s) missing a final newline: "${missing.join('", "')}"`, }); } diff --git a/src/checks/quality-checks.ts b/src/checks/quality-checks.ts index a82a4a7..02cff53 100644 --- a/src/checks/quality-checks.ts +++ b/src/checks/quality-checks.ts @@ -14,8 +14,8 @@ export async function runQualityChecks( name: "require-maintainer-can-modify", passed, message: passed - ? "PR allows maintainers to push to the source (head) branch" - : "PR does not allow maintainers to push to the source (head) branch", + ? "PR allows maintainers to push to the source branch" + : "PR does not allow maintainers to push to the source branch", }); } @@ -33,8 +33,8 @@ export async function runQualityChecks( name: "max-negative-reactions", passed, message: passed - ? `PR has ${String(negativeCount)} negative reaction(s), within allowed maximum of ${String(settings.maxNegativeReactions)}` - : `PR has ${String(negativeCount)} negative reaction(s), exceeds allowed maximum of ${String(settings.maxNegativeReactions)}`, + ? `PR has ${String(negativeCount)} negative reaction(s), within maximum of ${String(settings.maxNegativeReactions)}` + : `PR has ${String(negativeCount)} negative reaction(s), exceeds maximum of ${String(settings.maxNegativeReactions)}`, }); } diff --git a/src/checks/title-checks.ts b/src/checks/title-checks.ts index d82ba5a..3d22bc7 100644 --- a/src/checks/title-checks.ts +++ b/src/checks/title-checks.ts @@ -16,8 +16,8 @@ export function runTitleChecks(settings: Settings, context: Context): CheckResul name: "conventional-title", passed, message: passed - ? `PR title follows conventional commits format with type "${type}"` - : `PR title does not follow conventional commits format: "${context.title}"`, + ? `PR title "${context.title}" follows conventional commits format` + : `PR title "${context.title}" does not follow conventional commits format`, }); } diff --git a/src/checks/user-checks.ts b/src/checks/user-checks.ts index e89c53d..4bca8e1 100644 --- a/src/checks/user-checks.ts +++ b/src/checks/user-checks.ts @@ -66,7 +66,9 @@ export async function runUserChecks( recordCheck(results, { name: "repo-merge-ratio", passed, - message: `Repo merge ratio is ${String(mergedPercent)}% (${String(repoMerged)}/${String(total)}), minimum is ${String(settings.minRepoMergeRatio)}%`, + message: passed + ? `Repo merge ratio is ${String(mergedPercent)}% (${String(repoMerged)}/${String(total)}), meets minimum of ${String(settings.minRepoMergeRatio)}%` + : `Repo merge ratio is ${String(mergedPercent)}% (${String(repoMerged)}/${String(total)}), below minimum of ${String(settings.minRepoMergeRatio)}%`, }); } } @@ -87,7 +89,9 @@ export async function runUserChecks( recordCheck(results, { name: "global-merge-ratio", passed, - message: `Global merge ratio${scope} is ${String(mergedPercent)}% (${String(globalMerged)}/${String(total)}), minimum is ${String(settings.minGlobalMergeRatio)}%`, + message: passed + ? `Global merge ratio${scope} is ${String(mergedPercent)}% (${String(globalMerged)}/${String(total)}), meets minimum of ${String(settings.minGlobalMergeRatio)}%` + : `Global merge ratio${scope} is ${String(mergedPercent)}% (${String(globalMerged)}/${String(total)}), below minimum of ${String(settings.minGlobalMergeRatio)}%`, }); } }