47 lines
813 B
Go
47 lines
813 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() []Entry {
|
|
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 []Entry{}
|
|
}
|
|
|
|
if len(r.Issues) == 0 {
|
|
return []Entry{}
|
|
}
|
|
|
|
i := r.Issues[0]
|
|
if f.Cache.TryUpdate("redmine", i.UpdatedOn) {
|
|
url := fmt.Sprintf("%s/issues/%d", f.BaseURL, i.ID)
|
|
return []Entry{{
|
|
Title: fmt.Sprintf("🎫 [Redmine] - #%d %s", i.ID, i.Subject),
|
|
URL: url,
|
|
}}
|
|
}
|
|
return []Entry{}
|
|
}
|