fix pr browse opening issues page

This commit is contained in:
Cyborus 2024-05-14 11:46:49 -04:00
parent 85ee804919
commit 3f212baf4c
No known key found for this signature in database

View file

@ -292,7 +292,7 @@ impl PrCommand {
Checkout { pr, branch_name } => { Checkout { pr, branch_name } => {
checkout_pr(&repo, &api, pr, self.repo.is_some(), branch_name).await? checkout_pr(&repo, &api, pr, self.repo.is_some(), branch_name).await?
} }
Browse { id } => crate::issues::browse_issue(&repo, &api, id).await?, Browse { id } => browse_pr(&repo, &api, id).await?,
Comment { pr, body } => crate::issues::add_comment(&repo, &api, pr, body).await?, Comment { pr, body } => crate::issues::add_comment(&repo, &api, pr, body).await?,
} }
Ok(()) Ok(())
@ -988,3 +988,27 @@ async fn view_pr_commits(
} }
Ok(()) Ok(())
} }
pub async fn browse_pr(repo: &RepoName, api: &Forgejo, id: Option<u64>) -> eyre::Result<()> {
match id {
Some(id) => {
let pr = api
.repo_get_pull_request(repo.owner(), repo.name(), id)
.await?;
let html_url = pr
.html_url
.as_ref()
.ok_or_else(|| eyre::eyre!("pr does not have html_url"))?;
open::that(html_url.as_str())?;
}
None => {
let repo = api.repo_get(repo.owner(), repo.name()).await?;
let html_url = repo
.html_url
.as_ref()
.ok_or_else(|| eyre::eyre!("repo does not have html_url"))?;
open::that(format!("{}/pulls", html_url))?;
}
}
Ok(())
}