diff --git a/bamboohr/widget.go b/bamboohr/widget.go index c65fb90a..3f0fb04b 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -28,7 +28,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/config.yml b/config.yml index fb4438f6..ba840130 100644 --- a/config.yml +++ b/config.yml @@ -8,7 +8,12 @@ wtf: refreshInterval: 300 secretFile: "~/.wtf/gcal/client_secret.json" git: + commitCount: 10 refreshInterval: 8 + repository: "/Users/chris/Documents/Lendesk/core-api" + github: + refreshInterval: 900 + repo: "core-api" jira: refreshInterval: 900 opsgenie: diff --git a/gcal/widget.go b/gcal/widget.go index 4c957de0..d3bf30a2 100644 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -30,7 +30,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/git/client.go b/git/client.go index 249f7907..e97b3593 100644 --- a/git/client.go +++ b/git/client.go @@ -1,28 +1,23 @@ package git import ( + "fmt" "os/exec" "strings" "github.com/senorprogrammer/wtf/wtf" ) -type Client struct { - CommitCount int -} +type Client struct{} func NewClient() *Client { - client := Client{ - CommitCount: 10, - } - - return &client + return &Client{} } -/* -------------------- Unexported Functions -------------------- */ +/* -------------------- Exported Functions -------------------- */ func (client *Client) Branch() string { - arg := []string{"rev-parse", "--abbrev-ref", "HEAD"} + arg := []string{client.gitDir(), client.workTree(), "rev-parse", "--abbrev-ref", "HEAD"} cmd := exec.Command("git", arg...) str := wtf.ExecuteCommand(cmd) @@ -30,7 +25,7 @@ func (client *Client) Branch() string { } func (client *Client) ChangedFiles() []string { - arg := []string{"status", "--porcelain"} + arg := []string{client.gitDir(), client.workTree(), "status", "--porcelain"} cmd := exec.Command("git", arg...) str := wtf.ExecuteCommand(cmd) @@ -40,7 +35,9 @@ func (client *Client) ChangedFiles() []string { } func (client *Client) Commits() []string { - arg := []string{"log", "--date=format:\"%b %d, %Y\"", "-n 10", "--pretty=format:\"[forestgreen]%h [white]%s [grey]%an on %cd[white]\""} + numStr := fmt.Sprintf("-n %d", Config.UInt("wtf.git.commitCount", 10)) + + arg := []string{client.gitDir(), client.workTree(), "log", "--date=format:\"%b %d, %Y\"", numStr, "--pretty=format:\"[forestgreen]%h [white]%s [grey]%an on %cd[white]\""} cmd := exec.Command("git", arg...) str := wtf.ExecuteCommand(cmd) @@ -50,9 +47,19 @@ func (client *Client) Commits() []string { } func (client *Client) Repository() string { - arg := []string{"rev-parse", "--show-toplevel"} + arg := []string{client.gitDir(), client.workTree(), "rev-parse", "--show-toplevel"} cmd := exec.Command("git", arg...) str := wtf.ExecuteCommand(cmd) return str } + +/* -------------------- Exported Functions -------------------- */ + +func (client *Client) gitDir() string { + return fmt.Sprintf("--git-dir=%s/.git", Config.UString("wtf.git.repository")) +} + +func (client *Client) workTree() string { + return fmt.Sprintf("--work-tree=%s", Config.UString("wtf.git.repository")) +} diff --git a/git/widget.go b/git/widget.go index 78098119..90c70e36 100644 --- a/git/widget.go +++ b/git/widget.go @@ -29,7 +29,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/github/widget.go b/github/widget.go new file mode 100644 index 00000000..e7626d25 --- /dev/null +++ b/github/widget.go @@ -0,0 +1,55 @@ +package github + +import ( + "fmt" + "time" + + "github.com/gdamore/tcell" + "github.com/olebedev/config" + "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/wtf" +) + +var Config *config.Config + +type Widget struct { + wtf.BaseWidget + View *tview.TextView +} + +func NewWidget() *Widget { + widget := Widget{ + BaseWidget: wtf.BaseWidget{ + Name: "Github", + RefreshedAt: time.Now(), + RefreshInt: Config.UInt("wtf.github.refreshInterval", 900), + }, + } + + widget.addView() + + return &widget +} + +/* -------------------- Exported Functions -------------------- */ + +func (widget *Widget) Refresh() { + widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) + widget.RefreshedAt = time.Now() + + widget.View.Clear() + fmt.Fprintf(widget.View, "%s", "github") +} + +/* -------------------- Unexported Functions -------------------- */ + +func (widget *Widget) addView() { + view := tview.NewTextView() + + view.SetBorder(true) + view.SetBorderColor(tcell.ColorGray) + view.SetDynamicColors(true) + view.SetTitle(widget.Name) + + widget.View = view +} diff --git a/jira/widget.go b/jira/widget.go index a89c3cf2..4351da40 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -27,7 +27,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } @@ -35,7 +34,7 @@ func NewWidget() *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.View.SetTitle(" JIRA ") + widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) widget.RefreshedAt = time.Now() widget.View.Clear() diff --git a/opsgenie/widget.go b/opsgenie/widget.go index ff9917e4..e7c7a44d 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -28,7 +28,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/security/widget.go b/security/widget.go index 80e21508..227c0dec 100644 --- a/security/widget.go +++ b/security/widget.go @@ -28,7 +28,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/status/widget.go b/status/widget.go index 8f9f2adb..310a247a 100644 --- a/status/widget.go +++ b/status/widget.go @@ -30,7 +30,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/weather/widget.go b/weather/widget.go index b00d33ef..ff06bc60 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -29,7 +29,6 @@ func NewWidget() *Widget { } widget.addView() - go wtf.Refresh(&widget) return &widget } diff --git a/wtf.go b/wtf.go index ebfba560..fa7c83f4 100644 --- a/wtf.go +++ b/wtf.go @@ -8,12 +8,14 @@ import ( "github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" + "github.com/senorprogrammer/wtf/github" "github.com/senorprogrammer/wtf/homedir" "github.com/senorprogrammer/wtf/jira" "github.com/senorprogrammer/wtf/opsgenie" "github.com/senorprogrammer/wtf/security" "github.com/senorprogrammer/wtf/status" "github.com/senorprogrammer/wtf/weather" + "github.com/senorprogrammer/wtf/wtf" ) var Config = loadConfig() @@ -30,12 +32,7 @@ func loadConfig() *config.Config { } func refresher(stat *status.Widget, app *tview.Application) { - refreshInterval, err := Config.Int("wtf.refreshInterval") - if err != nil { - refreshInterval = 1 - } - - tick := time.NewTicker(time.Duration(refreshInterval) * time.Second) + tick := time.NewTicker(time.Duration(Config.UInt("wtf.refreshInterval", 1)) * time.Second) quit := make(chan struct{}) for { @@ -53,30 +50,42 @@ func main() { bamboohr.Config = Config bamboo := bamboohr.NewWidget() bamboo.Refresh() + go wtf.Schedule(bamboo) gcal.Config = Config cal := gcal.NewWidget() cal.Refresh() + go wtf.Schedule(cal) git.Config = Config git := git.NewWidget() git.Refresh() + go wtf.Schedule(git) + + github.Config = Config + github := github.NewWidget() + github.Refresh() + go wtf.Schedule(github) jira.Config = Config jira := jira.NewWidget() jira.Refresh() + go wtf.Schedule(jira) opsgenie.Config = Config opsgenie := opsgenie.NewWidget() opsgenie.Refresh() + go wtf.Schedule(opsgenie) security.Config = Config sec := security.NewWidget() sec.Refresh() + go wtf.Schedule(sec) status.Config = Config stat := status.NewWidget() stat.Refresh() + go wtf.Schedule(stat) weather.Config = Config weather := weather.NewWidget() @@ -90,6 +99,7 @@ func main() { 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(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) diff --git a/wtf/refresher.go b/wtf/scheduler.go similarity index 82% rename from wtf/refresher.go rename to wtf/scheduler.go index fa5ea9ee..7520d596 100644 --- a/wtf/refresher.go +++ b/wtf/scheduler.go @@ -4,12 +4,12 @@ import ( "time" ) -type Refresher interface { +type Scheduler interface { Refresh() RefreshInterval() int } -func Refresh(widget Refresher) { +func Schedule(widget Scheduler) { tick := time.NewTicker(time.Duration(widget.RefreshInterval()) * time.Second) quit := make(chan struct{})