From 7be32d4de26e610b1cd7316e02e8f02c2a06390d Mon Sep 17 00:00:00 2001
From: crystal <crystal@noreply.codeberg.org>
Date: Sat, 21 May 2022 02:50:40 -0600
Subject: [PATCH] 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
---
 server/gitea/client.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/server/gitea/client.go b/server/gitea/client.go
index 49983dd..85e9879 100644
--- a/server/gitea/client.go
+++ b/server/gitea/client.go
@@ -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()