mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
display changed lines in pr view
This commit is contained in:
parent
6fd1976013
commit
3583943858
1 changed files with 45 additions and 1 deletions
46
src/prs.rs
46
src/prs.rs
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue