refactoring
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
@@ -11,15 +10,10 @@ type RedmineFetcher struct {
|
||||
Cache *Cache
|
||||
}
|
||||
|
||||
func (f RedmineFetcher) Fetch() string {
|
||||
func (f RedmineFetcher) Fetch() []string {
|
||||
redmineURL := fmt.Sprintf("%s/issues.json", f.Config.RedmineBaseURL)
|
||||
req, _ := http.NewRequest("GET", redmineURL, nil)
|
||||
req.Header.Set("X-Redmine-API-Key", f.Config.RedmineKey)
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var r struct {
|
||||
Issues []struct {
|
||||
@@ -28,16 +22,18 @@ func (f RedmineFetcher) Fetch() string {
|
||||
Subject string
|
||||
}
|
||||
}
|
||||
json.NewDecoder(res.Body).Decode(&r)
|
||||
if err := getJSON(req, &r); err != nil {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
if len(r.Issues) == 0 {
|
||||
return ""
|
||||
return []string{}
|
||||
}
|
||||
|
||||
i := r.Issues[0]
|
||||
if f.Cache.TryUpdate("redmine", i.UpdatedOn) {
|
||||
url := fmt.Sprintf("%s/issues/%d", f.Config.RedmineBaseURL, i.ID)
|
||||
return fmt.Sprintf("Redmine: #%d %s <%s>", i.ID, i.Subject, url)
|
||||
return []string{fmt.Sprintf("Redmine: #%d %s <%s>", i.ID, i.Subject, url)}
|
||||
}
|
||||
return ""
|
||||
return []string{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user