mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #242 from baustinanki/github-issue-status
Add optional PR status display in Github module
This commit is contained in:
commit
46f42672e0
@ -3,6 +3,7 @@ package github
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/go-github/github"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s
|
|||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
str = str + fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title)
|
str = str + fmt.Sprintf(" %s[green]%4d[white] %s\n", mergeString(pr), *pr.Number, *pr.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
@ -72,3 +73,24 @@ func (widget *Widget) displayStats(repo *GithubRepo) string {
|
|||||||
func (widget *Widget) title(repo *GithubRepo) string {
|
func (widget *Widget) title(repo *GithubRepo) string {
|
||||||
return fmt.Sprintf("[green]%s - %s[white]", repo.Owner, repo.Name)
|
return fmt.Sprintf("[green]%s - %s[white]", repo.Owner, repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showStatus() bool {
|
||||||
|
return wtf.Config.UBool("wtf.mods.github.enableStatus", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
var mergeIcons = map[string]string{
|
||||||
|
"dirty": "[red]![white] ",
|
||||||
|
"clean": "[green]✔[white] ",
|
||||||
|
"unstable": "[red]✖[white] ",
|
||||||
|
"blocked": "[red]✖[white] ",
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeString(pr *github.PullRequest) string {
|
||||||
|
if !showStatus() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if str, ok := mergeIcons[pr.GetMergeableState()]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return "? "
|
||||||
|
}
|
||||||
|
@ -103,9 +103,35 @@ func (repo *GithubRepo) myPullRequests(username string) []*ghb.PullRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if showStatus() {
|
||||||
|
prs = repo.individualPRs(prs)
|
||||||
|
}
|
||||||
|
|
||||||
return prs
|
return prs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// individualPRs takes a list of pull requests (presumably returned from
|
||||||
|
// github.PullRequests.List) and fetches them individually to get more detailed
|
||||||
|
// status info on each. see: https://developer.github.com/v3/git/#checking-mergeability-of-pull-requests
|
||||||
|
func (repo *GithubRepo) individualPRs(prs []*ghb.PullRequest) []*ghb.PullRequest {
|
||||||
|
github, err := repo.githubClient()
|
||||||
|
if err != nil {
|
||||||
|
return prs
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret []*ghb.PullRequest
|
||||||
|
for i := range prs {
|
||||||
|
pr, _, err := github.PullRequests.Get(context.Background(), repo.Owner, repo.Name, prs[i].GetNumber())
|
||||||
|
if err != nil {
|
||||||
|
// worst case, just keep the original one
|
||||||
|
ret = append(ret, prs[i])
|
||||||
|
} else {
|
||||||
|
ret = append(ret, pr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// myReviewRequests returns a list of pull requests for which username has been
|
// myReviewRequests returns a list of pull requests for which username has been
|
||||||
// requested to do a code review
|
// requested to do a code review
|
||||||
func (repo *GithubRepo) myReviewRequests(username string) []*ghb.PullRequest {
|
func (repo *GithubRepo) myReviewRequests(username string) []*ghb.PullRequest {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user