Skip to content

Commit

Permalink
feat: add emoji support for annotation severity ⚠️
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 22, 2024
1 parent dfbb3ba commit 72a02dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* of annotations into different formats for integration with CI/CD tools.
*/

import { EMOJI_SUCCESS, EMOJI_WARNING } from "./constants"

// Regular expression for matching GitHub Actions annotations.
// Example: ::error file=foo.js,line=10,endLine=11::Something went wrong.
const GITHUB_ANNOTATIONS_RX =
Expand All @@ -18,13 +20,20 @@ const AZURE_DEVOPS_ANNOTATIONS_RX =
// Example: foo.ts:10:error TS1005: ';' expected.
const TYPESCRIPT_ANNOTATIONS_RX =
/^(?<file>[^:\s].*?):(?<line>\d+)(?::(?<endLine>\d+))?(?::\d+)?\s+-\s+(?<severity>error|warning)\s+(?<code>[^:]+)\s*:\s*(?<message>.*)$/gim

// Maps severity strings to `DiagnosticSeverity`.
const SEV_MAP: Record<string, DiagnosticSeverity> = Object.freeze({
["info"]: "info",
["notice"]: "info", // Maps 'notice' to 'info' severity
["warning"]: "warning",
["error"]: "error",
})
const SEV_EMOJI_MAP: Record<string, string> = Object.freeze({
["info"]: "ℹ️",
["notice"]: "ℹ️", // Maps 'notice' to 'info' severity
["warning"]: EMOJI_WARNING,
["error"]: EMOJI_SUCCESS,
})

/**
* Parses annotations from TypeScript, GitHub Actions, and Azure DevOps.
Expand Down Expand Up @@ -82,7 +91,7 @@ export function convertAnnotationsToItems(text: string) {
const m = rx.exec(s)
if (!m) return s
const { file, line, severity, code, message } = m.groups
return `- ${SEV_MAP[severity?.toLowerCase()] ?? "info"}: ${message} (${file}#L${line} ${code || ""})`
return `- ${SEV_EMOJI_MAP[severity?.toLowerCase()] ?? "info"}: ${message} ([${file}#L${line}](${file}) ${code || ""})\n`
}),
text
)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export const STATS_DIR_NAME = "stats"

export const EMOJI_SUCCESS = "✅"
export const EMOJI_FAIL = "❌"
export const EMOJI_WARNING = "⚠️"
export const EMOJI_UNDEFINED = "?"

export const MODEL_PROVIDER_OPENAI = "openai"
Expand Down

0 comments on commit 72a02dd

Please sign in to comment.