Skip to content

Commit

Permalink
Merge pull request #1805 from massongit/refactor_github_comment_line_…
Browse files Browse the repository at this point in the history
…range

githubCommentLineRange: a same process is written only once
  • Loading branch information
haya14busa authored Jun 30, 2024
2 parents ef233bf + 4da1024 commit f31b773
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions service/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,19 @@ func githubCommentLine(c *reviewdog.Comment) int {
}

func githubCommentLineRange(c *reviewdog.Comment) (start int, end int) {
var rdfRange *rdf.Range

// Prefer first suggestion line range to diagnostic location if available so
// that reviewdog can post code suggestion as well when the line ranges are
// different between the diagnostic location and its suggestion.
if c.Result.FirstSuggestionInDiffContext && len(c.Result.Diagnostic.GetSuggestions()) > 0 {
s := c.Result.Diagnostic.GetSuggestions()[0]
startLine := s.GetRange().GetStart().GetLine()
endLine := s.GetRange().GetEnd().GetLine()
if endLine == 0 {
endLine = startLine
}
return int(startLine), int(endLine)
rdfRange = c.Result.Diagnostic.GetSuggestions()[0].GetRange()
} else {
rdfRange = c.Result.Diagnostic.GetLocation().GetRange()
}
loc := c.Result.Diagnostic.GetLocation()
startLine := loc.GetRange().GetStart().GetLine()
endLine := loc.GetRange().GetEnd().GetLine()

startLine := rdfRange.GetStart().GetLine()
endLine := rdfRange.GetEnd().GetLine()
if endLine == 0 {
endLine = startLine
}
Expand Down

0 comments on commit f31b773

Please sign in to comment.