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

Displays Github review requests and PRs

This commit is contained in:
Chris Cummer 2018-04-05 10:05:05 -07:00 committed by Chris Cummer
parent 32b395a19e
commit fb637700b1
12 changed files with 168 additions and 38 deletions

View File

@ -63,7 +63,7 @@ func (widget *Widget) addView() {
func (widget *Widget) contentFrom(items []Item) string {
if len(items) == 0 {
return fmt.Sprintf("\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 52))
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 50))
}
str := "\n"

View File

@ -4,6 +4,7 @@ wtf:
refreshInterval: 900
url: "https://api.bamboohr.com/api/gateway.php"
gcal:
currentIcon: "💥"
eventCount: 10
refreshInterval: 300
secretFile: "~/.wtf/gcal/client_secret.json"
@ -12,8 +13,10 @@ wtf:
refreshInterval: 8
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
github:
refreshInterval: 900
organization: "BetterOfficeApps"
refreshInterval: 300
repo: "core-api"
username: "senorprogrammer"
jira:
refreshInterval: 900
opsgenie:

View File

@ -99,12 +99,11 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
}
func (widget *Widget) eventSummary(event *calendar.Event) string {
summary := event.Summary
if widget.eventIsNow(event) {
summary = "🔥 " + summary
return fmt.Sprintf("%s %s", Config.UString("wtf.gcal.currentIcon", "🔸"), event.Summary)
}
return summary
return event.Summary
}
func (widget *Widget) eventTimestamp(event *calendar.Event) string {

View File

@ -38,9 +38,9 @@ func NewWidget() *Widget {
func (widget *Widget) Refresh() {
data := Fetch()
str := fmt.Sprintf("[green]%s[white] [dodgerblue]%s[white]\n", data["repo"][0], data["branch"][0])
title := fmt.Sprintf("[green]%s[white]\n", data["repo"][0])
widget.View.SetTitle(fmt.Sprintf(" 🤞 %s ", str))
widget.View.SetTitle(fmt.Sprintf(" 🤞 %s ", title))
widget.RefreshedAt = time.Now()
widget.View.Clear()
@ -63,6 +63,9 @@ func (widget *Widget) addView() {
func (widget *Widget) contentFrom(data map[string][]string) string {
str := "\n"
str = str + " [red]Branch[white]\n"
str = str + fmt.Sprintf(" %s", data["branch"][0])
str = str + "\n"
str = str + widget.formatChanges(data["changes"])
str = str + "\n"
str = str + widget.formatCommits(data["commits"])

63
github/client.go Normal file
View File

@ -0,0 +1,63 @@
package github
import (
"context"
"fmt"
"net/http"
"os"
ghb "github.com/google/go-github/github"
"golang.org/x/oauth2"
)
type Client struct {
apiKey string
}
func NewClient() *Client {
client := Client{
apiKey: os.Getenv("WTF_GITHUB_TOKEN"),
}
return &client
}
func (client *Client) PullRequests(orgName string, repoName string) []*ghb.PullRequest {
oauthClient := client.oauthClient()
github := ghb.NewClient(oauthClient)
opts := &ghb.PullRequestListOptions{}
prs, _, err := github.PullRequests.List(context.Background(), orgName, repoName, opts)
if err != nil {
fmt.Printf("Problem in getting pull request information %v\n", err)
os.Exit(1)
}
return prs
}
func (client *Client) Repository(orgName string, repoName string) *ghb.Repository {
oauthClient := client.oauthClient()
github := ghb.NewClient(oauthClient)
repo, _, err := github.Repositories.Get(context.Background(), orgName, repoName)
if err != nil {
fmt.Printf("Problem in getting repository information %v\n", err)
os.Exit(1)
}
return repo
}
/* -------------------- Unexported Functions -------------------- */
func (client *Client) oauthClient() *http.Client {
tokenService := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: client.apiKey},
)
return oauth2.NewClient(context.Background(), tokenService)
}

View File

@ -5,6 +5,7 @@ import (
"time"
"github.com/gdamore/tcell"
ghb "github.com/google/go-github/github"
"github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
@ -34,11 +35,25 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
client := NewClient()
repo := client.Repository(Config.UString("wtf.github.organization"), Config.UString("wtf.github.repo"))
org := *repo.Organization
prs := client.PullRequests(Config.UString("wtf.github.organization"), Config.UString("wtf.github.repo"))
title := fmt.Sprintf("[green]%s - %s[white]", *org.Login, *repo.Name)
widget.View.SetTitle(fmt.Sprintf(" 🤘 %s ", title))
widget.RefreshedAt = time.Now()
str := "\n"
str = str + " [red]Open Review Requests[white]\n"
str = str + widget.prsForReview(prs)
str = str + "\n"
str = str + " [red]Open Pull Requests[white]\n"
str = str + widget.openPRs(prs)
widget.View.Clear()
fmt.Fprintf(widget.View, "%s", "github")
fmt.Fprintf(widget.View, str)
}
/* -------------------- Unexported Functions -------------------- */
@ -50,6 +65,51 @@ func (widget *Widget) addView() {
view.SetBorderColor(tcell.ColorGray)
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}
func (widget *Widget) prsForReview(prs []*ghb.PullRequest) string {
if len(prs) > 0 {
str := ""
for _, pr := range prs {
for _, reviewer := range pr.RequestedReviewers {
if *reviewer.Login == Config.UString("wtf.github.username") {
str = str + fmt.Sprintf(" [green]%d[white] %s\n", *pr.Number, *pr.Title)
}
}
}
if str == "" {
str = " [grey]none[white]\n"
}
return str
}
return " [grey]none[white]\n"
}
func (widget *Widget) openPRs(prs []*ghb.PullRequest) string {
if len(prs) > 0 {
str := ""
for _, pr := range prs {
user := *pr.User
if *user.Login == Config.UString("wtf.github.username") {
str = str + fmt.Sprintf(" [green]%d[white] %s\n", *pr.Number, *pr.Title)
}
}
if str == "" {
str = " [grey]none[white]\n"
}
return str
}
return " [grey]none[white]\n"
}

View File

@ -5,10 +5,10 @@ import ()
func Fetch() map[string]string {
data := make(map[string]string)
data["Firewall Enabled"] = FirewallState()
data["Firewall Stealth"] = FirewallStealthState()
data["Wifi Encryption"] = WifiEncryption()
data["Wifi Network"] = WifiName()
data["Enabled"] = FirewallState()
data["Stealth"] = FirewallStealthState()
data["Encryption"] = WifiEncryption()
data["Network"] = WifiName()
return data
}

View File

@ -2,7 +2,7 @@ package security
import (
"fmt"
"sort"
//"sort"
"time"
"github.com/gdamore/tcell"
@ -53,24 +53,14 @@ func (widget *Widget) addView() {
view.SetBorderColor(tcell.ColorGray)
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}
func (widget *Widget) contentFrom(data map[string]string) string {
str := "\n"
// Sort the map keys in alphabetical order
var keys []string
for key, _ := range data {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
val := data[key]
str = str + fmt.Sprintf(" %16s: %s\n", key, val)
}
str := fmt.Sprintf(" Firewall: %s Network: %s\n", data["Enabled"], data["Network"])
str = str + fmt.Sprintf(" Stealth: %s Crypto: %s\n", data["Stealth"], data["Encryption"])
return str
}

View File

@ -1,6 +1,7 @@
package weather
import (
//"fmt"
"os"
owm "github.com/briandowns/openweathermap"

View File

@ -70,9 +70,16 @@ func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
tempUnit := Config.UString("wtf.weather.tempUnit", "C")
str = str + fmt.Sprintf("%10s: %4.1f° %s\n", "Current", data.Main.Temp, tempUnit)
str = str + fmt.Sprintf("%10s: %4.1f° %s\n", "High", data.Main.TempMax, tempUnit)
str = str + fmt.Sprintf("%10s: %4.1f° %s\n", "Low", data.Main.TempMin, tempUnit)
str = str + fmt.Sprintf("%8s: %4.1f° %s\n", "High", data.Main.TempMax, tempUnit)
str = str + fmt.Sprintf("%8s: [yellow]%4.1f° %s[white]\n", "Current", data.Main.Temp, tempUnit)
str = str + fmt.Sprintf("%8s: %4.1f° %s\n", "Low", data.Main.TempMin, tempUnit)
str = str + "\n"
str = str + fmt.Sprintf(
" Sunrise: %s Sunset: %s\n",
wtf.UnixTime(int64(data.Sys.Sunrise)).Format("15:04"),
wtf.UnixTime(int64(data.Sys.Sunset)).Format("15:04"),
)
return str
}

16
wtf.go
View File

@ -83,19 +83,19 @@ func main() {
weather.Refresh()
grid := tview.NewGrid()
grid.SetRows(9, 9, 9, 9, 9, 6, 3) // How _high_ the row is, in terminal rows
grid.SetColumns(40, 40) // How _wide_ the column is, in terminal columns
grid.SetRows(10, 10, 10, 10, 10, 4) // How _high_ the row is, in terminal rows
grid.SetColumns(37, 37, 37, 37, 37) // How _wide_ the column is, in terminal columns
grid.SetBorder(false)
grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, false)
grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false)
grid.AddItem(git.View, 0, 2, 3, 1, 0, 0, false)
grid.AddItem(github.View, 3, 2, 3, 1, 0, 0, false)
grid.AddItem(git.View, 0, 2, 3, 3, 0, 0, false)
grid.AddItem(github.View, 3, 2, 2, 3, 0, 0, false)
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
grid.AddItem(sec.View, 1, 1, 1, 1, 0, 0, false)
grid.AddItem(opsgenie.View, 2, 0, 3, 1, 0, 0, false)
grid.AddItem(jira.View, 5, 0, 1, 1, 0, 0, false)
grid.AddItem(stat.View, 6, 0, 3, 3, 0, 0, false)
grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false)
grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false)
grid.AddItem(jira.View, 1, 1, 1, 1, 0, 0, false)
grid.AddItem(stat.View, 5, 2, 3, 3, 0, 0, false)
app := tview.NewApplication()

View File

@ -35,3 +35,7 @@ func Today() string {
localNow := time.Now().Local()
return localNow.Format("2006-01-02")
}
func UnixTime(unix int64) time.Time {
return time.Unix(unix, 0)
}