Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert hlint warnings to github Action “smart” log messages
# the github message format requires newlines to be escaped with the URL-style %0A
# see https://github.com/actions/toolkit/issues/193#issuecomment-605394935
def escapeNewline: gsub("[\\n]"; "%0A");
# depending on the hlint message, we want to display the
# headings and the bodies differently
def prepareTitle:
if .hint == "Unused LANGUAGE pragma"
then { heading: "Unused LANGUAGE pragma: \(.from)"
, suggestion: ""
}
else if .hint == "Avoid restricted function"
then { heading: "Don’t use function: \(.from)"
, suggestion: "" }
else if .hint == "Avoid restricted qualification"
then { heading: "Change import to: \(.to)"
, suggestion: .to }
# if there is a `to` field, we can add it as suggestion
else if (.to != "") and (.to != null)
then { heading: .hint
, suggestion: .to }
else { heading: .hint
, suggestion: ""
}
end end end end;
def formatTitle:
. as $dot
| prepareTitle
| "\(.heading)::"
+ if .suggestion != "" then .suggestion else "" end
# if there is any notes, display them after the body message.
+ if ($dot.note | length) == 0
then ""
else if ($dot.note | length) == 1
then "
Note: \($dot.note | join(" "))"
else "
Notes:
\($dot.note | map("* \(.)") | join("\n"))"
end end
| escapeNewline;
# hlint generates a json array of messages
map(
"::warning file=\(.file),line=\(.startLine),col=\(.startColumn),endLine=\(.endLine),endColumn=\(.endColumn),title=\(.|formatTitle)"
)
# split into lines of text
| .[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment