initial commit
This commit is contained in:
43
lib/fetcher.redmine.go
Normal file
43
lib/fetcher.redmine.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type RedmineFetcher struct {
|
||||
Config Config
|
||||
Cache *Cache
|
||||
}
|
||||
|
||||
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 {
|
||||
ID int
|
||||
UpdatedOn string
|
||||
Subject string
|
||||
}
|
||||
}
|
||||
json.NewDecoder(res.Body).Decode(&r)
|
||||
|
||||
if len(r.Issues) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user