Style gh pr list

This commit is contained in:
Corey Johnson 2019-10-14 14:21:15 -07:00
parent 1009ad5598
commit b4d28f11b0
3 changed files with 56 additions and 10 deletions

View file

@ -2,8 +2,11 @@ package command
import (
"fmt"
"strings"
"github.com/github/gh-cli/api"
"github.com/github/gh-cli/git"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
)
@ -37,22 +40,62 @@ func ExecutePr() error {
return err
}
fmt.Printf("Current Pr\n")
printHeader("Current branch")
if prPayload.CurrentPR != nil {
printPr(*prPayload.CurrentPR)
printPrs(*prPayload.CurrentPR)
} else {
message := fmt.Sprintf(" There is no pull request associated with %s", aurora.Cyan("["+currentBranch()+"]"))
printMessage(message)
}
fmt.Printf("Your Prs\n")
for _, pr := range prPayload.ViewerCreated {
printPr(pr)
fmt.Println()
printHeader("Created by you")
if len(prPayload.ViewerCreated) > 0 {
printPrs(prPayload.ViewerCreated...)
} else {
printMessage(" You have no open pull requests")
}
fmt.Printf("Prs you need to review\n")
for _, pr := range prPayload.ReviewRequested {
printPr(pr)
fmt.Println()
printHeader("Requesting a code review from you")
if len(prPayload.ReviewRequested) > 0 {
printPrs(prPayload.ReviewRequested...)
} else {
printMessage(" You have no pull requests to review")
}
fmt.Println()
return nil
}
func printPr(pr api.PullRequest) {
fmt.Printf(" #%d %s [%s]\n", pr.Number, pr.Title, pr.HeadRefName)
func printPrs(prs ...api.PullRequest) {
for _, pr := range prs {
fmt.Printf(" #%d %s [%s]\n", pr.Number, truncateTitle(pr.Title), aurora.Cyan(pr.HeadRefName))
}
}
func printHeader(s string) {
fmt.Println(aurora.Bold(s))
}
func printMessage(s string) {
fmt.Println(aurora.Gray(8, s))
}
func truncateTitle(title string) string {
const maxLength = 50
if len(title) > maxLength {
return title[0:maxLength-3] + "..."
}
return title
}
func currentBranch() string {
currentBranch, err := git.Head()
if err != nil {
panic(err)
}
return strings.Replace(currentBranch, "refs/heads/", "", 1)
}

1
go.mod
View file

@ -5,6 +5,7 @@ go 1.13
require (
github.com/BurntSushi/toml v0.3.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b
github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-isatty v0.0.9
github.com/mitchellh/go-homedir v1.1.0

2
go.sum
View file

@ -12,6 +12,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b h1:PMbSa9CgaiQR9NLlUTwKi+7aeLl3GG5JX5ERJxfQ3IE=
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=