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:
parent
32b395a19e
commit
fb637700b1
@ -63,7 +63,7 @@ func (widget *Widget) addView() {
|
|||||||
|
|
||||||
func (widget *Widget) contentFrom(items []Item) string {
|
func (widget *Widget) contentFrom(items []Item) string {
|
||||||
if len(items) == 0 {
|
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"
|
str := "\n"
|
||||||
|
@ -4,6 +4,7 @@ wtf:
|
|||||||
refreshInterval: 900
|
refreshInterval: 900
|
||||||
url: "https://api.bamboohr.com/api/gateway.php"
|
url: "https://api.bamboohr.com/api/gateway.php"
|
||||||
gcal:
|
gcal:
|
||||||
|
currentIcon: "💥"
|
||||||
eventCount: 10
|
eventCount: 10
|
||||||
refreshInterval: 300
|
refreshInterval: 300
|
||||||
secretFile: "~/.wtf/gcal/client_secret.json"
|
secretFile: "~/.wtf/gcal/client_secret.json"
|
||||||
@ -12,8 +13,10 @@ wtf:
|
|||||||
refreshInterval: 8
|
refreshInterval: 8
|
||||||
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
|
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
|
||||||
github:
|
github:
|
||||||
refreshInterval: 900
|
organization: "BetterOfficeApps"
|
||||||
|
refreshInterval: 300
|
||||||
repo: "core-api"
|
repo: "core-api"
|
||||||
|
username: "senorprogrammer"
|
||||||
jira:
|
jira:
|
||||||
refreshInterval: 900
|
refreshInterval: 900
|
||||||
opsgenie:
|
opsgenie:
|
||||||
|
@ -99,12 +99,11 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) eventSummary(event *calendar.Event) string {
|
func (widget *Widget) eventSummary(event *calendar.Event) string {
|
||||||
summary := event.Summary
|
|
||||||
if widget.eventIsNow(event) {
|
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 {
|
func (widget *Widget) eventTimestamp(event *calendar.Event) string {
|
||||||
|
@ -38,9 +38,9 @@ func NewWidget() *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data := Fetch()
|
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.RefreshedAt = time.Now()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
@ -63,6 +63,9 @@ func (widget *Widget) addView() {
|
|||||||
|
|
||||||
func (widget *Widget) contentFrom(data map[string][]string) string {
|
func (widget *Widget) contentFrom(data map[string][]string) string {
|
||||||
str := "\n"
|
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 + widget.formatChanges(data["changes"])
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
str = str + widget.formatCommits(data["commits"])
|
str = str + widget.formatCommits(data["commits"])
|
||||||
|
63
github/client.go
Normal file
63
github/client.go
Normal 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)
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
ghb "github.com/google/go-github/github"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
@ -34,11 +35,25 @@ func NewWidget() *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
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()
|
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()
|
widget.View.Clear()
|
||||||
fmt.Fprintf(widget.View, "%s", "github")
|
fmt.Fprintf(widget.View, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
@ -50,6 +65,51 @@ func (widget *Widget) addView() {
|
|||||||
view.SetBorderColor(tcell.ColorGray)
|
view.SetBorderColor(tcell.ColorGray)
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.Name)
|
view.SetTitle(widget.Name)
|
||||||
|
view.SetWrap(false)
|
||||||
|
|
||||||
widget.View = view
|
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"
|
||||||
|
}
|
||||||
|
@ -5,10 +5,10 @@ import ()
|
|||||||
func Fetch() map[string]string {
|
func Fetch() map[string]string {
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
|
|
||||||
data["Firewall Enabled"] = FirewallState()
|
data["Enabled"] = FirewallState()
|
||||||
data["Firewall Stealth"] = FirewallStealthState()
|
data["Stealth"] = FirewallStealthState()
|
||||||
data["Wifi Encryption"] = WifiEncryption()
|
data["Encryption"] = WifiEncryption()
|
||||||
data["Wifi Network"] = WifiName()
|
data["Network"] = WifiName()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package security
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
//"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@ -53,24 +53,14 @@ func (widget *Widget) addView() {
|
|||||||
view.SetBorderColor(tcell.ColorGray)
|
view.SetBorderColor(tcell.ColorGray)
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.Name)
|
view.SetTitle(widget.Name)
|
||||||
|
view.SetWrap(false)
|
||||||
|
|
||||||
widget.View = view
|
widget.View = view
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data map[string]string) string {
|
func (widget *Widget) contentFrom(data map[string]string) string {
|
||||||
str := "\n"
|
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"])
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package weather
|
package weather
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
//"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
owm "github.com/briandowns/openweathermap"
|
owm "github.com/briandowns/openweathermap"
|
||||||
|
@ -70,9 +70,16 @@ func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
|||||||
|
|
||||||
tempUnit := Config.UString("wtf.weather.tempUnit", "C")
|
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("%8s: %4.1f° %s\n", "High", data.Main.TempMax, tempUnit)
|
||||||
str = str + fmt.Sprintf("%10s: %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("%10s: %4.1f° %s\n", "Low", data.Main.TempMin, 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
|
return str
|
||||||
}
|
}
|
||||||
|
16
wtf.go
16
wtf.go
@ -83,19 +83,19 @@ func main() {
|
|||||||
weather.Refresh()
|
weather.Refresh()
|
||||||
|
|
||||||
grid := tview.NewGrid()
|
grid := tview.NewGrid()
|
||||||
grid.SetRows(9, 9, 9, 9, 9, 6, 3) // How _high_ the row is, in terminal rows
|
grid.SetRows(10, 10, 10, 10, 10, 4) // How _high_ the row is, in terminal rows
|
||||||
grid.SetColumns(40, 40) // How _wide_ the column is, in terminal columns
|
grid.SetColumns(37, 37, 37, 37, 37) // How _wide_ the column is, in terminal columns
|
||||||
grid.SetBorder(false)
|
grid.SetBorder(false)
|
||||||
|
|
||||||
grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, 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(cal.View, 2, 1, 4, 1, 0, 0, false)
|
||||||
grid.AddItem(git.View, 0, 2, 3, 1, 0, 0, false)
|
grid.AddItem(git.View, 0, 2, 3, 3, 0, 0, false)
|
||||||
grid.AddItem(github.View, 3, 2, 3, 1, 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(weather.View, 0, 1, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(sec.View, 1, 1, 1, 1, 0, 0, false)
|
grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(opsgenie.View, 2, 0, 3, 1, 0, 0, false)
|
grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false)
|
||||||
grid.AddItem(jira.View, 5, 0, 1, 1, 0, 0, false)
|
grid.AddItem(jira.View, 1, 1, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(stat.View, 6, 0, 3, 3, 0, 0, false)
|
grid.AddItem(stat.View, 5, 2, 3, 3, 0, 0, false)
|
||||||
|
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
|
|
||||||
|
@ -35,3 +35,7 @@ func Today() string {
|
|||||||
localNow := time.Now().Local()
|
localNow := time.Now().Local()
|
||||||
return localNow.Format("2006-01-02")
|
return localNow.Format("2006-01-02")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UnixTime(unix int64) time.Time {
|
||||||
|
return time.Unix(unix, 0)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user