response structs

This commit is contained in:
2026-01-19 23:01:16 +01:00
parent ee6dfca55f
commit a89c320106
3 changed files with 38 additions and 28 deletions

View File

@@ -7,6 +7,14 @@ import (
"strings" "strings"
) )
type GiteaResponse []struct {
Sha string `json:"sha"`
HTMLURL string `json:"html_url"`
Commit struct {
Message string `json:"message"`
} `json:"commit"`
}
type GiteaFetcher struct { type GiteaFetcher struct {
BaseURL string BaseURL string
Token string Token string
@@ -27,13 +35,8 @@ func (f GiteaFetcher) Fetch() []string {
req.Header.Set("Authorization", "token "+f.Token) req.Header.Set("Authorization", "token "+f.Token)
} }
var r []struct { var r GiteaResponse
Sha string `json:"sha"`
Commit struct {
Message string `json:"message"`
} `json:"commit"`
HTMLURL string `json:"html_url"`
}
if err := getJSON(req, &r); err != nil { if err := getJSON(req, &r); err != nil {
continue continue
} }
@@ -41,10 +44,11 @@ func (f GiteaFetcher) Fetch() []string {
if len(r) == 0 { if len(r) == 0 {
continue continue
} }
c := r[0]
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(giteaURL), c.Sha) { commit := r[0]
messages = append(messages, fmt.Sprintf("Gitea: %s <%s>", c.Commit.Message, c.HTMLURL))
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(giteaURL), commit.Sha) {
messages = append(messages, fmt.Sprintf("Gitea: %s <%s>", commit.Commit.Message, commit.HTMLURL))
} }
} }
return messages return messages

View File

@@ -5,6 +5,14 @@ import (
"net/http" "net/http"
) )
type RedmineResponse struct {
Issues []struct {
ID int
UpdatedOn string
Subject string
}
}
type RedmineFetcher struct { type RedmineFetcher struct {
Config Config Config Config
Cache *Cache Cache *Cache
@@ -15,13 +23,8 @@ func (f RedmineFetcher) Fetch() []string {
req, _ := http.NewRequest("GET", redmineURL, nil) req, _ := http.NewRequest("GET", redmineURL, nil)
req.Header.Set("X-Redmine-API-Key", f.Config.RedmineKey) req.Header.Set("X-Redmine-API-Key", f.Config.RedmineKey)
var r struct { var r RedmineResponse
Issues []struct {
ID int
UpdatedOn string
Subject string
}
}
if err := getJSON(req, &r); err != nil { if err := getJSON(req, &r); err != nil {
return []string{} return []string{}
} }

View File

@@ -6,6 +6,18 @@ import (
"net/http" "net/http"
) )
type WikiResponse struct {
Data struct {
Pages struct {
List []struct {
UpdatedAt string
Title string
Path string
}
}
}
}
type WikiFetcher struct { type WikiFetcher struct {
Config Config Config Config
Cache *Cache Cache *Cache
@@ -18,17 +30,8 @@ func (f WikiFetcher) Fetch() []string {
req.Header.Set("Authorization", "Bearer "+f.Config.WikiToken) req.Header.Set("Authorization", "Bearer "+f.Config.WikiToken)
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
var r struct { var r WikiResponse
Data struct {
Pages struct {
List []struct {
UpdatedAt string
Title string
Path string
}
}
}
}
if err := getJSON(req, &r); err != nil { if err := getJSON(req, &r); err != nil {
return []string{} return []string{}
} }