mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Widget titles can now be specified in the config file via a 'title' key. Example: wtf: mods: todo: title: Tada which can include emoji. No need to force everyone to look at my emoji, now they can define their own.
88 lines
1.8 KiB
Go
88 lines
1.8 KiB
Go
package jira
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/olebedev/config"
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
// 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(" Jira ", "jira", false),
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
if widget.Disabled() {
|
|
return
|
|
}
|
|
|
|
searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), Config.UString("wtf.mods.jira.project", ""), Config.UString("wtf.mods.jira.jql", ""))
|
|
|
|
widget.UpdateRefreshedAt()
|
|
|
|
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]%s[white]",
|
|
widget.Name,
|
|
Config.UString("wtf.mods.jira.project"),
|
|
),
|
|
)
|
|
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult)))
|
|
}
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|
str := " [red]Assigned Issues[white]\n"
|
|
|
|
for idx, issue := range searchResult.Issues {
|
|
str = str + fmt.Sprintf(
|
|
" [%s]%-6s[white] [green]%-10s[%s] %s\n",
|
|
widget.issueTypeColor(&issue),
|
|
issue.IssueFields.IssueType.Name,
|
|
issue.Key,
|
|
wtf.RowColor("jira", idx),
|
|
issue.IssueFields.Summary,
|
|
)
|
|
}
|
|
|
|
return str
|
|
}
|
|
|
|
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
|
var color string
|
|
|
|
switch issue.IssueFields.IssueType.Name {
|
|
case "Bug":
|
|
color = "red"
|
|
case "Story":
|
|
color = "blue"
|
|
case "Task":
|
|
color = "orange"
|
|
default:
|
|
color = "white"
|
|
}
|
|
|
|
return color
|
|
}
|