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

Properly scope Config to the wtf package and remove it as a dependency from everywhere else

This commit is contained in:
Chris Cummer
2018-06-16 14:59:22 -07:00
parent abedee0ce0
commit 66b69471d0
42 changed files with 126 additions and 251 deletions

View File

@@ -11,6 +11,8 @@ import (
"net/url"
"os"
"strings"
"github.com/senorprogrammer/wtf/wtf"
)
func IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
@@ -53,21 +55,21 @@ func buildJql(key string, value string) string {
/* -------------------- Unexported Functions -------------------- */
func jiraRequest(path string) (*http.Response, error) {
url := fmt.Sprintf("%s%s", Config.UString("wtf.mods.jira.domain"), path)
url := fmt.Sprintf("%s%s", wtf.Config.UString("wtf.mods.jira.domain"), path)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.SetBasicAuth(Config.UString("wtf.mods.jira.email"), os.Getenv("WTF_JIRA_API_KEY"))
req.SetBasicAuth(wtf.Config.UString("wtf.mods.jira.email"), os.Getenv("WTF_JIRA_API_KEY"))
verifyServerCertificate := Config.UBool("wtf.mods.jira.verifyServerCertificate", true)
verifyServerCertificate := wtf.Config.UBool("wtf.mods.jira.verifyServerCertificate", true)
httpClient := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !verifyServerCertificate,
},
},
}
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !verifyServerCertificate,
},
},
}
resp, err := httpClient.Do(req)
if err != nil {
return nil, err

View File

@@ -3,13 +3,9 @@ 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
}
@@ -25,7 +21,11 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), getProjects(), Config.UString("wtf.mods.jira.jql", ""))
searchResult, err := IssuesFor(
wtf.Config.UString("wtf.mods.jira.username"),
getProjects(),
wtf.Config.UString("wtf.mods.jira.jql", ""),
)
widget.UpdateRefreshedAt()
@@ -39,7 +39,7 @@ func (widget *Widget) Refresh() {
fmt.Sprintf(
"%s- [green]%s[white]",
widget.Name,
Config.UString("wtf.mods.jira.project"),
wtf.Config.UString("wtf.mods.jira.project"),
),
)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult)))
@@ -85,12 +85,12 @@ 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 := Config.String(configPath)
singleProject, err := wtf.Config.String(configPath)
if err == nil {
return []string{singleProject}
}
// else, assume list
projList := Config.UList(configPath)
projList := wtf.Config.UList(configPath)
var ret []string
for _, proj := range projList {
if str, ok := proj.(string); ok {