fix gitea client

path.Join() mangles giteaRoot by changing https://codeberg.org to https:/codeberg.org
This causes the upstream requests to fail every time, always resulting in 424 Failed Dependency
This commit is contained in:
crystal 2022-05-21 02:50:40 -06:00 committed by 6543
parent cde2137df0
commit 7be32d4de2

View file

@ -27,6 +27,8 @@ type FileResponse struct {
Body []byte
}
func joinURL(giteaRoot string, paths ...string) string { return giteaRoot + path.Join(paths...) }
func (f FileResponse) IsEmpty() bool { return len(f.Body) != 0 }
func NewClient(giteaRoot, giteaAPIToken string) *Client {
@ -42,7 +44,7 @@ func NewClient(giteaRoot, giteaAPIToken string) *Client {
func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource string) ([]byte, error) {
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref)))
req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref)))
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
res := fasthttp.AcquireResponse()
@ -63,7 +65,7 @@ func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) {
fastClient := getFastHTTPClient(10 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, uri))
req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, uri))
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
resp := fasthttp.AcquireResponse()
@ -87,7 +89,7 @@ func (client *Client) GiteaGetRepoBranchTimestamp(repoOwner, repoName, branchNam
fastClient := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName))
req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName))
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
res := fasthttp.AcquireResponse()
@ -104,7 +106,7 @@ func (client *Client) GiteaGetRepoDefaultBranch(repoOwner, repoName string) (str
fastClient := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName))
req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, repoOwner, repoName))
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
res := fasthttp.AcquireResponse()