Support creating Pull Requests on Codeberg via Zed UI (#66182)

## Summary
Currently, trying to create a pr via zeds ui fails with the error:
```
Unable to construct pull request URL
```

This PR fixes this by providing an implementation of
`GitHostingProvider::build_create_pull_request_url` to the Forgejo git
hosting provider.

## Testing
Tested by adding a unit test that verifies the generated pull request
url matches the expected structure. Verified that it works end-to-end by
creating a PR on codeberg via a build of this pr.

## Self-review

- [X] I've reviewed my diff for quality, security, reliability, and
performance.
- [ ] ~~UI changes follow the checklist~~ (N/A, no UI changes)
- [X] Tests cover the new or changed behavior.

Release Notes:
- Fixed creating pull requests from Zed for Forgejo remotes (including
Codeberg).
This commit is contained in:
Leon Lux
2026-10-30 09:59:44 +00:00
committed by GitHub
parent bfd1dd484b
commit 915290734a
@@ -228,6 +228,21 @@ impl GitHostingProvider for Forgejo {
permalink
}
fn build_create_pull_request_url(
&self,
remote: &ParsedGitRemote,
source_branch: &str,
) -> Option<Url> {
let ParsedGitRemote { owner, repo } = remote;
let mut url = self.base_url();
url.path_segments_mut()
.ok()?
.pop_if_empty()
.extend([owner.as_ref(), repo.as_ref(), "compare"])
.extend(source_branch.split('/'));
Some(url)
}
async fn commit_author_avatar_url(
&self,
repo_owner: &str,
@@ -319,6 +334,22 @@ mod tests {
);
}
#[test]
fn test_build_codeberg_create_pull_request_url() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let url = Forgejo::public_instance()
.build_create_pull_request_url(&remote, "feature/new-feature")
.expect("should be able to build pull request url");
assert_eq!(
url.as_str(),
"https://codeberg.org/zed-industries/zed/compare/feature/new-feature"
);
}
#[test]
fn test_parse_remote_url_given_self_hosted_https_url() {
let remote_url = "https://forgejo.my-enterprise.com/zed-industries/zed.git";