1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch 'master' into skip-certificate-check-jira

This commit is contained in:
Anand Sudhir Prayaga
2018-06-14 16:00:46 +02:00
committed by GitHub
193 changed files with 19396 additions and 324 deletions

View File

@@ -13,11 +13,12 @@ import (
"strings"
)
func IssuesFor(username string, project string, jql string) (*SearchResult, error) {
func IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
query := []string{}
if project != "" {
query = append(query, buildJql("project", project))
var projQuery = getProjectQuery(projects)
if projQuery != "" {
query = append(query, projQuery)
}
if username != "" {
@@ -95,3 +96,18 @@ func parseJson(obj interface{}, text io.Reader) {
}
}
}
func getProjectQuery(projects []string) string {
singleEmptyProject := len(projects) == 1 && len(projects[0]) == 0
if len(projects) == 0 || singleEmptyProject {
return ""
} else if len(projects) == 1 {
return buildJql("project", projects[0])
}
quoted := make([]string, len(projects))
for i := range projects {
quoted[i] = fmt.Sprintf("\"%s\"", projects[i])
}
return fmt.Sprintf("project in (%s)", strings.Join(quoted, ", "))
}

View File

@@ -1,8 +1,5 @@
package jira
import (
)
type Issue struct {
Expand string `json:"expand"`
ID string `json:"id"`

View File

@@ -1,7 +1,5 @@
package jira
import ()
type SearchResult struct {
StartAt int `json:"startAt"`
MaxResults int `json:"maxResults"`

View File

@@ -25,11 +25,7 @@ func NewWidget() *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", ""))
searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), getProjects(), Config.UString("wtf.mods.jira.jql", ""))
widget.UpdateRefreshedAt()
@@ -85,3 +81,21 @@ func (widget *Widget) issueTypeColor(issue *Issue) string {
return color
}
func getProjects() []string {
// see if project is set to a single string
configPath := "wtf.mods.jira.project"
singleProject, err := Config.String(configPath)
if err == nil {
return []string{singleProject}
}
// else, assume list
projList := Config.UList(configPath)
var ret []string
for _, proj := range projList {
if str, ok := proj.(string); ok {
ret = append(ret, str)
}
}
return ret
}