Skip to content

Commit 9952448

Browse files
xrstfMathieu Fenniak
authored andcommitted
fix: use an absolute URL for compare links in atom feed (#10933)
This PR changes the URL format for `/compare/` links in the RSS/Atom feeds to include the full domain. This makes the links consistent with all other URLs in the feeds. Fixes #10168. I tested this on a local Forgejo build with a sample org and a dummy repository as per the original issue. I then fetched the feed to check: ```bash $ curl http://localhost:3000/helloworld.atom | grep compare % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4194 0 4194 0 0 297k <id>10: http://localhost:3000/helloworld/test/compare/ed4090ecc2d9dd16b184763cc476ea1b28afa560...412413fd409fc0cab446e7b59702596e1bde1816</id> 0 -- <link href="http://localhost:3000/helloworld/test/compare/ed4090ecc2d9dd16b184763cc476ea1b28afa560...412413fd409fc0cab446e7b59702596e1bde1816" rel="alternate"></link> ``` ## Checklist ### AI Disclosure I used AI to * ask it how to run a single integration test locally because I didn't know about `make test-sqlite#XXX`. ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. *The decision if the pull request will be shown in the release notes is up to the mergers / release team.* The content of the `release-notes/<pull request number>.md` file will serve as the basis for the release notes. If the file does not exist, the title of the pull request will be used instead. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10933 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: xrstf <git@xrstf.de> Co-committed-by: xrstf <git@xrstf.de>
1 parent dd62575 commit 9952448

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

routers/web/feed/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
224224
}
225225

226226
if push.Len > 1 {
227-
link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)}
227+
link = &feeds.Link{Href: setting.AppURL + push.CompareURL}
228228
} else if push.Len == 1 {
229229
link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), push.Commits[0].Sha1)}
230230
}

tests/integration/feed_user_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func TestFeed(t *testing.T) {
6161
err := xml.Unmarshal(resp.Body.Bytes(), &rss)
6262
require.NoError(t, err)
6363
assert.Contains(t, rss.Channel.Link, "/user2")
64+
assert.NotEmpty(t, rss.Channel.Items)
65+
assert.Regexp(t, `http://localhost:\d+/user2/repo1/compare/ed4090`, rss.Channel.Items[0].Link)
6466
assert.NotEmpty(t, rss.Channel.PubDate)
6567
})
6668
})

tests/integration/fixtures/TestFeed/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@
1616
is_private: false
1717
created_unix: 1680454039
1818
content: '["1","Well, this test is short | succinct | distinct."]'
19+
20+
# a multi-commit push to validate the format of the generated compare URLs, see #10168
21+
- id: 1003
22+
user_id: 2
23+
op_type: 5 # commit repo
24+
act_user_id: 2
25+
comment_id: 0
26+
repo_id: 1 # public
27+
is_private: false
28+
created_unix: 1680454039
29+
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}'

0 commit comments

Comments
 (0)