mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fix merge conflict with constants in TravisCI client
This commit is contained in:
commit
b93952bfb5
@ -18,7 +18,23 @@ wtf/travisci/
|
|||||||
|
|
||||||
## Keyboard Commands
|
## Keyboard Commands
|
||||||
|
|
||||||
None.
|
<span class="caption">Key:</span> `[return]` <br />
|
||||||
|
<span class="caption">Action:</span> Open the selected build in the browser.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `j` <br />
|
||||||
|
<span class="caption">Action:</span> Select the next build in the list.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `k` <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous build 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 build in the list.
|
||||||
|
|
||||||
|
<span class="caption">Key:</span> `↑` <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous build in the list.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -50,10 +50,12 @@ Configuration zendesk:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;e
|
|||||||
<guid>https://wtfutil.com/posts/modules/travisci/</guid>
|
<guid>https://wtfutil.com/posts/modules/travisci/</guid>
|
||||||
<description>Added in v0.0.12.
|
<description>Added in v0.0.12.
|
||||||
Displays build information for your Travis CI account.
|
Displays build information for your Travis CI account.
|
||||||
Source Code wtf/travisci/ Keyboard Commands None.
|
Source Code wtf/travisci/ Keyboard Commands Key: [return] Action: Open the selected build in the browser.
|
||||||
Configuration travisci:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;enabled:trueposition:top:4left:1height:1width:2pro:falserefreshInterval:900 Attributes apiKey Value: Your Travis CI API access token.
|
Key: j Action: Select the next build in the list.
|
||||||
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Key: k Action: Select the previous build in the list.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed. 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 build in the list.
|
||||||
|
Key: ↑ Action: Select the previous build in the list.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -50,10 +50,12 @@ Configuration zendesk:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;e
|
|||||||
<guid>https://wtfutil.com/posts/modules/travisci/</guid>
|
<guid>https://wtfutil.com/posts/modules/travisci/</guid>
|
||||||
<description>Added in v0.0.12.
|
<description>Added in v0.0.12.
|
||||||
Displays build information for your Travis CI account.
|
Displays build information for your Travis CI account.
|
||||||
Source Code wtf/travisci/ Keyboard Commands None.
|
Source Code wtf/travisci/ Keyboard Commands Key: [return] Action: Open the selected build in the browser.
|
||||||
Configuration travisci:apiKey:&#34;3276d7155dd9ee27b8b14f8743a408a9&#34;enabled:trueposition:top:4left:1height:1width:2pro:falserefreshInterval:900 Attributes apiKey Value: Your Travis CI API access token.
|
Key: j Action: Select the next build in the list.
|
||||||
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Key: k Action: Select the previous build in the list.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed. 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 build in the list.
|
||||||
|
Key: ↑ Action: Select the previous build in the list.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -147,7 +147,23 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
|||||||
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">wtf/travisci/</code></pre></div>
|
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">wtf/travisci/</code></pre></div>
|
||||||
<h2 id="keyboard-commands">Keyboard Commands</h2>
|
<h2 id="keyboard-commands">Keyboard Commands</h2>
|
||||||
|
|
||||||
<p>None.</p>
|
<p><span class="caption">Key:</span> <code>[return]</code> <br />
|
||||||
|
<span class="caption">Action:</span> Open the selected build in the browser.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>j</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the next build in the list.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>k</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous build 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 build in the list.</p>
|
||||||
|
|
||||||
|
<p><span class="caption">Key:</span> <code>↑</code> <br />
|
||||||
|
<span class="caption">Action:</span> Select the previous build 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">travisci<span class="p">:</span><span class="w">
|
<div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">travisci<span class="p">:</span><span class="w">
|
||||||
|
@ -66,10 +66,7 @@ func (widget *Widget) displayStats(project *GerritProject) string {
|
|||||||
|
|
||||||
func (widget *Widget) rowColor(index int) string {
|
func (widget *Widget) rowColor(index int) string {
|
||||||
if widget.View.HasFocus() && (index == widget.selected) {
|
if widget.View.HasFocus() && (index == widget.selected) {
|
||||||
foreColor := wtf.Config.UString("wtf.colors.highlight.fore", "black")
|
return wtf.DefaultFocussedRowColor()
|
||||||
backColor := wtf.Config.UString("wtf.colors.highlight.back", "orange")
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
|
||||||
}
|
}
|
||||||
return wtf.RowColor("gerrit", index)
|
return wtf.RowColor("gerrit", index)
|
||||||
}
|
}
|
||||||
|
@ -130,10 +130,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|||||||
|
|
||||||
func (widget *Widget) rowColor(idx int) string {
|
func (widget *Widget) rowColor(idx int) string {
|
||||||
if widget.View.HasFocus() && (idx == widget.selected) {
|
if widget.View.HasFocus() && (idx == widget.selected) {
|
||||||
foreColor := wtf.Config.UString("wtf.colors.highlight.fore", "black")
|
return wtf.DefaultFocussedRowColor()
|
||||||
backColor := wtf.Config.UString("wtf.colors.highlight.back", "orange")
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
|
||||||
}
|
}
|
||||||
return wtf.RowColor("jira", idx)
|
return wtf.RowColor("jira", idx)
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@ -235,7 +235,7 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) {
|
|||||||
case "todoist":
|
case "todoist":
|
||||||
widgets = append(widgets, todoist.NewWidget(app, pages))
|
widgets = append(widgets, todoist.NewWidget(app, pages))
|
||||||
case "travisci":
|
case "travisci":
|
||||||
widgets = append(widgets, travisci.NewWidget())
|
widgets = append(widgets, travisci.NewWidget(app, pages))
|
||||||
case "trello":
|
case "trello":
|
||||||
widgets = append(widgets, trello.NewWidget())
|
widgets = append(widgets, trello.NewWidget())
|
||||||
case "twitter":
|
case "twitter":
|
||||||
|
@ -13,11 +13,16 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var TRAVIS_HOSTS = map[bool]string{
|
||||||
|
false: "travis-ci.org",
|
||||||
|
true: "travis-ci.com",
|
||||||
|
}
|
||||||
|
|
||||||
func BuildsFor() (*Builds, error) {
|
func BuildsFor() (*Builds, error) {
|
||||||
builds := &Builds{}
|
builds := &Builds{}
|
||||||
|
|
||||||
pro := wtf.Config.UBool("wtf.mods.travisci.pro", false)
|
pro := wtf.Config.UBool("wtf.mods.travisci.pro", false)
|
||||||
travisAPIURL.Host = hosts[pro]
|
travisAPIURL.Host = "api." + TRAVIS_HOSTS[pro]
|
||||||
|
|
||||||
resp, err := travisRequest("builds")
|
resp, err := travisRequest("builds")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,19 +38,15 @@ func BuildsFor() (*Builds, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
||||||
hosts = map[bool]string{
|
|
||||||
false: "api.travis-ci.org",
|
|
||||||
true: "api.travis-ci.com",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func travisRequest(path string) (*http.Response, error) {
|
func travisRequest(path string) (*http.Response, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("limit", "10")
|
params.Add("limit", "10")
|
||||||
|
|
||||||
url := travisAPIURL.ResolveReference(&url.URL{Path: path, RawQuery: params.Encode()})
|
requestUrl := travisAPIURL.ResolveReference(&url.URL{Path: path, RawQuery: params.Encode()})
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url.String(), nil)
|
req, err := http.NewRequest("GET", requestUrl.String(), nil)
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
req.Header.Add("Travis-API-Version", "3")
|
req.Header.Add("Travis-API-Version", "3")
|
||||||
|
@ -5,10 +5,12 @@ type Builds struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Build struct {
|
type Build struct {
|
||||||
|
ID int `json:"id"`
|
||||||
CreatedBy Owner `json:"created_by"`
|
CreatedBy Owner `json:"created_by"`
|
||||||
Branch Branch `json:"branch"`
|
Branch Branch `json:"branch"`
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
Repository Repository `json:"repository"`
|
Repository Repository `json:"repository"`
|
||||||
|
Commit Commit `json:"commit"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,4 +24,9 @@ type Branch struct {
|
|||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Commit struct {
|
||||||
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,45 @@ package travisci
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const HelpText = `
|
||||||
|
Keyboard commands for Travis CI:
|
||||||
|
|
||||||
|
/: Show/hide this help window
|
||||||
|
j: Select the next build in the list
|
||||||
|
k: Select the previous build in the list
|
||||||
|
r: Refresh the data
|
||||||
|
|
||||||
|
arrow down: Select the next build in the list
|
||||||
|
arrow up: Select the previous build in the list
|
||||||
|
|
||||||
|
return: Open the selected build in a browser
|
||||||
|
`
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
builds *Builds
|
||||||
|
selected int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget("TravisCI", "travisci", false),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
|
TextWidget: wtf.NewTextWidget("TravisCI", "travisci", true),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
|
widget.unselect()
|
||||||
|
|
||||||
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,31 +55,43 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
|
|
||||||
widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name))
|
|
||||||
|
|
||||||
var content string
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
content = err.Error()
|
widget.View.SetTitle(widget.Name)
|
||||||
|
widget.View.SetText(err.Error())
|
||||||
} else {
|
} else {
|
||||||
widget.View.SetWrap(false)
|
widget.builds = builds
|
||||||
content = widget.contentFrom(builds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetText(content)
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) display() {
|
||||||
|
if widget.builds == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.View.SetWrap(false)
|
||||||
|
|
||||||
|
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - Builds", widget.Name)))
|
||||||
|
widget.View.SetText(widget.contentFrom(widget.builds))
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(builds *Builds) string {
|
func (widget *Widget) contentFrom(builds *Builds) string {
|
||||||
var str string
|
var str string
|
||||||
for _, build := range builds.Builds {
|
for idx, build := range builds.Builds {
|
||||||
|
|
||||||
str = str + fmt.Sprintf(
|
str = str + fmt.Sprintf(
|
||||||
"[%s] %s-%s (%s) [white]%s\n",
|
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
||||||
|
widget.rowColor(idx),
|
||||||
buildColor(&build),
|
buildColor(&build),
|
||||||
build.Repository.Name,
|
build.Repository.Name,
|
||||||
build.Number,
|
build.Number,
|
||||||
build.Branch.Name,
|
build.Branch.Name,
|
||||||
|
widget.rowColor(idx),
|
||||||
|
strings.Split(build.Commit.Message, "\n")[0],
|
||||||
build.CreatedBy.Login,
|
build.CreatedBy.Login,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -60,6 +99,13 @@ func (widget *Widget) contentFrom(builds *Builds) string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) rowColor(idx int) string {
|
||||||
|
if widget.View.HasFocus() && (idx == widget.selected) {
|
||||||
|
return wtf.DefaultFocussedRowColor()
|
||||||
|
}
|
||||||
|
return "White"
|
||||||
|
}
|
||||||
|
|
||||||
func buildColor(build *Build) string {
|
func buildColor(build *Build) string {
|
||||||
switch build.State {
|
switch build.State {
|
||||||
case "broken":
|
case "broken":
|
||||||
@ -80,3 +126,69 @@ func buildColor(build *Build) string {
|
|||||||
return "white"
|
return "white"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) next() {
|
||||||
|
widget.selected++
|
||||||
|
if widget.builds != nil && widget.selected >= len(widget.builds.Builds) {
|
||||||
|
widget.selected = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) prev() {
|
||||||
|
widget.selected--
|
||||||
|
if widget.selected < 0 && widget.builds != nil {
|
||||||
|
widget.selected = len(widget.builds.Builds) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) openBuild() {
|
||||||
|
sel := widget.selected
|
||||||
|
if sel >= 0 && widget.builds != nil && sel < len(widget.builds.Builds) {
|
||||||
|
build := &widget.builds.Builds[widget.selected]
|
||||||
|
travisHost := TRAVIS_HOSTS[wtf.Config.UBool("wtf.mods.travisci.pro", false)]
|
||||||
|
wtf.OpenFile(fmt.Sprintf("https://%s/%s/%s/%d", travisHost, build.Repository.Slug, "builds", build.ID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.openBuild()
|
||||||
|
return nil
|
||||||
|
case tcell.KeyEsc:
|
||||||
|
widget.unselect()
|
||||||
|
return event
|
||||||
|
case tcell.KeyUp:
|
||||||
|
widget.prev()
|
||||||
|
widget.display()
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -113,6 +113,13 @@ func RightAlignFormat(view *tview.TextView) string {
|
|||||||
return fmt.Sprintf("%%%ds", w-1)
|
return fmt.Sprintf("%%%ds", w-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultFocussedRowColor() string {
|
||||||
|
foreColor := Config.UString("wtf.colors.highlight.fore", "black")
|
||||||
|
backColor := Config.UString("wtf.colors.highlight.back", "orange")
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||||
|
}
|
||||||
|
|
||||||
func RowColor(module string, idx int) string {
|
func RowColor(module string, idx int) string {
|
||||||
evenKey := fmt.Sprintf("wtf.mods.%s.colors.row.even", module)
|
evenKey := fmt.Sprintf("wtf.mods.%s.colors.row.even", module)
|
||||||
oddKey := fmt.Sprintf("wtf.mods.%s.colors.row.odd", module)
|
oddKey := fmt.Sprintf("wtf.mods.%s.colors.row.odd", module)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user