Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from reviewdog/remainig-as-summary
github-pr-review: use review summary comments for too many annotations
- Loading branch information
Showing
5 changed files
with
210 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package githubutils | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/reviewdog/reviewdog" | ||
) | ||
|
||
// LinkedMarkdownCheckResult returns Markdown string which contains a link to the | ||
// location in the CheckResult and CheckResult content itself. | ||
func LinkedMarkdownCheckResult(owner, repo, sha string, c *reviewdog.CheckResult) string { | ||
if c.Path == "" { | ||
return c.Message | ||
} | ||
loc := BasicLocationFormat(c) | ||
link := PathLink(owner, repo, sha, c.Path, c.Lnum) | ||
return fmt.Sprintf("[%s](%s) %s", loc, link, c.Message) | ||
} | ||
|
||
// PathLink build a link to GitHub path to given sha, file, and line. | ||
func PathLink(owner, repo, sha, path string, line int) string { | ||
if sha == "" { | ||
sha = "master" | ||
} | ||
fragment := "" | ||
if line > 0 { | ||
fragment = fmt.Sprintf("#L%d", line) | ||
} | ||
return fmt.Sprintf("http://github.com/%s/%s/blob/%s/%s%s", | ||
owner, repo, sha, path, fragment) | ||
} | ||
|
||
// BasicLocationFormat format chec CheckResult to %f|%l col %c| erorformat. | ||
func BasicLocationFormat(c *reviewdog.CheckResult) string { | ||
loc := c.Path + "|" | ||
if c.Lnum != 0 { | ||
loc = fmt.Sprintf("%s%d", loc, c.Lnum) | ||
if c.Col != 0 { | ||
loc = fmt.Sprintf("%s col %d", loc, c.Col) | ||
} | ||
} | ||
return loc + "|" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package githubutils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/reviewdog/reviewdog" | ||
) | ||
|
||
func TestLinkedMarkdownCheckResult(t *testing.T) { | ||
tests := []struct { | ||
owner, repo, sha string | ||
c *reviewdog.CheckResult | ||
want string | ||
}{ | ||
{ | ||
owner: "o", | ||
repo: "r", | ||
sha: "s", | ||
c: &reviewdog.CheckResult{ | ||
Path: "path/to/file.txt", | ||
Lnum: 1414, | ||
Col: 14, | ||
Message: "msg", | ||
}, | ||
want: "[path/to/file.txt|1414 col 14|](http://github.com/o/r/blob/s/path/to/file.txt#L1414) msg", | ||
}, | ||
{ | ||
owner: "o", | ||
repo: "r", | ||
sha: "s", | ||
c: &reviewdog.CheckResult{ | ||
Path: "path/to/file.txt", | ||
Lnum: 1414, | ||
Col: 0, | ||
Message: "msg", | ||
}, | ||
want: "[path/to/file.txt|1414|](http://github.com/o/r/blob/s/path/to/file.txt#L1414) msg", | ||
}, | ||
{ | ||
owner: "o", | ||
repo: "r", | ||
sha: "s", | ||
c: &reviewdog.CheckResult{ | ||
Path: "path/to/file.txt", | ||
Lnum: 0, | ||
Col: 0, | ||
Message: "msg", | ||
}, | ||
want: "[path/to/file.txt||](http://github.com/o/r/blob/s/path/to/file.txt) msg", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
if got := LinkedMarkdownCheckResult(tt.owner, tt.repo, tt.sha, tt.c); got != tt.want { | ||
t.Errorf("LinkedMarkdownCheckResult(%q, %q, %q, %#v) = %q, want %q", | ||
tt.owner, tt.repo, tt.sha, tt.c, got, tt.want) | ||
} | ||
} | ||
} |