Skip to content

Commit

Permalink
fix: Calculate check conclusion from annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
carmanchris31 committed Apr 28, 2022
1 parent f3bbd7f commit 14435d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### :sparkles: Release Note <!-- optional -->

### :rocket: Enhancements
- [#1170](https://github.com/reviewdog/reviewdog/pull/1170) Calculate check conclusion from annotations
- ...

### :bug: Fixes
Expand Down
36 changes: 30 additions & 6 deletions doghouse/server/doghouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ func (ch *Checker) postCheck(ctx context.Context, checkID int64, checks []*filte
}
}

conclusion := "success"
if len(annotations) > 0 {
conclusion = ch.conclusion()
}
conclusion := ch.conclusion(annotations)
opt := github.UpdateCheckRunOptions{
Name: ch.checkName(),
Status: github.String("completed"),
Expand Down Expand Up @@ -160,8 +157,35 @@ func (ch *Checker) checkTitle() string {
}

// https://developer.github.com/v3/checks/runs/#parameters-1
func (ch *Checker) conclusion() string {
switch strings.ToLower(ch.req.Level) {
func (ch *Checker) conclusion(annotations []*github.CheckRunAnnotation) string {
checkResult := "success"

if ch.req.Level != "" {
// Level takes precedence when configured (for backwards compatibility)
if len(annotations) > 0 {
checkResult = strings.ToLower(ch.req.Level)
}
} else {
levelSeverity := map[string]int{
"success": 0,
"notice": 1,
"warning": 2,
"failure": 3,
}

highestLevel := "success"
for _, a := range annotations {
annotationLevel := *a.AnnotationLevel
if levelSeverity[annotationLevel] > levelSeverity[highestLevel] {
highestLevel = annotationLevel
}
}
checkResult = highestLevel
}

switch checkResult {
case "success":
return "success"
case "info", "warning":
return "neutral"
}
Expand Down

0 comments on commit 14435d7

Please sign in to comment.