diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-05-07 17:26:46 +0200 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-05-07 21:24:57 +0200 |
commit | 35839438581bce0abf50917b702cd585a15c4145 (patch) | |
tree | 539629d6024769f67b20941f9ac1e70cfd88da4c /src/prs.rs | |
parent | add pr change viewing commands (diff) | |
download | forgejo-cli-35839438581bce0abf50917b702cd585a15c4145.tar.xz forgejo-cli-35839438581bce0abf50917b702cd585a15c4145.zip |
display changed lines in `pr view`
Diffstat (limited to '')
-rw-r--r-- | src/prs.rs | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -147,7 +147,7 @@ impl PrCommand { } => create_pr(&repo, &api, title, base, head, body).await?, Merge { pr, method, delete } => merge_pr(&repo, &api, pr, method, delete).await?, View { id, command } => match command.unwrap_or(ViewCommand::Body) { - ViewCommand::Body => crate::issues::view_issue(&repo, &api, id).await?, + ViewCommand::Body => view_pr(&repo, &api, id).await?, ViewCommand::Comment { idx } => { crate::issues::view_comment(&repo, &api, id, idx).await? } @@ -186,6 +186,50 @@ impl PrCommand { } } +pub async fn view_pr(repo: &RepoName, api: &Forgejo, id: u64) -> eyre::Result<()> { + let mut additions = 0; + let mut deletions = 0; + let query = RepoGetPullRequestFilesQuery { + limit: Some(u32::MAX), + ..Default::default() + }; + let (_, files) = api + .repo_get_pull_request_files(repo.owner(), repo.name(), id, query) + .await?; + for file in files { + additions += file.additions.unwrap_or_default(); + deletions += file.deletions.unwrap_or_default(); + } + let pr = api + .repo_get_pull_request(repo.owner(), repo.name(), id) + .await?; + let title = pr + .title + .as_ref() + .ok_or_else(|| eyre::eyre!("pr does not have title"))?; + let user = pr + .user + .as_ref() + .ok_or_else(|| eyre::eyre!("pr does not have creator"))?; + let username = user + .login + .as_ref() + .ok_or_else(|| eyre::eyre!("user does not have login"))?; + println!("#{}: {}", id, title); + println!( + "By {} - \x1b[92m+{additions} \x1b[91m-{deletions}\x1b[0m", + username + ); + if let Some(body) = &pr.body { + println!(); + for line in body.lines() { + println!(" {line}"); + } + println!(); + } + Ok(()) +} + async fn create_pr( repo: &RepoName, api: &Forgejo, |