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