From 27a267b1239ccf7c277af702a85ce21a8edfe37b Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 10 Apr 2018 10:12:25 -0700 Subject: [PATCH] Cleaner config format and added simple_config.yml example --- CONTRIBUTING.md | 90 +++++++++++++++++++++++++ LICENSE.md | 7 ++ Makefile | 0 README.md | 36 ++++++++-- _sample_configs/complex_config.yml | 105 +++++++++++++++++++++++++++++ _sample_configs/simple_config.yml | 22 ++++++ bamboohr/widget.go | 2 +- config.yml | 104 ---------------------------- gcal/client.go | 4 +- gcal/widget.go | 2 +- git/client.go | 6 +- github/widget.go | 8 +-- newrelic/client.go | 4 +- newrelic/widget.go | 2 +- weather/client.go | 2 +- weather/widget.go | 4 +- wtf/scheduler.go | 8 ++- wtf/text_widget.go | 12 ++-- 18 files changed, 285 insertions(+), 133 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 Makefile create mode 100644 _sample_configs/complex_config.yml create mode 100644 _sample_configs/simple_config.yml delete mode 100644 config.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..dc502913 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,90 @@ +# Contributing + +When contributing to this repository, please first discuss the change you wish to make via issue, +email, or any other method with the owners of this repository before making a change. + +Note that we have a code of conduct. Please follow it in all your interactions with the project. + +## Pull Request Process + +1. Ensure any install or build dependencies are removed before the end of the layer when doing a + build. +2. Update the [README.md](README.md) with details of changes to the interface, this includes new environment + variables, useful file locations and configuration parameters. +3. Increase the version numbers in any examples files and the [README.md](README.md) to the new version that this + Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). + +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +### Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +### Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +### Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [INSERT EMAIL ADDRESS]. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +### Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..7bbd1567 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2018, Chris Cummer + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index f68abd61..fe4a8e5f 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,10 @@ A personal terminal-based dashboard utility, designed for displaying infrequently-updating, but very important, daily data. -## Required Prerequisites +## Prerequisites -1. [Git](https://git-scm.com/downloads) -1. [Go](https://golang.org/doc/install) - -## Optional Prerequisites +Ensure you have [Go](https://golang.org/doc/install) installed and +operational. Depending on which modules you want to run, you'll need the appropriate API and configuration credentials. For each of the following supported services @@ -109,3 +107,31 @@ Displays the following current weather information for the specified city: In the configuration, use a city code from the OpenWeatherMap [city list](http://openweathermap.org/help/city_list.txt). + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests. + +## Authors + +* Chris Cummer, [senorprogrammer](https://github.com/senorprogrammer) + +## License + +See [LICENSE.md](LICENSE.md) file for details. + +## Acknowledgments + +The inspiration for `WTF` came from Monica Dinculescu's +[tiny-care-terminal](https://github.com/notwaldorf/tiny-care-terminal). + +The following open-source libraries were used in the creation of `WTF`. +Many thanks to all these developers. + +* [calendar](https://google.golang.org/api/calendar/v3) +* [config](https://github.com/olebedev/config) +* [go-github](https://github.com/google/go-github) +* [newrelic](https://github.com/yfronto/newrelic) +* [openweathremap](https://github.com/briandowns/openweathermap) +* [tcell](https://github.com/gdamore/tcell) +* [tview](https://github.com/rivo/tview) diff --git a/_sample_configs/complex_config.yml b/_sample_configs/complex_config.yml new file mode 100644 index 00000000..1e98b523 --- /dev/null +++ b/_sample_configs/complex_config.yml @@ -0,0 +1,105 @@ +wtf: + grid: + # How _wide_ the columns are, in terminal characters. In this case we have + # five columns, each of which are 37 characters wide + columns: [37, 37, 37, 37, 37] + + # How _high_ the rows are, in terminal lines. In this case we have five rows + # that support ten line of text, and one of four + rows: [10, 10, 10, 10, 10, 4] + refreshInterval: 1 + mods: + bamboohr: + enabled: true + position: + top: 0 + left: 0 + height: 2 + width: 1 + refreshInterval: 900 + url: "https://api.bamboohr.com/api/gateway.php" + gcal: + currentIcon: "💥" + enabled: true + eventCount: 10 + position: + top: 2 + left: 1 + height: 4 + width: 1 + refreshInterval: 300 + secretFile: "~/.wtf/gcal/client_secret.json" + git: + commitCount: 5 + enabled: true + position: + top: 0 + left: 2 + height: 2 + width: 3 + refreshInterval: 8 + repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf" + github: + enabled: true + owner: "senorprogrammer" + position: + top: 2 + left: 2 + height: 2 + width: 3 + refreshInterval: 300 + repo: "wtf" + username: "senorprogrammer" + jira: + enabled: true + position: + top: 1 + left: 1 + height: 1 + width: 1 + refreshInterval: 900 + newrelic: + applicationId: 10549735 + enabled: true + deployCount: 10 + position: + top: 4 + left: 2 + height: 2 + width: 3 + refreshInterval: 900 + opsgenie: + enabled: true + position: + top: 2 + left: 0 + height: 2 + width: 1 + refreshInterval: 21600 + security: + enabled: true + position: + top: 4 + left: 0 + height: 2 + width: 1 + refreshInterval: 3600 + status: + enabled: false + position: + top: 5 + left: 0 + height: 1 + width: 1 + refreshInterval: 1 + weather: + cityId: 6173331 + enabled: true + language: "EN" + position: + top: 0 + left: 1 + height: 1 + width: 1 + tempUnit: "C" + refreshInterval: 900 diff --git a/_sample_configs/simple_config.yml b/_sample_configs/simple_config.yml new file mode 100644 index 00000000..620c98d9 --- /dev/null +++ b/_sample_configs/simple_config.yml @@ -0,0 +1,22 @@ +wtf: + grid: + columns: [40] + rows: [13, 3] + refreshInterval: 1 + mods: + security: + enabled: true + position: + top: 0 + left: 0 + height: 1 + width: 1 + refreshInterval: 3600 + status: + enabled: true + position: + top: 1 + left: 0 + height: 1 + width: 1 + refreshInterval: 1 diff --git a/bamboohr/widget.go b/bamboohr/widget.go index 7b370caa..a7736fdd 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -33,7 +33,7 @@ func (widget *Widget) Refresh() { return } - url, _ := Config.String("wtf.bamboohr.url") + url, _ := Config.String("wtf.mods.bamboohr.url") client := NewClient(url) todayItems := client.Away( diff --git a/config.yml b/config.yml deleted file mode 100644 index bc89be15..00000000 --- a/config.yml +++ /dev/null @@ -1,104 +0,0 @@ -wtf: - grid: - # How _wide_ the columns are, in terminal characters. In this case we have - # five columns, each of which are 37 characters wide - columns: [37, 37, 37, 37, 37] - - # How _high_ the rows are, in terminal lines. In this case we have five rows - # that support ten line of text, and one of four - rows: [10, 10, 10, 10, 10, 4] - refreshInterval: 1 - bamboohr: - enabled: true - position: - top: 0 - left: 0 - height: 2 - width: 1 - refreshInterval: 900 - url: "https://api.bamboohr.com/api/gateway.php" - gcal: - currentIcon: "💥" - enabled: true - eventCount: 10 - position: - top: 2 - left: 1 - height: 4 - width: 1 - refreshInterval: 300 - secretFile: "~/.wtf/gcal/client_secret.json" - git: - commitCount: 5 - enabled: true - position: - top: 0 - left: 2 - height: 2 - width: 3 - refreshInterval: 8 - repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf" - github: - enabled: true - owner: "senorprogrammer" - position: - top: 2 - left: 2 - height: 2 - width: 3 - refreshInterval: 300 - repo: "wtf" - username: "senorprogrammer" - jira: - enabled: true - position: - top: 1 - left: 1 - height: 1 - width: 1 - refreshInterval: 900 - newrelic: - applicationId: 10549735 - enabled: true - deployCount: 10 - position: - top: 4 - left: 2 - height: 2 - width: 3 - refreshInterval: 900 - opsgenie: - enabled: true - position: - top: 2 - left: 0 - height: 2 - width: 1 - refreshInterval: 21600 - security: - enabled: true - position: - top: 4 - left: 0 - height: 2 - width: 1 - refreshInterval: 3600 - status: - enabled: false - position: - top: 5 - left: 0 - height: 1 - width: 1 - refreshInterval: 1 - weather: - cityId: 6173331 - enabled: true - language: "EN" - position: - top: 0 - left: 1 - height: 1 - width: 1 - tempUnit: "C" - refreshInterval: 900 diff --git a/gcal/client.go b/gcal/client.go index 40c87a49..605cb9fc 100644 --- a/gcal/client.go +++ b/gcal/client.go @@ -30,7 +30,7 @@ import ( func Fetch() (*calendar.Events, error) { ctx := context.Background() - secretPath, _ := homedir.Expand(Config.UString("wtf.gcal.secretFile")) + secretPath, _ := homedir.Expand(Config.UString("wtf.mods.gcal.secretFile")) b, err := ioutil.ReadFile(secretPath) if err != nil { @@ -49,7 +49,7 @@ func Fetch() (*calendar.Events, error) { } t := wtf.Today().Format(time.RFC3339) - events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(t).MaxResults(int64(Config.UInt("wtf.gcal.eventCount", 10))).OrderBy("startTime").Do() + events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(t).MaxResults(int64(Config.UInt("wtf.mods.gcal.eventCount", 10))).OrderBy("startTime").Do() if err != nil { return nil, err } diff --git a/gcal/widget.go b/gcal/widget.go index be233898..ed7ede62 100644 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -98,7 +98,7 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string { func (widget *Widget) eventSummary(event *calendar.Event) string { if widget.eventIsNow(event) { - return fmt.Sprintf("%s %s", Config.UString("wtf.gcal.currentIcon", "🔸"), event.Summary) + return fmt.Sprintf("%s %s", Config.UString("wtf.mods.gcal.currentIcon", "🔸"), event.Summary) } return event.Summary diff --git a/git/client.go b/git/client.go index e97b3593..ce9121c5 100644 --- a/git/client.go +++ b/git/client.go @@ -35,7 +35,7 @@ func (client *Client) ChangedFiles() []string { } func (client *Client) Commits() []string { - numStr := fmt.Sprintf("-n %d", Config.UInt("wtf.git.commitCount", 10)) + numStr := fmt.Sprintf("-n %d", Config.UInt("wtf.mods.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...) @@ -57,9 +57,9 @@ func (client *Client) Repository() string { /* -------------------- Exported Functions -------------------- */ func (client *Client) gitDir() string { - return fmt.Sprintf("--git-dir=%s/.git", Config.UString("wtf.git.repository")) + return fmt.Sprintf("--git-dir=%s/.git", Config.UString("wtf.mods.git.repository")) } func (client *Client) workTree() string { - return fmt.Sprintf("--work-tree=%s", Config.UString("wtf.git.repository")) + return fmt.Sprintf("--work-tree=%s", Config.UString("wtf.mods.git.repository")) } diff --git a/github/widget.go b/github/widget.go index 4e9f8ece..8b268fe5 100644 --- a/github/widget.go +++ b/github/widget.go @@ -35,16 +35,16 @@ func (widget *Widget) Refresh() { } client := NewClient() - prs, _ := client.PullRequests(Config.UString("wtf.github.owner"), Config.UString("wtf.github.repo")) + prs, _ := client.PullRequests(Config.UString("wtf.mods.github.owner"), Config.UString("wtf.mods.github.repo")) widget.View.SetTitle(fmt.Sprintf(" Github: %s ", widget.title())) widget.RefreshedAt = time.Now() str := " [red]Open Review Requests[white]\n" - str = str + widget.prsForReview(prs, Config.UString("wtf.github.username")) + str = str + widget.prsForReview(prs, Config.UString("wtf.mods.github.username")) str = str + "\n" str = str + " [red]Open Pull Requests[white]\n" - str = str + widget.openPRs(prs, Config.UString("wtf.github.username")) + str = str + widget.openPRs(prs, Config.UString("wtf.mods.github.username")) widget.View.Clear() fmt.Fprintf(widget.View, str) @@ -109,5 +109,5 @@ func (widget *Widget) openPRs(prs []*ghb.PullRequest, username string) string { } func (widget *Widget) title() string { - return fmt.Sprintf("[green]%s - %s[white]", Config.UString("wtf.github.owner"), Config.UString("wtf.github.repo")) + return fmt.Sprintf("[green]%s - %s[white]", Config.UString("wtf.mods.github.owner"), Config.UString("wtf.mods.github.repo")) } diff --git a/newrelic/client.go b/newrelic/client.go index b3d27c44..c5d3f9a9 100644 --- a/newrelic/client.go +++ b/newrelic/client.go @@ -9,7 +9,7 @@ import ( func Application() (*nr.Application, error) { client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) - application, err := client.GetApplication(Config.UInt("wtf.newrelic.applicationId")) + application, err := client.GetApplication(Config.UInt("wtf.mods.newrelic.applicationId")) if err != nil { return nil, err } @@ -21,7 +21,7 @@ func Deployments() ([]nr.ApplicationDeployment, error) { client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) opts := &nr.ApplicationDeploymentOptions{Page: 1} - deployments, err := client.GetApplicationDeployments(Config.UInt("wtf.newrelic.applicationId"), opts) + deployments, err := client.GetApplicationDeployments(Config.UInt("wtf.mods.newrelic.applicationId"), opts) if err != nil { return nil, err } diff --git a/newrelic/widget.go b/newrelic/widget.go index ba935937..a3f846c9 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -95,7 +95,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revisions = append(revisions, deploy.Revision) - if len(revisions) == Config.UInt("wtf.newrelic.deployCount", 5) { + if len(revisions) == Config.UInt("wtf.mods.newrelic.deployCount", 5) { break } } diff --git a/weather/client.go b/weather/client.go index 935e5db5..c531dd8f 100644 --- a/weather/client.go +++ b/weather/client.go @@ -19,7 +19,7 @@ func Fetch(cityID int) *owm.CurrentWeatherData { /* -------------------- Unexported Functions -------------------- */ func currentWeather(apiKey string, cityCode int) (*owm.CurrentWeatherData, error) { - weather, err := owm.NewCurrent(Config.UString("wtf.weather.tempUnit", "C"), Config.UString("wtf.weather.language", "EN"), apiKey) + weather, err := owm.NewCurrent(Config.UString("wtf.mods.weather.tempUnit", "C"), Config.UString("wtf.mods.weather.language", "EN"), apiKey) if err != nil { return nil, err } diff --git a/weather/widget.go b/weather/widget.go index a6015f55..25edfc0d 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -35,7 +35,7 @@ func (widget *Widget) Refresh() { return } - data := Fetch(Config.UInt("wtf.weather.cityId", 6176823)) + data := Fetch(Config.UInt("wtf.mods.weather.cityId", 6176823)) widget.View.SetTitle(fmt.Sprintf(" %s Weather: [green]%s[white] ", icon(data), data.Name)) widget.RefreshedAt = time.Now() @@ -72,7 +72,7 @@ func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string { str = str + strings.Join(descs, ",") + "\n\n" - tempUnit := Config.UString("wtf.weather.tempUnit", "C") + tempUnit := Config.UString("wtf.mods.weather.tempUnit", "C") str = str + fmt.Sprintf("%8s: %4.1f° %s\n", "High", data.Main.TempMax, tempUnit) str = str + fmt.Sprintf("%8s: [green]%4.1f° %s[white]\n", "Current", data.Main.Temp, tempUnit) diff --git a/wtf/scheduler.go b/wtf/scheduler.go index 3b6795fc..b670a4f5 100644 --- a/wtf/scheduler.go +++ b/wtf/scheduler.go @@ -10,7 +10,13 @@ type Scheduler interface { } func Schedule(widget Scheduler) { - tick := time.NewTicker(time.Duration(widget.RefreshInterval()) * time.Second) + interval := time.Duration(widget.RefreshInterval()) * time.Second + + if interval <= 0 { + return + } + + tick := time.NewTicker(interval) quit := make(chan struct{}) // Kick off the first refresh and then leave the rest to the timer diff --git a/wtf/text_widget.go b/wtf/text_widget.go index eadfbc69..f2fceda7 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -23,14 +23,14 @@ type TextWidget struct { func NewTextWidget(name string, configKey string) TextWidget { widget := TextWidget{ - enabled: Config.UBool(fmt.Sprintf("wtf.%s.enabled", configKey), false), + enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false), Name: name, - RefreshInt: Config.UInt(fmt.Sprintf("wtf.%s.refreshInterval", configKey)), + RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)), Position: Position{ - top: Config.UInt(fmt.Sprintf("wtf.%s.position.top", configKey)), - left: Config.UInt(fmt.Sprintf("wtf.%s.position.left", configKey)), - height: Config.UInt(fmt.Sprintf("wtf.%s.position.height", configKey)), - width: Config.UInt(fmt.Sprintf("wtf.%s.position.width", configKey)), + top: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)), + left: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)), + height: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)), + width: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)), }, }