diff --git a/_site/content/posts/modules/jenkins.md b/_site/content/posts/modules/jenkins.md new file mode 100644 index 00000000..c556998e --- /dev/null +++ b/_site/content/posts/modules/jenkins.md @@ -0,0 +1,63 @@ +--- +title: "Modules: Jenkins" +date: 2018-06-09T20:53:35-07:00 +draft: false +--- + +Added in `v0.0.8`. + +Displays jenkins status of given builds in a project or view + +jenkins screenshot + +## Source Code + +```bash +wtf/jenkins/ +``` + +## Required ENV Variables + +Key: `WTF_JENKINS_API_KEY`
+Value: Your Jenkins API key. + +## Keyboard Commands + +None. + +## Configuration + +```yaml +jenkins: + enabled: true + position: + top: 2 + left: 3 + height: 2 + width: 3 + refreshInterval: 300 + url: "https://jenkins.domain.com/jenkins/view_url" + user: "username" +``` + +### Attributes + +`enabled`
+Determines whether or not this module is executed and if its data displayed onscreen.
+Values: `true`, `false`. + +`position`
+Defines where in the grid this module's widget will be displayed. + +`refreshInterval`
+How often, in seconds, this module will update its data.
+Values: A positive integer, `0..n`. + +`user`
+Your Jenkins username.
+ +`url`
+The url to your Jenkins project or view.
+Values: A valid URI. + diff --git a/_site/static/imgs/modules/jenkins.png b/_site/static/imgs/modules/jenkins.png new file mode 100644 index 00000000..5074eca1 Binary files /dev/null and b/_site/static/imgs/modules/jenkins.png differ diff --git a/_site/themes/hyde-hyde/layouts/partials/sidebar.html b/_site/themes/hyde-hyde/layouts/partials/sidebar.html index e8358071..6379bf87 100644 --- a/_site/themes/hyde-hyde/layouts/partials/sidebar.html +++ b/_site/themes/hyde-hyde/layouts/partials/sidebar.html @@ -35,6 +35,7 @@ + diff --git a/docs/404.html b/docs/404.html index 9c8dab86..34799494 100644 --- a/docs/404.html +++ b/docs/404.html @@ -76,6 +76,7 @@ + diff --git a/docs/categories/index.html b/docs/categories/index.html index 52c703bd..1cfe3602 100644 --- a/docs/categories/index.html +++ b/docs/categories/index.html @@ -78,6 +78,7 @@ + diff --git a/docs/imgs/modules/jenkins.png b/docs/imgs/modules/jenkins.png new file mode 100644 index 00000000..5074eca1 Binary files /dev/null and b/docs/imgs/modules/jenkins.png differ diff --git a/docs/index.html b/docs/index.html index 23c7b3ba..a3633563 100644 --- a/docs/index.html +++ b/docs/index.html @@ -77,6 +77,7 @@ + diff --git a/docs/index.xml b/docs/index.xml index df581d78..b1b99da1 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -56,6 +56,21 @@ cells.names cells.addresses enabled Whether or not this module is executed and i position Where in the grid this module’s widget will be displayed. + + Modules: Jenkins + https://wtfutil.com/posts/modules/jenkins/ + Sat, 09 Jun 2018 20:53:35 -0700 + + https://wtfutil.com/posts/modules/jenkins/ + Added in v0.0.8. +Displays jenkins status of given builds in a project or view +Source Code wtf/jenkins/ Required ENV Variables Key: WTF_JENKINS_API_KEY Value: Your Jenkins API key. +Keyboard Commands None. +Configuration jenkins:enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:"https://jenkins.domain.com/jenkins/view_url"user:"username" Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false. +position Defines where in the grid this module’s widget will be displayed. +refreshInterval How often, in seconds, this module will update its data. + + Gitlab https://wtfutil.com/posts/modules/gitlab/ diff --git a/docs/posts/configuration/attributes/index.html b/docs/posts/configuration/attributes/index.html index a6c2c728..cd9e2280 100644 --- a/docs/posts/configuration/attributes/index.html +++ b/docs/posts/configuration/attributes/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/configuration/index.html b/docs/posts/configuration/index.html index f72b1014..5c1f870d 100644 --- a/docs/posts/configuration/index.html +++ b/docs/posts/configuration/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/configuration/iterm2/index.html b/docs/posts/configuration/iterm2/index.html index b74a8c57..883a77a1 100644 --- a/docs/posts/configuration/iterm2/index.html +++ b/docs/posts/configuration/iterm2/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/glossary/index.html b/docs/posts/glossary/index.html index 6af86c99..7bdf108b 100644 --- a/docs/posts/glossary/index.html +++ b/docs/posts/glossary/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/index.html b/docs/posts/index.html index f0330de5..bd8fb7f0 100644 --- a/docs/posts/index.html +++ b/docs/posts/index.html @@ -78,6 +78,7 @@ + @@ -122,6 +123,13 @@ + +
  • + + Modules: Jenkins + + +
  • diff --git a/docs/posts/index.xml b/docs/posts/index.xml index 0ecc040d..e83b1289 100644 --- a/docs/posts/index.xml +++ b/docs/posts/index.xml @@ -56,6 +56,21 @@ cells.names cells.addresses enabled Whether or not this module is executed and i position Where in the grid this module’s widget will be displayed. + + Modules: Jenkins + https://wtfutil.com/posts/modules/jenkins/ + Sat, 09 Jun 2018 20:53:35 -0700 + + https://wtfutil.com/posts/modules/jenkins/ + Added in v0.0.8. +Displays jenkins status of given builds in a project or view +Source Code wtf/jenkins/ Required ENV Variables Key: WTF_JENKINS_API_KEY Value: Your Jenkins API key. +Keyboard Commands None. +Configuration jenkins:enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:"https://jenkins.domain.com/jenkins/view_url"user:"username" Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false. +position Defines where in the grid this module’s widget will be displayed. +refreshInterval How often, in seconds, this module will update its data. + + Gitlab https://wtfutil.com/posts/modules/gitlab/ diff --git a/docs/posts/installation/index.html b/docs/posts/installation/index.html index 6e077b0a..680b39a0 100644 --- a/docs/posts/installation/index.html +++ b/docs/posts/installation/index.html @@ -76,6 +76,7 @@
  • + diff --git a/docs/posts/modules/bamboohr/index.html b/docs/posts/modules/bamboohr/index.html index 72d55e24..0cea882b 100644 --- a/docs/posts/modules/bamboohr/index.html +++ b/docs/posts/modules/bamboohr/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/circleci/index.html b/docs/posts/modules/circleci/index.html index be92bead..b9e0690a 100644 --- a/docs/posts/modules/circleci/index.html +++ b/docs/posts/modules/circleci/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/clocks/index.html b/docs/posts/modules/clocks/index.html index 39870f33..26d11768 100644 --- a/docs/posts/modules/clocks/index.html +++ b/docs/posts/modules/clocks/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/cmdrunner/index.html b/docs/posts/modules/cmdrunner/index.html index d146dc78..c4242623 100644 --- a/docs/posts/modules/cmdrunner/index.html +++ b/docs/posts/modules/cmdrunner/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/cryptocurrencies/bittrex/index.html b/docs/posts/modules/cryptocurrencies/bittrex/index.html index 9a4b90da..8f126198 100644 --- a/docs/posts/modules/cryptocurrencies/bittrex/index.html +++ b/docs/posts/modules/cryptocurrencies/bittrex/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/cryptocurrencies/cryptolive/index.html b/docs/posts/modules/cryptocurrencies/cryptolive/index.html index 7e9776ca..67108e87 100644 --- a/docs/posts/modules/cryptocurrencies/cryptolive/index.html +++ b/docs/posts/modules/cryptocurrencies/cryptolive/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/gcal/index.html b/docs/posts/modules/gcal/index.html index e145f5a2..29823703 100644 --- a/docs/posts/modules/gcal/index.html +++ b/docs/posts/modules/gcal/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/git/index.html b/docs/posts/modules/git/index.html index 84503c00..cc166eed 100644 --- a/docs/posts/modules/git/index.html +++ b/docs/posts/modules/git/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/github/index.html b/docs/posts/modules/github/index.html index 993eebfa..43de01e6 100644 --- a/docs/posts/modules/github/index.html +++ b/docs/posts/modules/github/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/gitlab/index.html b/docs/posts/modules/gitlab/index.html index 096390ec..048e11a2 100644 --- a/docs/posts/modules/gitlab/index.html +++ b/docs/posts/modules/gitlab/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/gspreadsheet/index.html b/docs/posts/modules/gspreadsheet/index.html index c63af76c..235186c3 100644 --- a/docs/posts/modules/gspreadsheet/index.html +++ b/docs/posts/modules/gspreadsheet/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/index.html b/docs/posts/modules/index.html index 8e30d931..525d9991 100644 --- a/docs/posts/modules/index.html +++ b/docs/posts/modules/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/ipapi/index.html b/docs/posts/modules/ipapi/index.html index ed349da0..f768e9d9 100644 --- a/docs/posts/modules/ipapi/index.html +++ b/docs/posts/modules/ipapi/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/ipinfo/index.html b/docs/posts/modules/ipinfo/index.html index b13c8c60..fd8393a7 100644 --- a/docs/posts/modules/ipinfo/index.html +++ b/docs/posts/modules/ipinfo/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/jenkins/index.html b/docs/posts/modules/jenkins/index.html new file mode 100644 index 00000000..5b3bb5f9 --- /dev/null +++ b/docs/posts/modules/jenkins/index.html @@ -0,0 +1,181 @@ + + + + + + + + + + + + +Modules: Jenkins | WTF - A Terminal Dashboard + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +

    Modules: Jenkins

    + +
    + +
    + + + +

    Added in v0.0.8.

    + +

    Displays jenkins status of given builds in a project or view

    + +

    jenkins screenshot

    + +

    Source Code

    +
    wtf/jenkins/
    +

    Required ENV Variables

    + +

    Key: WTF_JENKINS_API_KEY
    +Value: Your Jenkins API key.

    + +

    Keyboard Commands

    + +

    None.

    + +

    Configuration

    +
    jenkins:
    +  enabled: true
    +  position:
    +    top: 2
    +    left: 3
    +    height: 2
    +    width: 3
    +  refreshInterval: 300
    +  url: "https://jenkins.domain.com/jenkins/view_url"
    +  user: "username"
    +

    Attributes

    + +

    enabled
    +Determines whether or not this module is executed and if its data displayed onscreen.
    +Values: true, false.

    + +

    position
    +Defines where in the grid this module’s widget will be displayed.

    + +

    refreshInterval
    +How often, in seconds, this module will update its data.
    +Values: A positive integer, 0..n.

    + +

    user
    +Your Jenkins username.

    + +

    url
    +The url to your Jenkins project or view.
    +Values: A valid URI.

    + +
    + + +
    + + + + diff --git a/docs/posts/modules/jira/index.html b/docs/posts/modules/jira/index.html index 84d8a680..cece665e 100644 --- a/docs/posts/modules/jira/index.html +++ b/docs/posts/modules/jira/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/newrelic/index.html b/docs/posts/modules/newrelic/index.html index 49fb2bf0..8b333652 100644 --- a/docs/posts/modules/newrelic/index.html +++ b/docs/posts/modules/newrelic/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/opsgenie/index.html b/docs/posts/modules/opsgenie/index.html index 242e200f..58db2554 100644 --- a/docs/posts/modules/opsgenie/index.html +++ b/docs/posts/modules/opsgenie/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/power/index.html b/docs/posts/modules/power/index.html index 36eeceee..9523486b 100644 --- a/docs/posts/modules/power/index.html +++ b/docs/posts/modules/power/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/prettyweather/index.html b/docs/posts/modules/prettyweather/index.html index 4a20f1a5..995cf7be 100644 --- a/docs/posts/modules/prettyweather/index.html +++ b/docs/posts/modules/prettyweather/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/security/index.html b/docs/posts/modules/security/index.html index 8139a7ca..d2bd19ef 100644 --- a/docs/posts/modules/security/index.html +++ b/docs/posts/modules/security/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/textfile/index.html b/docs/posts/modules/textfile/index.html index 2720af7d..bfb11fc1 100644 --- a/docs/posts/modules/textfile/index.html +++ b/docs/posts/modules/textfile/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/todo/index.html b/docs/posts/modules/todo/index.html index 02d67c70..d67881e8 100644 --- a/docs/posts/modules/todo/index.html +++ b/docs/posts/modules/todo/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/modules/weather/index.html b/docs/posts/modules/weather/index.html index 5142c248..78a449ee 100644 --- a/docs/posts/modules/weather/index.html +++ b/docs/posts/modules/weather/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/posts/overview/index.html b/docs/posts/overview/index.html index 6b68ea81..0cd74e6d 100644 --- a/docs/posts/overview/index.html +++ b/docs/posts/overview/index.html @@ -76,6 +76,7 @@ + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 8200ef65..577c3a23 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -17,6 +17,11 @@ 2018-06-10T18:26:26-04:00 + + https://wtfutil.com/posts/modules/jenkins/ + 2018-06-09T20:53:35-07:00 + + https://wtfutil.com/posts/modules/gitlab/ 2018-06-08T13:14:11-07:00 diff --git a/docs/tags/index.html b/docs/tags/index.html index 87abb6ad..04a1ff12 100644 --- a/docs/tags/index.html +++ b/docs/tags/index.html @@ -78,6 +78,7 @@ + diff --git a/jenkins/client.go b/jenkins/client.go new file mode 100644 index 00000000..e599b9f7 --- /dev/null +++ b/jenkins/client.go @@ -0,0 +1,64 @@ +package jenkins + +import ( + "bytes" + "encoding/json" + "io" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +func Create(jenkinsURL string, username string, apiKey string) (*View, error) { + const apiSuffix = "api/json?pretty=true" + parsedSuffix, err := url.Parse(apiSuffix) + if err != nil { + return &View{}, err + } + + parsedJenkinsURL, err := url.Parse(ensureLastSlash(jenkinsURL)) + if err != nil { + return &View{}, err + } + jenkinsAPIURL := parsedJenkinsURL.ResolveReference(parsedSuffix) + + req, err := http.NewRequest("GET", jenkinsAPIURL.String(), nil) + req.SetBasicAuth(username, apiKey) + + httpClient := &http.Client{} + resp, err := httpClient.Do(req) + + if err != nil { + return &View{}, err + } + + view := &View{} + parseJson(view, resp.Body) + + return view, nil +} + +func ensureLastSlash(URL string) string { + return strings.TrimRight(URL, "/") + "/" +} + +/* -------------------- Unexported Functions -------------------- */ + + +func parseJson(obj interface{}, text io.Reader) { + jsonStream, err := ioutil.ReadAll(text) + if err != nil { + panic(err) + } + + decoder := json.NewDecoder(bytes.NewReader(jsonStream)) + + for { + if err := decoder.Decode(obj); err == io.EOF { + break + } else if err != nil { + panic(err) + } + } +} diff --git a/jenkins/job.go b/jenkins/job.go new file mode 100644 index 00000000..e360e0f6 --- /dev/null +++ b/jenkins/job.go @@ -0,0 +1,8 @@ +package jenkins + +type Job struct { + Class string `json:"_class"` + Name string `json:"name"` + Url string `json:"url"` + Color string `json:"color"` +} diff --git a/jenkins/view.go b/jenkins/view.go new file mode 100644 index 00000000..9041b297 --- /dev/null +++ b/jenkins/view.go @@ -0,0 +1,10 @@ +package jenkins + +type View struct { + Class string `json:"_class"` + Description string `json:"description"` + Jobs []Job `json:"jobs"` + Name string `json:"name"` + Property []string `json:"property"` + url string `json:"url"` +} diff --git a/jenkins/widget.go b/jenkins/widget.go new file mode 100644 index 00000000..a922fbbf --- /dev/null +++ b/jenkins/widget.go @@ -0,0 +1,83 @@ +package jenkins + +import ( + "fmt" + "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/wtf" + "os" +) + +// Config is a pointer to the global config object +var Config *config.Config + +type Widget struct { + wtf.TextWidget +} + +func NewWidget() *Widget { + widget := Widget{ + TextWidget: wtf.NewTextWidget("Jenkins", "jenkins", false), + } + + return &widget +} + +/* -------------------- Exported Functions -------------------- */ + +func (widget *Widget) Refresh() { + if widget.Disabled() { + return + } + + view, err := Create(Config.UString("wtf.mods.jenkins.url"), + Config.UString("wtf.mods.jenkins.user"), os.Getenv("WTF_JENKINS_API_KEY")) + + widget.UpdateRefreshedAt() + widget.View.Clear() + + if err != nil { + widget.View.SetWrap(true) + widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) + fmt.Fprintf(widget.View, "%v", err) + } else { + widget.View.SetWrap(false) + widget.View.SetTitle( + fmt.Sprintf( + " %s: [green] ", + widget.Name, + ), + ) + fmt.Fprintf(widget.View, "%s", widget.contentFrom(view)) + } +} + +/* -------------------- Unexported Functions -------------------- */ + +func (widget *Widget) contentFrom(view *View) string { + str := fmt.Sprintf(" [red]%s[white]\n", view.Name); + + for _, job := range view.Jobs { + str = str + fmt.Sprintf( + " [%s]%-6s[white]\n", + widget.jobColor(&job), + job.Name, + ) + } + + return str +} + +func (widget *Widget) jobColor(job *Job) string { + var color string + + switch job.Color { + case "blue": + color = "green" + case "red": + color = "red" + default: + color = "white" + } + + return color +} diff --git a/wtf.go b/wtf.go index d50e78d3..3f2f6ea1 100644 --- a/wtf.go +++ b/wtf.go @@ -26,6 +26,7 @@ import ( "github.com/senorprogrammer/wtf/help" "github.com/senorprogrammer/wtf/ipapi" "github.com/senorprogrammer/wtf/ipinfo" + "github.com/senorprogrammer/wtf/jenkins" "github.com/senorprogrammer/wtf/jira" "github.com/senorprogrammer/wtf/newrelic" "github.com/senorprogrammer/wtf/opsgenie" @@ -195,11 +196,13 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { case "gitlab": Widgets = append(Widgets, gitlab.NewWidget(app, pages)) case "gspreadsheets": - Widgets = append(Widgets, gspreadsheets.NewWidget()) + Widgets = append(Widgets, gspreadsheets.NewWidget()) + case "ipapi": + Widgets = append(Widgets, ipapi.NewWidget()) case "ipinfo": Widgets = append(Widgets, ipinfo.NewWidget()) - case "ipapi": - Widgets = append(Widgets, ipapi.NewWidget()) + case "jenkins": + Widgets = append(Widgets, jenkins.NewWidget()) case "jira": Widgets = append(Widgets, jira.NewWidget()) case "newrelic": @@ -244,6 +247,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { gspreadsheets.Config = Config ipapi.Config = Config ipinfo.Config = Config + jenkins.Config = Config jira.Config = Config newrelic.Config = Config opsgenie.Config = Config