From a0188d963a060080aba73dabbcc7c3018da75635 Mon Sep 17 00:00:00 2001 From: Cyborus Date: Thu, 6 Jun 2024 15:32:51 -0400 Subject: `pr browse` opens current pr instead of pr list `issue browse` now requires an issue id --- src/issues.rs | 62 +++++++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 49 deletions(-) (limited to 'src/issues.rs') diff --git a/src/issues.rs b/src/issues.rs index a8e130d..b7b3a6e 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -59,7 +59,7 @@ pub enum IssueSubcommand { command: Option, }, Browse { - id: Option, + id: IssueId, }, } @@ -157,13 +157,7 @@ impl IssueCommand { } }, Close { issue, with_msg } => close_issue(&repo, &api, issue.number, with_msg).await?, - Browse { id } => { - let number = id.as_ref().and_then(|s| { - let num_s = s.rsplit_once("#").map(|(_, b)| b).unwrap_or(s); - num_s.parse::().ok() - }); - browse_issue(&repo, &api, number).await? - } + Browse { id } => browse_issue(&repo, &api, id.number).await?, Comment { issue, body } => add_comment(&repo, &api, issue.number, body).await?, } Ok(()) @@ -176,16 +170,8 @@ impl IssueCommand { View { id: issue, .. } | Edit { issue, .. } | Close { issue, .. } - | Comment { issue, .. } => issue.repo.as_deref(), - Browse { id, .. } => id.as_ref().and_then(|s| { - let repo = s.rsplit_once("#").map(|(a, _)| a).unwrap_or(s); - // Don't treat a lone issue number as a repo name - if repo.parse::().is_ok() { - None - } else { - Some(repo) - } - }), + | Comment { issue, .. } + | Browse { id: issue, .. } => issue.repo.as_deref(), } } @@ -198,21 +184,11 @@ impl IssueCommand { View { id: issue, .. } | Edit { issue, .. } | Close { issue, .. } - | Comment { issue, .. } => eyre::eyre!( + | Comment { issue, .. } + | Browse { id: issue, .. } => eyre::eyre!( "can't figure out what repo to access, try specifying with `{{owner}}/{{repo}}#{}`", issue.number ), - Browse { id, .. } => { - let number = id.as_ref().and_then(|s| { - let num_s = s.rsplit_once("#").map(|(_, b)| b).unwrap_or(s); - num_s.parse::().ok() - }); - if let Some(number) = number { - eyre::eyre!("can't figure out what repo to access, try specifying with `{{owner}}/{{repo}}#{}`", number) - } else { - eyre::eyre!("can't figure out what repo to access, try specifying with `{{owner}}/{{repo}}`") - } - } } } } @@ -390,25 +366,13 @@ fn print_comment(comment: &Comment) -> eyre::Result<()> { Ok(()) } -pub async fn browse_issue(repo: &RepoName, api: &Forgejo, id: Option) -> eyre::Result<()> { - match id { - Some(id) => { - let issue = api.issue_get_issue(repo.owner(), repo.name(), id).await?; - let html_url = issue - .html_url - .as_ref() - .ok_or_else(|| eyre::eyre!("issue 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!("issue does not have html_url"))?; - open::that(format!("{}/issues", html_url))?; - } - } +pub async fn browse_issue(repo: &RepoName, api: &Forgejo, id: u64) -> eyre::Result<()> { + let issue = api.issue_get_issue(repo.owner(), repo.name(), id).await?; + let html_url = issue + .html_url + .as_ref() + .ok_or_else(|| eyre::eyre!("issue does not have html_url"))?; + open::that(html_url.as_str())?; Ok(()) } -- cgit v1.2.3