mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Make jenkins widget interactive
This commit is contained in:
parent
dccf04a27a
commit
d4853f7cfd
@ -17,6 +17,26 @@ Displays jenkins status of given builds in a project or view
|
|||||||
wtf/jenkins/
|
wtf/jenkins/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Keyboard Commands
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `[return]` <br />
|
||||||
|
<span class="caption">Action:</span> Open the selected job in the browser.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `j` <br />
|
||||||
|
<span class="caption">Action:</span> Select the next job in the list.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `k` <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous job in the list.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `r` <br />
|
||||||
|
<span class="caption">Action:</span> Refresh the data.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `↓` <br />
|
||||||
|
<span class="caption">Action:</span> Select the next job in the list.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `↑` <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous job in the list.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
2
docs/index.json
vendored
2
docs/index.json
vendored
@ -200,7 +200,7 @@
|
|||||||
"title": "Jenkins",
|
"title": "Jenkins",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"description": "",
|
"description": "",
|
||||||
"content": " Added in v0.0.8.\nDisplays jenkins status of given builds in a project or view\nSource Code wtf/jenkins/ Configuration jenkins:apiKey:\u0026#34;3276d7155dd9ee27b8b14f8743a408a9\u0026#34;enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:\u0026#34;https://jenkins.domain.com/jenkins/view_url\u0026#34;user:\u0026#34;username\u0026#34;verifyServerCertificate:true Attributes apiKey Value: Your Jenkins API key.\nenabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.\nposition Defines where in the grid this module\u0026rsquo;s widget will be displayed.\nrefreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0..n.\nuser Your Jenkins username. url The url to your Jenkins project or view. Values: A valid URI.\nverifyServerCertificate Optional Determines whether or not the server\u0026rsquo;s certificate chain and host name are verified. Values: true, false.\n"
|
"content": " Added in v0.0.8.\nDisplays jenkins status of given builds in a project or view\nSource Code wtf/jenkins/ Keyboard Commands Key: [return] Action: Open the selected job in the browser.\nKey: j Action: Select the next job in the list.\nKey: k Action: Select the previous job in the list.\nKey: r Action: Refresh the data.\nKey: ↓ Action: Select the next job in the list.\nKey: ↑ Action: Select the previous job in the list.\nConfiguration jenkins:apiKey:\u0026#34;3276d7155dd9ee27b8b14f8743a408a9\u0026#34;enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:\u0026#34;https://jenkins.domain.com/jenkins/view_url\u0026#34;user:\u0026#34;username\u0026#34;verifyServerCertificate:true Attributes apiKey Value: Your Jenkins API key.\nenabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.\nposition Defines where in the grid this module\u0026rsquo;s widget will be displayed.\nrefreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0..n.\nuser Your Jenkins username. url The url to your Jenkins project or view. Values: A valid URI.\nverifyServerCertificate Optional Determines whether or not the server\u0026rsquo;s certificate chain and host name are verified. Values: true, false.\n"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"uri": "https://wtfutil.com/modules/jira/",
|
"uri": "https://wtfutil.com/modules/jira/",
|
||||||
|
10
docs/index.xml
vendored
10
docs/index.xml
vendored
@ -328,10 +328,12 @@ Key: ↑ Action: Select the previous story in the list.</description>
|
|||||||
<guid>https://wtfutil.com/modules/jenkins/</guid>
|
<guid>https://wtfutil.com/modules/jenkins/</guid>
|
||||||
<description>Added in v0.0.8.
|
<description>Added in v0.0.8.
|
||||||
Displays jenkins status of given builds in a project or view
|
Displays jenkins status of given builds in a project or view
|
||||||
Source Code wtf/jenkins/ Configuration jenkins:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:&#34;https://jenkins.domain.com/jenkins/view_url&#34;user:&#34;username&#34;verifyServerCertificate:true Attributes apiKey Value: Your Jenkins API key.
|
Source Code wtf/jenkins/ Keyboard Commands Key: [return] Action: Open the selected job in the browser.
|
||||||
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Key: j Action: Select the next job in the list.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed.
|
Key: k Action: Select the previous job in the list.
|
||||||
refreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0.</description>
|
Key: r Action: Refresh the data.
|
||||||
|
Key: ↓ Action: Select the next job in the list.
|
||||||
|
Key: ↑ Action: Select the previous job in the list.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -178,10 +178,12 @@ Key: ↑ Action: Select the previous story in the list.</description>
|
|||||||
<guid>https://wtfutil.com/modules/jenkins/</guid>
|
<guid>https://wtfutil.com/modules/jenkins/</guid>
|
||||||
<description>Added in v0.0.8.
|
<description>Added in v0.0.8.
|
||||||
Displays jenkins status of given builds in a project or view
|
Displays jenkins status of given builds in a project or view
|
||||||
Source Code wtf/jenkins/ Configuration jenkins:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;enabled:trueposition:top:2left:3height:2width:3refreshInterval:300url:&#34;https://jenkins.domain.com/jenkins/view_url&#34;user:&#34;username&#34;verifyServerCertificate:true Attributes apiKey Value: Your Jenkins API key.
|
Source Code wtf/jenkins/ Keyboard Commands Key: [return] Action: Open the selected job in the browser.
|
||||||
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Key: j Action: Select the next job in the list.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed.
|
Key: k Action: Select the previous job in the list.
|
||||||
refreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0.</description>
|
Key: r Action: Refresh the data.
|
||||||
|
Key: ↓ Action: Select the next job in the list.
|
||||||
|
Key: ↑ Action: Select the previous job in the list.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -480,6 +480,26 @@
|
|||||||
|
|
||||||
<h2 id="source-code">Source Code</h2>
|
<h2 id="source-code">Source Code</h2>
|
||||||
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">wtf/jenkins/</code></pre></div>
|
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">wtf/jenkins/</code></pre></div>
|
||||||
|
<h2 id="keyboard-commands">Keyboard Commands</h2>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>[return]</code> <br />
|
||||||
|
<span class="caption">Action:</span> Open the selected job in the browser.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>j</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the next job in the list.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>k</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous job in the list.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>r</code> <br />
|
||||||
|
<span class="caption">Action:</span> Refresh the data.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>↓</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the next job in the list.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>↑</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous job in the list.</p>
|
||||||
|
|
||||||
<h2 id="configuration">Configuration</h2>
|
<h2 id="configuration">Configuration</h2>
|
||||||
<div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">jenkins<span class="p">:</span><span class="w">
|
<div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">jenkins<span class="p">:</span><span class="w">
|
||||||
</span><span class="w"> </span>apiKey<span class="p">:</span><span class="w"> </span><span class="s2">"3276d7155dd9ee27b8b14f8743a408a9"</span><span class="w">
|
</span><span class="w"> </span>apiKey<span class="p">:</span><span class="w"> </span><span class="s2">"3276d7155dd9ee27b8b14f8743a408a9"</span><span class="w">
|
||||||
|
@ -2,19 +2,48 @@ package jenkins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const HelpText = `
|
||||||
|
Keyboard commands for Jenkins:
|
||||||
|
|
||||||
|
/: Show/hide this help window
|
||||||
|
j: Select the next job in the list
|
||||||
|
k: Select the previous job in the list
|
||||||
|
r: Refresh the data
|
||||||
|
|
||||||
|
arrow down: Select the next job in the list
|
||||||
|
arrow up: Select the previous job in the list
|
||||||
|
|
||||||
|
return: Open the selected job in a browser
|
||||||
|
`
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
view *View
|
||||||
|
selected int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget("Jenkins", "jenkins", false),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
|
TextWidget: wtf.NewTextWidget("Jenkins", "jenkins", true),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
|
widget.unselect()
|
||||||
|
|
||||||
|
widget.View.SetScrollable(true)
|
||||||
|
widget.View.SetRegions(true)
|
||||||
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,25 +59,34 @@ func (widget *Widget) Refresh() {
|
|||||||
wtf.Config.UString("wtf.mods.jenkins.user"),
|
wtf.Config.UString("wtf.mods.jenkins.user"),
|
||||||
widget.apiKey(),
|
widget.apiKey(),
|
||||||
)
|
)
|
||||||
|
widget.view = view
|
||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
|
|
||||||
var content string
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
|
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||||
content = err.Error()
|
widget.View.SetText(err.Error())
|
||||||
} else {
|
|
||||||
widget.View.SetWrap(false)
|
|
||||||
widget.View.SetTitle(fmt.Sprintf(" %s: [green] ", widget.Name))
|
|
||||||
content = widget.contentFrom(view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetText(content)
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) display() {
|
||||||
|
if widget.view == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.View.SetWrap(false)
|
||||||
|
|
||||||
|
widget.View.Clear()
|
||||||
|
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s: [red]%s", widget.Name, widget.view.Name)))
|
||||||
|
widget.View.SetText(widget.contentFrom(widget.view))
|
||||||
|
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) apiKey() string {
|
func (widget *Widget) apiKey() string {
|
||||||
return wtf.Config.UString(
|
return wtf.Config.UString(
|
||||||
"wtf.mods.jenkins.apiKey",
|
"wtf.mods.jenkins.apiKey",
|
||||||
@ -57,19 +95,30 @@ func (widget *Widget) apiKey() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(view *View) string {
|
func (widget *Widget) contentFrom(view *View) string {
|
||||||
str := fmt.Sprintf(" [red]%s[white]\n", view.Name)
|
var str string
|
||||||
|
for idx, job := range view.Jobs {
|
||||||
for _, job := range view.Jobs {
|
|
||||||
str = str + fmt.Sprintf(
|
str = str + fmt.Sprintf(
|
||||||
" [%s]%-6s[white]\n",
|
`["%d"][""][%s] [%s]%-6s[white]`,
|
||||||
|
idx,
|
||||||
|
widget.rowColor(idx),
|
||||||
widget.jobColor(&job),
|
widget.jobColor(&job),
|
||||||
job.Name,
|
job.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
str = str + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) rowColor(idx int) string {
|
||||||
|
if widget.View.HasFocus() && (idx == widget.selected) {
|
||||||
|
return wtf.DefaultFocussedRowColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
return wtf.DefaultRowColor()
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) jobColor(job *Job) string {
|
func (widget *Widget) jobColor(job *Job) string {
|
||||||
switch job.Color {
|
switch job.Color {
|
||||||
case "blue":
|
case "blue":
|
||||||
@ -80,3 +129,67 @@ func (widget *Widget) jobColor(job *Job) string {
|
|||||||
return "white"
|
return "white"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) next() {
|
||||||
|
widget.selected++
|
||||||
|
if widget.view != nil && widget.selected >= len(widget.view.Jobs) {
|
||||||
|
widget.selected = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) prev() {
|
||||||
|
widget.selected--
|
||||||
|
if widget.selected < 0 && widget.view != nil {
|
||||||
|
widget.selected = len(widget.view.Jobs) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) openJob() {
|
||||||
|
sel := widget.selected
|
||||||
|
if sel >= 0 && widget.view != nil && sel < len(widget.view.Jobs) {
|
||||||
|
job := &widget.view.Jobs[widget.selected]
|
||||||
|
wtf.OpenFile(job.Url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) unselect() {
|
||||||
|
widget.selected = -1
|
||||||
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
switch string(event.Rune()) {
|
||||||
|
case "/":
|
||||||
|
widget.ShowHelp()
|
||||||
|
case "j":
|
||||||
|
widget.next()
|
||||||
|
return nil
|
||||||
|
case "k":
|
||||||
|
widget.prev()
|
||||||
|
return nil
|
||||||
|
case "r":
|
||||||
|
widget.Refresh()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch event.Key() {
|
||||||
|
case tcell.KeyDown:
|
||||||
|
widget.next()
|
||||||
|
return nil
|
||||||
|
case tcell.KeyEnter:
|
||||||
|
widget.openJob()
|
||||||
|
return nil
|
||||||
|
case tcell.KeyEsc:
|
||||||
|
widget.unselect()
|
||||||
|
return event
|
||||||
|
case tcell.KeyUp:
|
||||||
|
widget.prev()
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2
main.go
2
main.go
@ -219,7 +219,7 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) {
|
|||||||
case "ipinfo":
|
case "ipinfo":
|
||||||
widgets = append(widgets, ipinfo.NewWidget())
|
widgets = append(widgets, ipinfo.NewWidget())
|
||||||
case "jenkins":
|
case "jenkins":
|
||||||
widgets = append(widgets, jenkins.NewWidget())
|
widgets = append(widgets, jenkins.NewWidget(app, pages))
|
||||||
case "jira":
|
case "jira":
|
||||||
widgets = append(widgets, jira.NewWidget(app, pages))
|
widgets = append(widgets, jira.NewWidget(app, pages))
|
||||||
case "logger":
|
case "logger":
|
||||||
|
@ -113,6 +113,13 @@ func RightAlignFormat(view *tview.TextView) string {
|
|||||||
return fmt.Sprintf("%%%ds", w-1)
|
return fmt.Sprintf("%%%ds", w-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultRowColor() string {
|
||||||
|
foreColor := Config.UString("wtf.colors.foreground", "white")
|
||||||
|
backColor := Config.UString("wtf.colors.background", "black")
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||||
|
}
|
||||||
|
|
||||||
func DefaultFocussedRowColor() string {
|
func DefaultFocussedRowColor() string {
|
||||||
foreColor := Config.UString("wtf.colors.highlight.fore", "black")
|
foreColor := Config.UString("wtf.colors.highlight.fore", "black")
|
||||||
backColor := Config.UString("wtf.colors.highlight.back", "orange")
|
backColor := Config.UString("wtf.colors.highlight.back", "orange")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user