From 4ec9d33a6fb787af35038cac02b68ff174f00e43 Mon Sep 17 00:00:00 2001 From: Nikolay Mateev Date: Fri, 13 Dec 2019 18:27:35 +0200 Subject: [PATCH] Add shortcuts for GitHub Pull Requests and Issues (#777) --- modules/github/github_repo.go | 16 ++++++++++++++++ modules/github/keyboard.go | 2 ++ modules/github/widget.go | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/modules/github/github_repo.go b/modules/github/github_repo.go index 3b0abce7..be0bfadc 100644 --- a/modules/github/github_repo.go +++ b/modules/github/github_repo.go @@ -10,6 +10,12 @@ import ( "golang.org/x/oauth2" ) +const ( + pullRequestsPath = "/pulls" + issuesPath = "/issues" +) + + // GithubRepo defines a new GithubRepo structure type GithubRepo struct { apiKey string @@ -42,6 +48,16 @@ func (repo *GithubRepo) Open() { utils.OpenFile(*repo.RemoteRepo.HTMLURL) } +// Open will open the GitHub Pull Requests URL using the utils helper +func (repo *GithubRepo) OpenPulls() { + utils.OpenFile(*repo.RemoteRepo.HTMLURL + pullRequestsPath) +} + +// Open will open the GitHub Issues URL using the utils helper +func (repo *GithubRepo) OpenIssues() { + utils.OpenFile(*repo.RemoteRepo.HTMLURL + issuesPath) +} + // Refresh reloads the github data via the Github API func (repo *GithubRepo) Refresh() { prs, err := repo.loadPullRequests() diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index ce3d2ace..9ea92554 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -12,6 +12,8 @@ func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardChar("l", widget.NextSource, "Select next source") widget.SetKeyboardChar("h", widget.PrevSource, "Select previous source") widget.SetKeyboardChar("o", widget.openRepo, "Open item in browser") + widget.SetKeyboardChar("p", widget.openPulls, "Open pull requests in browser") + widget.SetKeyboardChar("i", widget.openIssues, "Open issues in browser") widget.SetKeyboardKey(tcell.KeyDown, widget.Next, "Select next item") widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item") diff --git a/modules/github/widget.go b/modules/github/widget.go index 2a7f9f23..ed8ee7da 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -157,3 +157,19 @@ func (widget *Widget) openRepo() { repo.Open() } } + +func (widget *Widget) openPulls() { + repo := widget.currentGithubRepo() + + if repo != nil { + repo.OpenPulls() + } +} + +func (widget *Widget) openIssues() { + repo := widget.currentGithubRepo() + + if repo != nil { + repo.OpenIssues() + } +}