From ad92847fa0ec215edfbe809ca7c92d24b56f60e6 Mon Sep 17 00:00:00 2001 From: miyuko Date: Mon, 11 May 2026 02:18:34 +0100 Subject: [PATCH] Record git repo URL in manifest for archive uploads with forge auth. Resolves: https://codeberg.org/git-pages/git-pages/issues/165 --- src/auth.go | 7 +++++++ src/main.go | 2 +- src/pages.go | 7 +++++-- src/update.go | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/auth.go b/src/auth.go index b178eb2..b9bfeb3 100644 --- a/src/auth.go +++ b/src/auth.go @@ -119,6 +119,13 @@ type Authorization struct { forgeUser *ForgeUser } +func (auth *Authorization) ForgeRepoURL() string { + if auth.forgeUser != nil && len(auth.repoURLs) == 1 { + return auth.repoURLs[0] + } + return "" +} + func authorizeDNSChallenge(r *http.Request) (*Authorization, error) { host, err := GetHost(r) if err != nil { diff --git a/src/main.go b/src/main.go index 0df0c7e..bd266c2 100644 --- a/src/main.go +++ b/src/main.go @@ -437,7 +437,7 @@ func Main(versionInfo string) { } webRoot := webRootArg(*updateSite) - result = UpdateFromArchive(ctx, webRoot, contentType, file) + result = UpdateFromArchive(ctx, webRoot, "", contentType, file) } else { branch := "pages" if sourceURL.Fragment != "" { diff --git a/src/pages.go b/src/pages.go index addff83..2624e84 100644 --- a/src/pages.go +++ b/src/pages.go @@ -523,19 +523,22 @@ func putPage(w http.ResponseWriter, r *http.Request) error { result = UpdateFromRepository(ctx, webRoot, repoURL, branch) default: - if auth, err := AuthorizeUpdateFromArchive(r); err != nil { + auth, err := AuthorizeUpdateFromArchive(r) + if err != nil { return err } else if auth.forgeUser != nil { GetPrincipal(r.Context()).ForgeUser = auth.forgeUser } + repoURL := auth.ForgeRepoURL() + if checkDryRun(w, r) { return nil } // request body contains archive reader := http.MaxBytesReader(w, r.Body, int64(config.Limits.MaxSiteSize.Bytes())) - result = UpdateFromArchive(ctx, webRoot, contentType, reader) + result = UpdateFromArchive(ctx, webRoot, repoURL, contentType, reader) } return reportUpdateResult(w, r, result) diff --git a/src/update.go b/src/update.go index 0a93ed9..7fad302 100644 --- a/src/update.go +++ b/src/update.go @@ -128,6 +128,7 @@ var errArchiveFormat = errors.New("unsupported archive format") func UpdateFromArchive( ctx context.Context, webRoot string, + repoURL string, contentType string, reader io.Reader, ) (result UpdateResult) { @@ -162,6 +163,10 @@ func UpdateFromArchive( logc.Printf(ctx, "update %s err: %s", webRoot, err) result = UpdateResult{UpdateError, nil, err} } else { + if repoURL != "" { + newManifest.RepoUrl = &repoURL + } + result = Update(ctx, webRoot, oldManifest, newManifest, ModifyManifestOptions{}) }