github.com/mattbailey/reviewdog@v0.10.0/service/github/githubutils/utils.go (about) 1 package githubutils 2 3 import ( 4 "fmt" 5 6 "github.com/reviewdog/reviewdog" 7 ) 8 9 // LinkedMarkdownCheckResult returns Markdown string which contains a link to the 10 // location in the CheckResult and CheckResult content itself. 11 func LinkedMarkdownCheckResult(owner, repo, sha string, c *reviewdog.CheckResult) string { 12 if c.Path == "" { 13 return c.Message 14 } 15 loc := BasicLocationFormat(c) 16 link := PathLink(owner, repo, sha, c.Path, c.Lnum) 17 return fmt.Sprintf("[%s](%s) %s", loc, link, c.Message) 18 } 19 20 // PathLink build a link to GitHub path to given sha, file, and line. 21 func PathLink(owner, repo, sha, path string, line int) string { 22 if sha == "" { 23 sha = "master" 24 } 25 fragment := "" 26 if line > 0 { 27 fragment = fmt.Sprintf("#L%d", line) 28 } 29 return fmt.Sprintf("http://github.com/%s/%s/blob/%s/%s%s", 30 owner, repo, sha, path, fragment) 31 } 32 33 // BasicLocationFormat format check CheckResult to %f|%l col %c| errorformat. 34 func BasicLocationFormat(c *reviewdog.CheckResult) string { 35 loc := c.Path + "|" 36 if c.Lnum != 0 { 37 loc = fmt.Sprintf("%s%d", loc, c.Lnum) 38 if c.Col != 0 { 39 loc = fmt.Sprintf("%s col %d", loc, c.Col) 40 } 41 } 42 return loc + "|" 43 }