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: ed4090ecc2...412413fd40</id>
0 --    <link href="ed4090ecc2...412413fd40" 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>
This commit is contained in:
xrstf 2026-02-01 10:00:21 +01:00 committed by Mathieu Fenniak
parent dd62575d5a
commit 995244895a
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 | succinct | 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}'