[v14.0/forgejo] fix: use an absolute URL for compare links in atom feed (#11126)

**Backport:** #10933

(cherry picked from commit 995244895a)

Co-authored-by: xrstf <git@xrstf.de>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11126
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Mathieu Fenniak 2026-02-01 19:46:45 +01:00
commit a59481d3d9
3 changed files with 14 additions and 1 deletions

View file

@ -224,7 +224,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
}
if push.Len > 1 {
link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)}
link = &feeds.Link{Href: setting.AppURL + push.CompareURL}
} else if push.Len == 1 {
link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), push.Commits[0].Sha1)}
}

View file

@ -61,6 +61,8 @@ func TestFeed(t *testing.T) {
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
require.NoError(t, err)
assert.Contains(t, rss.Channel.Link, "/user2")
assert.NotEmpty(t, rss.Channel.Items)
assert.Regexp(t, `http://localhost:\d+/user2/repo1/compare/ed4090`, rss.Channel.Items[0].Link)
assert.NotEmpty(t, rss.Channel.PubDate)
})
})

View file

@ -16,3 +16,14 @@
is_private: false
created_unix: 1680454039
content: '["1","Well, this test is short | succient | distinct."]'
# a multi-commit push to validate the format of the generated compare URLs, see #10168
- id: 1003
user_id: 2
op_type: 5 # commit repo
act_user_id: 2
comment_id: 0
repo_id: 1 # public
is_private: false
created_unix: 1680454039
content: '{"Commits":[{"Sha1":"412413fd409fc0cab446e7b59702596e1bde1816","Message":"fourth commit","AuthorEmail":"git@example.com","AuthorName":"dummy","CommitterEmail":"git@example.com","CommitterName":"dummy","Signature":null,"Verification":null,"Timestamp":"2026-01-19T22:07:22+01:00"},{"Sha1":"00a01802439eb2c0391fdfaa2c344b5e25d0b9d4","Message":"third commit","AuthorEmail":"git@example.com","AuthorName":"dummy","CommitterEmail":"git@example.com","CommitterName":"dummy","Signature":null,"Verification":null,"Timestamp":"2026-01-19T22:07:18+01:00"}],"HeadCommit":{"Sha1":"412413fd409fc0cab446e7b59702596e1bde1816","Message":"fourth commit","AuthorEmail":"git@example.com","AuthorName":"dummy","CommitterEmail":"git@example.com","CommitterName":"dummy","Signature":null,"Verification":null,"Timestamp":"2026-01-19T22:07:22+01:00"},"CompareURL":"user2/repo1/compare/ed4090ecc2d9dd16b184763cc476ea1b28afa560...412413fd409fc0cab446e7b59702596e1bde1816","Len":2}'