mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Jira extracted to new config format
This commit is contained in:
parent
9b41e6e732
commit
fea83a38b2
3
main.go
3
main.go
@ -241,7 +241,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := jenkins.NewSettingsFromYAML(wtf.Config)
|
settings := jenkins.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = jenkins.NewWidget(app, pages, settings)
|
widget = jenkins.NewWidget(app, pages, settings)
|
||||||
case "jira":
|
case "jira":
|
||||||
widget = jira.NewWidget(app, pages)
|
settings := jira.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = jira.NewWidget(app, pages, settings)
|
||||||
case "logger":
|
case "logger":
|
||||||
widget = logger.NewWidget(app)
|
widget = logger.NewWidget(app)
|
||||||
case "mercurial":
|
case "mercurial":
|
||||||
|
@ -9,13 +9,10 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
|
func (widget *Widget) IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
|
||||||
query := []string{}
|
query := []string{}
|
||||||
|
|
||||||
var projQuery = getProjectQuery(projects)
|
var projQuery = getProjectQuery(projects)
|
||||||
@ -37,7 +34,7 @@ func IssuesFor(username string, projects []string, jql string) (*SearchResult, e
|
|||||||
|
|
||||||
url := fmt.Sprintf("/rest/api/2/search?%s", v.Encode())
|
url := fmt.Sprintf("/rest/api/2/search?%s", v.Encode())
|
||||||
|
|
||||||
resp, err := jiraRequest(url)
|
resp, err := widget.jiraRequest(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SearchResult{}, err
|
return &SearchResult{}, err
|
||||||
}
|
}
|
||||||
@ -54,26 +51,18 @@ func buildJql(key string, value string) string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func apiKey() string {
|
func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
|
||||||
return wtf.Config.UString(
|
url := fmt.Sprintf("%s%s", widget.settings.domain, path)
|
||||||
"wtf.mods.jira.apiKey",
|
|
||||||
os.Getenv("WTF_JIRA_API_KEY"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func jiraRequest(path string) (*http.Response, error) {
|
|
||||||
url := fmt.Sprintf("%s%s", wtf.Config.UString("wtf.mods.jira.domain"), path)
|
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(wtf.Config.UString("wtf.mods.jira.email"), apiKey())
|
req.SetBasicAuth(widget.settings.email, widget.settings.apiKey)
|
||||||
|
|
||||||
verifyServerCertificate := wtf.Config.UBool("wtf.mods.jira.verifyServerCertificate", true)
|
|
||||||
httpClient := &http.Client{Transport: &http.Transport{
|
httpClient := &http.Client{Transport: &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{
|
TLSClientConfig: &tls.Config{
|
||||||
InsecureSkipVerify: !verifyServerCertificate,
|
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
|
||||||
},
|
},
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: http.ProxyFromEnvironment,
|
||||||
},
|
},
|
||||||
|
74
modules/jira/settings.go
Normal file
74
modules/jira/settings.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package jira
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type colors struct {
|
||||||
|
rows struct {
|
||||||
|
even string
|
||||||
|
odd string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
colors
|
||||||
|
common *cfg.Common
|
||||||
|
|
||||||
|
apiKey string
|
||||||
|
domain string
|
||||||
|
email string
|
||||||
|
jql string
|
||||||
|
projects []string
|
||||||
|
username string
|
||||||
|
verifyServerCertificate bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
|
localConfig, _ := ymlConfig.Get("wtf.mods.jira")
|
||||||
|
|
||||||
|
settings := Settings{
|
||||||
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
|
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_JIRA_API_KEY")),
|
||||||
|
domain: localConfig.UString("domain"),
|
||||||
|
email: localConfig.UString("email"),
|
||||||
|
jql: localConfig.UString("jql"),
|
||||||
|
username: localConfig.UString("username"),
|
||||||
|
verifyServerCertificate: localConfig.UBool("verifyServerCertificate", true),
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.colors.rows.even = localConfig.UString("colors.even", "lightblue")
|
||||||
|
settings.colors.rows.odd = localConfig.UString("colors.odd", "white")
|
||||||
|
|
||||||
|
settings.projects = settings.arrayifyProjects(localConfig)
|
||||||
|
|
||||||
|
return &settings
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported functions -------------------- */
|
||||||
|
|
||||||
|
// arrayifyProjects figures out if we're dealing with a single project or an array of projects
|
||||||
|
func (settings *Settings) arrayifyProjects(localConfig *config.Config) []string {
|
||||||
|
projects := []string{}
|
||||||
|
|
||||||
|
// Single project
|
||||||
|
project, err := localConfig.String("project")
|
||||||
|
if err == nil {
|
||||||
|
projects = append(projects, project)
|
||||||
|
return projects
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array of projects
|
||||||
|
projectList := localConfig.UList("project")
|
||||||
|
for _, projectName := range projectList {
|
||||||
|
if project, ok := projectName.(string); ok {
|
||||||
|
projects = append(projects, project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return projects
|
||||||
|
}
|
@ -28,12 +28,15 @@ type Widget struct {
|
|||||||
|
|
||||||
result *SearchResult
|
result *SearchResult
|
||||||
selected int
|
selected int
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Jira", "jira", true),
|
TextWidget: wtf.NewTextWidget(app, "Jira", "jira", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
@ -48,10 +51,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
searchResult, err := IssuesFor(
|
searchResult, err := widget.IssuesFor(
|
||||||
wtf.Config.UString("wtf.mods.jira.username"),
|
widget.settings.username,
|
||||||
getProjects(),
|
widget.settings.projects,
|
||||||
wtf.Config.UString("wtf.mods.jira.jql", ""),
|
widget.settings.jql,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,7 +77,7 @@ func (widget *Widget) display() {
|
|||||||
}
|
}
|
||||||
widget.View.SetWrap(false)
|
widget.View.SetWrap(false)
|
||||||
|
|
||||||
str := fmt.Sprintf("%s- [green]%s[white]", widget.Name(), wtf.Config.UString("wtf.mods.jira.project"))
|
str := fmt.Sprintf("%s- [green]%s[white]", widget.Name(), widget.settings.projects)
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
widget.View.SetTitle(widget.ContextualTitle(str))
|
widget.View.SetTitle(widget.ContextualTitle(str))
|
||||||
@ -100,7 +103,7 @@ func (widget *Widget) openItem() {
|
|||||||
sel := widget.selected
|
sel := widget.selected
|
||||||
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {
|
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {
|
||||||
issue := &widget.result.Issues[widget.selected]
|
issue := &widget.result.Issues[widget.selected]
|
||||||
wtf.OpenFile(wtf.Config.UString("wtf.mods.jira.domain") + "/browse/" + issue.Key)
|
wtf.OpenFile(widget.settings.domain + "/browse/" + issue.Key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +140,12 @@ func (widget *Widget) rowColor(idx int) string {
|
|||||||
if widget.View.HasFocus() && (idx == widget.selected) {
|
if widget.View.HasFocus() && (idx == widget.selected) {
|
||||||
return wtf.DefaultFocussedRowColor()
|
return wtf.DefaultFocussedRowColor()
|
||||||
}
|
}
|
||||||
return wtf.RowColor("jira", idx)
|
|
||||||
|
if idx%2 == 0 {
|
||||||
|
return widget.settings.colors.rows.even
|
||||||
|
}
|
||||||
|
|
||||||
|
return widget.settings.colors.rows.odd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
||||||
@ -153,24 +161,6 @@ func (widget *Widget) issueTypeColor(issue *Issue) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjects() []string {
|
|
||||||
// see if project is set to a single string
|
|
||||||
configPath := "wtf.mods.jira.project"
|
|
||||||
singleProject, err := wtf.Config.String(configPath)
|
|
||||||
if err == nil {
|
|
||||||
return []string{singleProject}
|
|
||||||
}
|
|
||||||
// else, assume list
|
|
||||||
projList := wtf.Config.UList(configPath)
|
|
||||||
var ret []string
|
|
||||||
for _, proj := range projList {
|
|
||||||
if str, ok := proj.(string); ok {
|
|
||||||
ret = append(ret, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch string(event.Rune()) {
|
switch string(event.Rune()) {
|
||||||
case "/":
|
case "/":
|
||||||
|
@ -136,10 +136,7 @@ func ReadFileBytes(filePath string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RightAlignFormat(view *tview.TextView) string {
|
func RightAlignFormat(view *tview.TextView) string {
|
||||||
//mutex := &sync.Mutex{}
|
|
||||||
//mutex.Lock()
|
|
||||||
_, _, w, _ := view.GetInnerRect()
|
_, _, w, _ := view.GetInnerRect()
|
||||||
//mutex.Unlock()
|
|
||||||
|
|
||||||
return fmt.Sprintf("%%%ds", w-1)
|
return fmt.Sprintf("%%%ds", w-1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user