mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #473 from Sean-Der/master
Add new key 'customQueries' to github module
This commit is contained in:
commit
a98aa8592a
@ -18,12 +18,14 @@ func (widget *Widget) display() {
|
||||
str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n"
|
||||
str += " [red]Stats[white]\n"
|
||||
str += widget.displayStats(repo)
|
||||
str += "\n"
|
||||
str += " [red]Open Review Requests[white]\n"
|
||||
str += "\n [red]Open Review Requests[white]\n"
|
||||
str += widget.displayMyReviewRequests(repo, widget.settings.username)
|
||||
str += "\n"
|
||||
str += " [red]My Pull Requests[white]\n"
|
||||
str += "\n [red]My Pull Requests[white]\n"
|
||||
str += widget.displayMyPullRequests(repo, widget.settings.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)
|
||||
}
|
||||
|
||||
widget.TextWidget.Redraw(title, str, false)
|
||||
}
|
||||
@ -43,6 +45,23 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s
|
||||
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 {
|
||||
return " [grey]none[white]\n"
|
||||
}
|
||||
|
||||
str := ""
|
||||
for _, issue := range res.Issues {
|
||||
str += fmt.Sprintf(" [green]%4d[white] %s\n", *issue.Number, *issue.Title)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string {
|
||||
prs := repo.myReviewRequests(username)
|
||||
|
||||
|
@ -2,6 +2,7 @@ package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
ghb "github.com/google/go-github/v25/github"
|
||||
@ -152,9 +153,23 @@ func (repo *GithubRepo) myReviewRequests(username string) []*ghb.PullRequest {
|
||||
return prs
|
||||
}
|
||||
|
||||
func (repo *GithubRepo) customIssueQuery(filter string, perPage int) *ghb.IssuesSearchResult {
|
||||
github, err := repo.githubClient()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
opts := &ghb.SearchOptions{}
|
||||
if perPage != 0 {
|
||||
opts.ListOptions.PerPage = perPage
|
||||
}
|
||||
|
||||
prs, _, _ := github.Search.Issues(context.Background(), fmt.Sprintf("%s repo:%s/%s", filter, repo.Owner, repo.Name), opts)
|
||||
return prs
|
||||
}
|
||||
|
||||
func (repo *GithubRepo) loadPullRequests() ([]*ghb.PullRequest, error) {
|
||||
github, err := repo.githubClient()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -16,12 +16,19 @@ type Settings struct {
|
||||
|
||||
apiKey string
|
||||
baseURL string
|
||||
customQueries []customQuery
|
||||
enableStatus bool
|
||||
repositories []string
|
||||
uploadURL string
|
||||
username string
|
||||
}
|
||||
|
||||
type customQuery struct {
|
||||
title string
|
||||
filter string
|
||||
perPage int
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
|
||||
settings := Settings{
|
||||
@ -34,6 +41,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
username: ymlConfig.UString("username"),
|
||||
}
|
||||
settings.repositories = parseRepositories(ymlConfig)
|
||||
settings.customQueries = parseCustomQueries(ymlConfig)
|
||||
|
||||
return &settings
|
||||
}
|
||||
@ -52,3 +60,27 @@ func parseRepositories(ymlConfig *config.Config) []string {
|
||||
result = wtf.ToStrs(ymlConfig.UList("repositories"))
|
||||
return result
|
||||
}
|
||||
|
||||
func parseCustomQueries(ymlConfig *config.Config) []customQuery {
|
||||
result := []customQuery{}
|
||||
if customQueries, err := ymlConfig.Map("customQueries"); err == nil {
|
||||
for _, query := range customQueries {
|
||||
c := customQuery{}
|
||||
for key, value := range query.(map[string]interface{}) {
|
||||
switch key {
|
||||
case "title":
|
||||
c.title = value.(string)
|
||||
case "filter":
|
||||
c.filter = value.(string)
|
||||
case "perPage":
|
||||
c.perPage = value.(int)
|
||||
}
|
||||
}
|
||||
|
||||
if c.title != "" && c.filter != "" {
|
||||
result = append(result, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user