1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch 'github-selection' of github.com:Midnight-Conqueror/wtf into Midnight-Conqueror-github-selection

This commit is contained in:
Chris Cummer
2019-09-05 05:23:59 -07:00
3 changed files with 102 additions and 11 deletions

View File

@@ -12,6 +12,19 @@ func (widget *Widget) display() {
func (widget *Widget) content() (string, string, bool) {
repo := widget.currentGithubRepo()
username := widget.settings.username
// Choses the correct place to scroll to when changing sources
if len(widget.View.GetHighlights()) > 0 {
widget.View.ScrollToHighlight()
} else {
widget.View.ScrollToBeginning()
}
// initial maxItems count
widget.Items = make([]int, 0)
widget.SetItemCount(len(repo.myReviewRequests((username))))
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo))
if repo == nil {
return title, " GitHub repo data is unavailable ", false
@@ -24,9 +37,9 @@ func (widget *Widget) content() (string, string, bool) {
str += " [red]Stats[white]\n"
str += widget.displayStats(repo)
str += "\n [red]Open Review Requests[white]\n"
str += widget.displayMyReviewRequests(repo, widget.settings.username)
str += widget.displayMyReviewRequests(repo, username)
str += "\n [red]My Pull Requests[white]\n"
str += widget.displayMyPullRequests(repo, widget.settings.username)
str += widget.displayMyPullRequests(repo, username)
for _, customQuery := range widget.settings.customQueries {
str += fmt.Sprintf("\n [red]%s[white]\n", customQuery.title)
str += widget.displayCustomQuery(repo, customQuery.filter, customQuery.perPage)
@@ -38,32 +51,50 @@ func (widget *Widget) content() (string, string, bool) {
func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {
prs := repo.myPullRequests(username, widget.settings.enableStatus)
if len(prs) == 0 {
prLength := len(prs)
if prLength == 0 {
return " [grey]none[white]\n"
}
maxItems := widget.GetItemCount()
str := ""
for _, pr := range prs {
str += fmt.Sprintf(" %s[green]%4d[white] %s\n", widget.mergeString(pr), *pr.Number, *pr.Title)
for idx, pr := range prs {
str += fmt.Sprintf(` %s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title)
str += "\n"
widget.Items = append(widget.Items, *pr.Number)
}
widget.SetItemCount(maxItems + prLength)
return str
}
func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string {
res := repo.customIssueQuery(filter, perPage)
if res == nil {
return " [grey]Invalid Query[white]\n"
}
if len(res.Issues) == 0 {
issuesLength := len(res.Issues)
if issuesLength == 0 {
return " [grey]none[white]\n"
}
maxItems := widget.GetItemCount()
str := ""
for _, issue := range res.Issues {
str += fmt.Sprintf(" [green]%4d[white] %s\n", *issue.Number, *issue.Title)
for idx, issue := range res.Issues {
str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title)
str += "\n"
widget.Items = append(widget.Items, *issue.Number)
}
widget.SetItemCount(maxItems + issuesLength)
return str
}
@@ -75,8 +106,10 @@ func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string)
}
str := ""
for _, pr := range prs {
str += fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title)
for idx, pr := range prs {
str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title)
str += "\n"
widget.Items = append(widget.Items, *pr.Number)
}
return str