mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'fix-github-selection-lint' of github.com:Midnight-Conqueror/wtf into Midnight-Conqueror-fix-github-selection-lint
This commit is contained in:
commit
27ecabfb18
@ -61,7 +61,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s
|
|||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for idx, pr := range prs {
|
for idx, pr := range prs {
|
||||||
str += fmt.Sprintf(` %s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title)
|
str += fmt.Sprintf(` %s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems+idx, *pr.Number, *pr.Title)
|
||||||
str += "\n"
|
str += "\n"
|
||||||
widget.Items = append(widget.Items, *pr.Number)
|
widget.Items = append(widget.Items, *pr.Number)
|
||||||
}
|
}
|
||||||
@ -73,22 +73,22 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s
|
|||||||
|
|
||||||
func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string {
|
func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string {
|
||||||
res := repo.customIssueQuery(filter, perPage)
|
res := repo.customIssueQuery(filter, perPage)
|
||||||
|
|
||||||
if res == nil {
|
if res == nil {
|
||||||
return " [grey]Invalid Query[white]\n"
|
return " [grey]Invalid Query[white]\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
issuesLength := len(res.Issues)
|
issuesLength := len(res.Issues)
|
||||||
|
|
||||||
if issuesLength == 0 {
|
if issuesLength == 0 {
|
||||||
return " [grey]none[white]\n"
|
return " [grey]none[white]\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
maxItems := widget.GetItemCount()
|
maxItems := widget.GetItemCount()
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for idx, issue := range res.Issues {
|
for idx, issue := range res.Issues {
|
||||||
str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title)
|
str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, maxItems+idx, *issue.Number, *issue.Title)
|
||||||
str += "\n"
|
str += "\n"
|
||||||
widget.Items = append(widget.Items, *issue.Number)
|
widget.Items = append(widget.Items, *issue.Number)
|
||||||
}
|
}
|
||||||
@ -131,10 +131,10 @@ func (widget *Widget) title(repo *GithubRepo) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mergeIcons = map[string]string{
|
var mergeIcons = map[string]string{
|
||||||
"dirty": "[red]![white] ",
|
"dirty": "[red]\u0021[white] ",
|
||||||
"clean": "[green]✔[white] ",
|
"clean": "[green]\u2713[white] ",
|
||||||
"unstable": "[red]✖[white] ",
|
"unstable": "[red]\u274C[white] ",
|
||||||
"blocked": "[red]✖[white] ",
|
"blocked": "[red]\u274C[white] ",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) mergeString(pr *github.PullRequest) string {
|
func (widget *Widget) mergeString(pr *github.PullRequest) string {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GithubRepo defines a new GithubRepo structure
|
||||||
type GithubRepo struct {
|
type GithubRepo struct {
|
||||||
apiKey string
|
apiKey string
|
||||||
baseURL string
|
baseURL string
|
||||||
@ -22,6 +23,7 @@ type GithubRepo struct {
|
|||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewGithubRepo returns a new Github Repo with a name, owner, apiKey, baseURL and uploadURL
|
||||||
func NewGithubRepo(name, owner, apiKey, baseURL, uploadURL string) *GithubRepo {
|
func NewGithubRepo(name, owner, apiKey, baseURL, uploadURL string) *GithubRepo {
|
||||||
repo := GithubRepo{
|
repo := GithubRepo{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -35,6 +37,7 @@ func NewGithubRepo(name, owner, apiKey, baseURL, uploadURL string) *GithubRepo {
|
|||||||
return &repo
|
return &repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open will open the GitHub Repo URL using the utils helper
|
||||||
func (repo *GithubRepo) Open() {
|
func (repo *GithubRepo) Open() {
|
||||||
utils.OpenFile(*repo.RemoteRepo.HTMLURL)
|
utils.OpenFile(*repo.RemoteRepo.HTMLURL)
|
||||||
}
|
}
|
||||||
@ -54,6 +57,7 @@ func (repo *GithubRepo) Refresh() {
|
|||||||
|
|
||||||
/* -------------------- Counts -------------------- */
|
/* -------------------- Counts -------------------- */
|
||||||
|
|
||||||
|
// IssueCount return the total amount of issues as an int
|
||||||
func (repo *GithubRepo) IssueCount() int {
|
func (repo *GithubRepo) IssueCount() int {
|
||||||
if repo.RemoteRepo == nil {
|
if repo.RemoteRepo == nil {
|
||||||
return 0
|
return 0
|
||||||
@ -62,10 +66,12 @@ func (repo *GithubRepo) IssueCount() int {
|
|||||||
return *repo.RemoteRepo.OpenIssuesCount
|
return *repo.RemoteRepo.OpenIssuesCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PullRequestCount returns the total amount of pull requests as an int
|
||||||
func (repo *GithubRepo) PullRequestCount() int {
|
func (repo *GithubRepo) PullRequestCount() int {
|
||||||
return len(repo.PullRequests)
|
return len(repo.PullRequests)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StarCount returns the total amount of stars this repo has gained as an int
|
||||||
func (repo *GithubRepo) StarCount() int {
|
func (repo *GithubRepo) StarCount() int {
|
||||||
if repo.RemoteRepo == nil {
|
if repo.RemoteRepo == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
const defaultTitle = "GitHub"
|
const defaultTitle = "GitHub"
|
||||||
|
|
||||||
|
// Settings defines the configuration properties for this module
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ type customQuery struct {
|
|||||||
perPage int `help:"Number of issues to show"`
|
perPage int `help:"Number of issues to show"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSettingsFromYAML creates a new settings instance from a YAML config block
|
||||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/view"
|
"github.com/wtfutil/wtf/view"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Widget define wtf widget to register widget later
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
view.MultiSourceWidget
|
view.MultiSourceWidget
|
||||||
view.KeyboardWidget
|
view.KeyboardWidget
|
||||||
@ -19,9 +20,10 @@ type Widget struct {
|
|||||||
settings *Settings
|
settings *Settings
|
||||||
Selected int
|
Selected int
|
||||||
maxItems int
|
maxItems int
|
||||||
Items []int
|
Items []int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWidget creates a new instance of the widget
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common),
|
KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common),
|
||||||
@ -48,14 +50,18 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
// SetItemCount sets the amount of PRs RRs and other PRs throughout the widgets display creation
|
||||||
func (widget *Widget) SetItemCount(items int) {
|
func (widget *Widget) SetItemCount(items int) {
|
||||||
widget.maxItems = items
|
widget.maxItems = items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetItemCount returns the amount of PRs RRs and other PRs calculated so far as an int
|
||||||
func (widget *Widget) GetItemCount() int {
|
func (widget *Widget) GetItemCount() int {
|
||||||
return widget.maxItems
|
return widget.maxItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSelected returns the index of the currently highlighted item as an int
|
||||||
func (widget *Widget) GetSelected() int {
|
func (widget *Widget) GetSelected() int {
|
||||||
if widget.Selected < 0 {
|
if widget.Selected < 0 {
|
||||||
return 0
|
return 0
|
||||||
@ -63,6 +69,7 @@ func (widget *Widget) GetSelected() int {
|
|||||||
return widget.Selected
|
return widget.Selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next cycles the currently highlighted text down
|
||||||
func (widget *Widget) Next() {
|
func (widget *Widget) Next() {
|
||||||
widget.Selected++
|
widget.Selected++
|
||||||
if widget.Selected >= widget.maxItems {
|
if widget.Selected >= widget.maxItems {
|
||||||
@ -71,6 +78,7 @@ func (widget *Widget) Next() {
|
|||||||
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prev cycles the currently highlighted text up
|
||||||
func (widget *Widget) Prev() {
|
func (widget *Widget) Prev() {
|
||||||
widget.Selected--
|
widget.Selected--
|
||||||
if widget.Selected < 0 {
|
if widget.Selected < 0 {
|
||||||
@ -79,12 +87,14 @@ func (widget *Widget) Prev() {
|
|||||||
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unselect stops highlighting the text and jumps the scroll position to the top
|
||||||
func (widget *Widget) Unselect() {
|
func (widget *Widget) Unselect() {
|
||||||
widget.Selected = -1
|
widget.Selected = -1
|
||||||
widget.View.Highlight()
|
widget.View.Highlight()
|
||||||
widget.View.ScrollToBeginning()
|
widget.View.ScrollToBeginning()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh reloads the github data via the Github API and reruns the display
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
for _, repo := range widget.GithubRepos {
|
for _, repo := range widget.GithubRepos {
|
||||||
repo.Refresh()
|
repo.Refresh()
|
||||||
@ -93,6 +103,7 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.display()
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HelpText displays the widgets controls
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
return widget.KeyboardWidget.HelpText()
|
return widget.KeyboardWidget.HelpText()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user