44 lines
796 B
Go
44 lines
796 B
Go
package lib
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type RedmineResponse struct {
|
|
Issues []struct {
|
|
ID int
|
|
UpdatedOn string
|
|
Subject string
|
|
}
|
|
}
|
|
|
|
type RedmineFetcher struct {
|
|
BaseURL string
|
|
Key string
|
|
Cache *Cache
|
|
}
|
|
|
|
func (f RedmineFetcher) Fetch() []string {
|
|
redmineURL := fmt.Sprintf("%s/issues.json", f.BaseURL)
|
|
req, _ := http.NewRequest("GET", redmineURL, nil)
|
|
req.Header.Set("X-Redmine-API-Key", f.Key)
|
|
|
|
var r RedmineResponse
|
|
|
|
if err := getJSON(req, &r); err != nil {
|
|
return []string{}
|
|
}
|
|
|
|
if len(r.Issues) == 0 {
|
|
return []string{}
|
|
}
|
|
|
|
i := r.Issues[0]
|
|
if f.Cache.TryUpdate("redmine", i.UpdatedOn) {
|
|
url := fmt.Sprintf("%s/issues/%d", f.BaseURL, i.ID)
|
|
return []string{fmt.Sprintf("🎫 [Redmine] - #%d %s - %s", i.ID, i.Subject, url)}
|
|
}
|
|
return []string{}
|
|
}
|