From e7ef2eb3700ca59c5ee5be026859f8ef35540741 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Thu, 6 Nov 2025 13:57:31 +0100 Subject: [PATCH] fix: add required headers to pagure migration (#9973) See https://pagure.io/fedora-infrastructure/issue/12886 for details. Resolves https://codeberg.org/forgejo/forgejo/issues/9974 ## Test 1. Go to https://dev.gusted.xyz/repo/migrate?service_type=10 2. Fill in https://pagure.io/slapi-nis 3. Migrate. 4. Verify the migration succeeded. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9973 Reviewed-by: Gusted Co-authored-by: Alexander Bokovoy Co-committed-by: Alexander Bokovoy --- services/migrations/pagure.go | 8 +++++++- ...tags => GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F} | 0 ...tags => GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F} | 0 3 files changed, 7 insertions(+), 1 deletion(-) rename services/migrations/testdata/pagure/full_download/authorized/{GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags => GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F} (100%) rename services/migrations/testdata/pagure/full_download/unauthorized/{GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags => GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F} (100%) diff --git a/services/migrations/pagure.go b/services/migrations/pagure.go index f9433671c0..c544714ae7 100644 --- a/services/migrations/pagure.go +++ b/services/migrations/pagure.go @@ -16,6 +16,7 @@ import ( "forgejo.org/modules/log" base "forgejo.org/modules/migration" "forgejo.org/modules/proxy" + "forgejo.org/modules/setting" "forgejo.org/modules/structs" "forgejo.org/modules/util" ) @@ -279,6 +280,11 @@ func (d *PagureDownloader) callAPI(endpoint string, parameter map[string]string, if err != nil { return err } + + // pagure.io is protected by Anubis and requires proper headers + req.Header.Add("Accept", "*/*") + req.Header.Add("User-Agent", "Forgejo/"+setting.AppVer) + if d.privateIssuesOnlyRepo { req.Header.Set("Authorization", "token "+d.token) } @@ -344,7 +350,7 @@ func (d *PagureDownloader) GetMilestones() ([]*base.Milestone, error) { func (d *PagureDownloader) GetLabels() ([]*base.Label, error) { rawLabels := PagureLabelsList{} - err := d.callAPI("/api/0/"+d.repoName+"/tags", nil, &rawLabels) + err := d.callAPI("/api/0/"+d.repoName+"/tags/", nil, &rawLabels) if err != nil { return nil, err } diff --git a/services/migrations/testdata/pagure/full_download/authorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags b/services/migrations/testdata/pagure/full_download/authorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F similarity index 100% rename from services/migrations/testdata/pagure/full_download/authorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags rename to services/migrations/testdata/pagure/full_download/authorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F diff --git a/services/migrations/testdata/pagure/full_download/unauthorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags b/services/migrations/testdata/pagure/full_download/unauthorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F similarity index 100% rename from services/migrations/testdata/pagure/full_download/unauthorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags rename to services/migrations/testdata/pagure/full_download/unauthorized/GET_%2Fapi%2F0%2Fprotop2g-test-srce%2Ftags%2F