-
-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce GitHub Alerts Style comment #1668
base: master
Are you sure you want to change the base?
Changes from 5 commits
3301afc
1246224
4949d2c
03fa944
3e52b04
67b1525
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,8 @@ | |
function f() | ||
{ | ||
} | ||
|
||
# Severity test | ||
test INFO | ||
Check notice on line 20 in _testdata/custom.txt GitHub Actions / custom-rdjson[custom-rdjson] _testdata/custom.txt#L20
Raw output
Check warning on line 20 in _testdata/custom.txt GitHub Actions / custom-rdjson[custom-rdjson] _testdata/custom.txt#L20
Raw output
Check warning on line 20 in _testdata/custom.txt GitHub Actions / custom-rdjson[custom-rdjson] _testdata/custom.txt#L20
Raw output
Check failure on line 20 in _testdata/custom.txt GitHub Actions / custom-rdjson[custom-rdjson] _testdata/custom.txt#L20
Raw output
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note [custom-rdjson] reported by [reviewdog](https://github.com/reviewdog/reviewdog) 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning [custom-rdjson] reported by [reviewdog](https://github.com/reviewdog/reviewdog) 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning [custom-rdjson] reported by [reviewdog](https://github.com/reviewdog/reviewdog) 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caution [custom-rdjson] reported by [reviewdog](https://github.com/reviewdog/reviewdog) 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note 📝 [custom-rdjson] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caution 🚫 [custom-rdjson] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caution 🚫 [custom-rdjson] reported by reviewdog 🐶 |
||
test WARNING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
test ERROR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package commentutil | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
@@ -96,3 +97,36 @@ func severity(c *reviewdog.Comment) string { | |
return "" | ||
} | ||
} | ||
|
||
// GitHubAlertComment creates a markdown comment using GitHub Alerts syntax. | ||
haya14busa marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning [golint-pr-review] comment on exported function GitHubAlertComemnt should be of the form "GitHubAlertComemnt ..." reported by reviewdog 🐶 |
||
// https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts | ||
func GitHubAlertComment(c *reviewdog.Comment) string { | ||
return "> " + githubAlert(c) + "\n" + toMarkdownQuote(MarkdownComment(c)) | ||
} | ||
|
||
func toMarkdownQuote(str string) string { | ||
var sb strings.Builder | ||
scanner := bufio.NewScanner(strings.NewReader(str)) | ||
for scanner.Scan() { | ||
sb.WriteString("> ") | ||
sb.Write(scanner.Bytes()) | ||
sb.WriteRune('\n') | ||
} | ||
return sb.String() | ||
} | ||
|
||
func githubAlert(c *reviewdog.Comment) string { | ||
// TODO: Maybe we should support TIP and IMPORTANT severity. | ||
switch c.Result.Diagnostic.GetSeverity() { | ||
case rdf.Severity_ERROR: | ||
return "[!CAUTION]" | ||
case rdf.Severity_WARNING: | ||
return "[!WARNING]" | ||
case rdf.Severity_INFO: | ||
return "[!NOTE]" | ||
default: | ||
// I'm not 100% sure what's the best default alert notation, but let's use | ||
// warning as default. | ||
return "[!WARNING]" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
[custom-rdjson]
severity test INFO
reported by reviewdog 🐶