initial commit

This commit is contained in:
2026-01-18 21:40:51 +01:00
commit 197a01440c
14 changed files with 374 additions and 0 deletions

44
lib/fetcher.gitea.go Normal file
View File

@@ -0,0 +1,44 @@
package lib
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
type GiteaFetcher struct {
URL string
Token string
Cache *Cache
}
func (f GiteaFetcher) Fetch() string {
req, _ := http.NewRequest("GET", f.URL, nil)
if f.Token != "" {
req.Header.Set("Authorization", "token "+f.Token)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return ""
}
defer res.Body.Close()
var r []struct {
Sha string `json:"sha"`
Commit struct {
Message string `json:"message"`
} `json:"commit"`
HTMLURL string `json:"html_url"`
}
json.NewDecoder(res.Body).Decode(&r)
if len(r) == 0 {
return ""
}
c := r[0]
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(f.URL), c.Sha) {
return fmt.Sprintf("Gitea: %s <%s>", c.Commit.Message, c.HTMLURL)
}
return ""
}