gitea api logging

This commit is contained in:
Ben Harris 2022-05-26 13:57:36 -04:00
parent 3e04412113
commit 54946a45d7
1 changed files with 13 additions and 4 deletions

View File

@ -20,7 +20,9 @@ const giteaAPIRepos = "/api/v1/repos/"
func giteaRawContent(targetOwner, targetRepo, ref, giteaRoot, giteaAPIToken, resource string) ([]byte, error) { func giteaRawContent(targetOwner, targetRepo, ref, giteaRoot, giteaAPIToken, resource string) ([]byte, error) {
req := fasthttp.AcquireRequest() req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))) apiPath := path.Join(giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))
log.Debug().Msgf("giteaRawContent: trying path %s", apiPath)
req.SetRequestURI(apiPath)
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken) req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res := fasthttp.AcquireResponse() res := fasthttp.AcquireResponse()
@ -37,14 +39,18 @@ func giteaGetRepoBranchTimestamp(giteaRoot, repoOwner, repoName, branchName, git
client := getFastHTTPClient(5 * time.Second) client := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest() req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName)) apiPath := path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName)
log.Debug().Msgf("giteaGetRepoBranchTimestamp: trying path %s", apiPath)
req.SetRequestURI(apiPath)
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken) req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res := fasthttp.AcquireResponse() res := fasthttp.AcquireResponse()
if err := client.Do(req, res); err != nil { if err := client.Do(req, res); err != nil {
log.Err(err)
return time.Time{}, err return time.Time{}, err
} }
if res.StatusCode() != fasthttp.StatusOK { if res.StatusCode() != fasthttp.StatusOK {
log.Error().Msgf("unexpected status code '%d'", res.StatusCode())
return time.Time{}, fmt.Errorf("unexpected status code '%d'", res.StatusCode()) return time.Time{}, fmt.Errorf("unexpected status code '%d'", res.StatusCode())
} }
return time.Parse(time.RFC3339, fastjson.GetString(res.Body(), "commit", "timestamp")) return time.Parse(time.RFC3339, fastjson.GetString(res.Body(), "commit", "timestamp"))
@ -54,15 +60,18 @@ func giteaGetRepoDefaultBranch(giteaRoot, repoOwner, repoName, giteaAPIToken str
client := getFastHTTPClient(5 * time.Second) client := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest() req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName)) apiPath := path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName)
log.Debug().Msgf("trying repo %s/%s", repoOwner, repoName) log.Debug().Msgf("trying path %s", apiPath)
req.SetRequestURI(apiPath)
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken) req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res := fasthttp.AcquireResponse() res := fasthttp.AcquireResponse()
if err := client.Do(req, res); err != nil { if err := client.Do(req, res); err != nil {
log.Err(err)
return "", err return "", err
} }
if res.StatusCode() != fasthttp.StatusOK { if res.StatusCode() != fasthttp.StatusOK {
log.Error().Msgf("unexpected status code '%d'", res.StatusCode())
return "", fmt.Errorf("unexpected status code '%d'", res.StatusCode()) return "", fmt.Errorf("unexpected status code '%d'", res.StatusCode())
} }
return fastjson.GetString(res.Body(), "default_branch"), nil return fastjson.GetString(res.Body(), "default_branch"), nil