FetcherRequest

This commit is contained in:
Zsolt Tasnadi
2026-01-20 08:31:59 +01:00
parent 8f51e6d981
commit 6be44be9bf
4 changed files with 66 additions and 16 deletions

View File

@@ -29,15 +29,25 @@ func (f GiteaFetcher) Fetch() []Entry {
if repo == "" {
continue
}
giteaURL := fmt.Sprintf("%s/api/v1/repos/%s/commits", f.BaseURL, strings.TrimSpace(repo))
req, _ := http.NewRequest("GET", giteaURL, nil)
repo = strings.TrimSpace(repo)
path := fmt.Sprintf("/api/v1/repos/%s/commits", repo)
headers := map[string]string{}
if f.Token != "" {
req.Header.Set("Authorization", "token "+f.Token)
headers["Authorization"] = "token " + f.Token
}
req := FetcherRequest{
BaseURL: f.BaseURL,
Path: path,
Method: http.MethodGet,
Headers: headers,
}
var r GiteaResponse
if err := getJSON(req, &r); err != nil {
if err := req.Run(&r); err != nil {
continue
}
@@ -46,8 +56,9 @@ func (f GiteaFetcher) Fetch() []Entry {
}
commit := r[0]
cacheKey := "gitea_" + url.QueryEscape(f.BaseURL+path)
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(giteaURL), commit.Sha) {
if f.Cache.TryUpdate(cacheKey, commit.Sha) {
messages = append(messages, Entry{
Title: fmt.Sprintf("📝 [Gitea] - (%s) %s", repo, commit.Commit.Message),
URL: commit.HTMLURL,