summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-08-03 00:44:21 +0200
committerCyborus <cyborus@cyborus.xyz>2024-08-03 00:44:21 +0200
commit67f09d8cdba38329555e4ead6a179536339e1ec2 (patch)
tree98be6e9ee8fc91df2673f2e7ff817b68ad90868c
parentMerge pull request '`repo delete`' (#99) from repo-delete into main (diff)
downloadforgejo-cli-67f09d8cdba38329555e4ead6a179536339e1ec2.tar.xz
forgejo-cli-67f09d8cdba38329555e4ead6a179536339e1ec2.zip
chore(dep): update `forgejo-api` to v0.4.0
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml2
-rw-r--r--src/issues.rs2
-rw-r--r--src/prs.rs30
-rw-r--r--src/release.rs20
-rw-r--r--src/user.rs56
6 files changed, 63 insertions, 51 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 06f1526..ca347d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -603,9 +603,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "forgejo-api"
-version = "0.3.2"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4ca8dec306811ad8b1c9095df65ad0f8960a751dd0ef2625254334fc5fa8f43"
+checksum = "a10f9cefc57c1aafba0f566294e56f2ef7bebbbe333265b9e58b5cad84fa2c50"
dependencies = [
"base64ct",
"bytes",
diff --git a/Cargo.toml b/Cargo.toml
index 63fc8bd..3e3c359 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ comrak = "0.26.0"
crossterm = "0.27.0"
directories = "5.0.1"
eyre = "0.6.12"
-forgejo-api = "0.3.2"
+forgejo-api = "0.4.0"
futures = "0.3.30"
git2 = "0.19.0"
hyper = "1.4.1"
diff --git a/src/issues.rs b/src/issues.rs
index d428d0e..130a1ef 100644
--- a/src/issues.rs
+++ b/src/issues.rs
@@ -593,7 +593,7 @@ pub async fn edit_comment(
};
let id = comment
.id
- .ok_or_else(|| eyre::eyre!("comment does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("comment does not have id"))? as u64;
api.issue_edit_comment(
repo.owner(),
repo.name(),
diff --git a/src/prs.rs b/src/prs.rs
index 5a400f1..9d38d5c 100644
--- a/src/prs.rs
+++ b/src/prs.rs
@@ -415,7 +415,7 @@ pub async fn view_pr(repo: &RepoName, api: &Forgejo, id: Option<u64>) -> eyre::R
..
} = crate::special_render();
let pr = try_get_pr(repo, api, id).await?;
- let id = pr.number.ok_or_eyre("pr does not have number")?;
+ let id = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
let mut additions = 0;
@@ -634,7 +634,7 @@ async fn view_pr_status(repo: &RepoName, api: &Forgejo, id: Option<u64>) -> eyre
}
println!();
} else {
- let pr_number = pr.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let query = forgejo_api::structs::RepoGetPullRequestCommitsQuery {
page: None,
limit: Some(u32::MAX),
@@ -713,7 +713,7 @@ async fn edit_pr_labels(
rm: Vec<String>,
) -> eyre::Result<()> {
let pr = try_get_pr(repo, api, pr).await?;
- let pr_number = pr.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
let query = forgejo_api::structs::IssueListLabelsQuery {
@@ -741,7 +741,9 @@ async fn edit_pr_labels(
.iter()
.find(|label| label.name.as_ref() == Some(&label_name));
if let Some(label) = maybe_label {
- add_ids.push(label.id.ok_or_eyre("label does not have id")?);
+ add_ids.push(serde_json::Value::Number(
+ label.id.ok_or_eyre("label does not have id")?.into(),
+ ));
} else {
unknown_labels.push(label_name);
}
@@ -767,8 +769,14 @@ async fn edit_pr_labels(
.await?;
let opts = forgejo_api::structs::DeleteLabelsOption { updated_at: None };
for id in rm_ids {
- api.issue_remove_label(repo.owner(), repo.name(), pr_number, id, opts.clone())
- .await?;
+ api.issue_remove_label(
+ repo.owner(),
+ repo.name(),
+ pr_number,
+ id as u64,
+ opts.clone(),
+ )
+ .await?;
}
if !unknown_labels.is_empty() {
@@ -989,7 +997,7 @@ async fn merge_pr(
head_commit_id: None,
merge_when_checks_succeed: None,
};
- let pr_number = pr_info.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr_info.number.ok_or_eyre("pr does not have number")? as u64;
api.repo_merge_pull_request(repo.owner(), repo.name(), pr_number, request)
.await?;
@@ -1162,7 +1170,7 @@ async fn view_diff(
editor: bool,
) -> eyre::Result<()> {
let pr = try_get_pr(repo, api, pr).await?;
- let pr_number = pr.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
let diff_type = if patch { "patch" } else { "diff" };
let diff = api
@@ -1188,7 +1196,7 @@ async fn view_diff(
async fn view_pr_files(repo: &RepoName, api: &Forgejo, pr: Option<u64>) -> eyre::Result<()> {
let pr = try_get_pr(repo, api, pr).await?;
- let pr_number = pr.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
let crate::SpecialRender {
bright_red,
@@ -1234,7 +1242,7 @@ async fn view_pr_commits(
oneline: bool,
) -> eyre::Result<()> {
let pr = try_get_pr(repo, api, pr).await?;
- let pr_number = pr.number.ok_or_eyre("pr does not have number")?;
+ let pr_number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
let query = RepoGetPullRequestCommitsQuery {
limit: Some(u32::MAX),
@@ -1343,7 +1351,7 @@ async fn try_get_pr_number(
let pr = guess_pr(repo, api)
.await
.wrap_err("could not guess pull request number, please specify")?;
- let number = pr.number.ok_or_eyre("pr does not have number")?;
+ let number = pr.number.ok_or_eyre("pr does not have number")? as u64;
let repo = repo_name_from_pr(&pr)?;
(repo, number)
}
diff --git a/src/release.rs b/src/release.rs
index 2c9d065..716c508 100644
--- a/src/release.rs
+++ b/src/release.rs
@@ -218,6 +218,7 @@ async fn create_release(
};
let release_opt = forgejo_api::structs::CreateReleaseOption {
+ hide_archive_links: None,
body,
draft: Some(draft),
name: Some(name.clone()),
@@ -247,7 +248,7 @@ async fn create_release(
};
let id = release
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))? as u64;
api.repo_create_release_attachment(
repo.owner(),
repo.name(),
@@ -287,6 +288,7 @@ async fn edit_release(
None => None,
};
let release_edit = forgejo_api::structs::EditReleaseOption {
+ hide_archive_links: None,
name: rename,
tag_name: tag,
body,
@@ -296,7 +298,7 @@ async fn edit_release(
};
let id = release
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))? as u64;
api.repo_edit_release(repo.owner(), repo.name(), id, release_edit)
.await?;
Ok(())
@@ -449,7 +451,7 @@ async fn create_asset(
let id = find_release(repo, api, &release)
.await?
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))? as u64;
let query = RepoCreateReleaseAttachmentQuery {
name: Some(asset.to_owned()),
};
@@ -484,10 +486,10 @@ async fn delete_asset(
.ok_or_else(|| eyre!("asset not found"))?;
let release_id = release
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))? as u64;
let asset_id = asset
.id
- .ok_or_else(|| eyre::eyre!("asset does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("asset does not have id"))? as u64;
api.repo_delete_release_attachment(repo.owner(), repo.name(), release_id, asset_id)
.await?;
println!("Removed attachment `{}` from {}", asset_name, release_name);
@@ -530,10 +532,12 @@ async fn download_asset(
.ok_or_else(|| eyre!("asset not found"))?;
let release_id = release
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?
+ as u64;
let asset_id = asset
.id
- .ok_or_else(|| eyre::eyre!("asset does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("asset does not have id"))?
+ as u64;
api.download_release_attachment(repo.owner(), repo.name(), release_id, asset_id)
.await?
.to_vec()
@@ -593,7 +597,7 @@ async fn delete_release(
let id = find_release(repo, api, &name)
.await?
.id
- .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ .ok_or_else(|| eyre::eyre!("release does not have id"))? as u64;
api.repo_delete_release(repo.owner(), repo.name(), id)
.await?;
}
diff --git a/src/user.rs b/src/user.rs
index 5d7647a..2b12867 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -613,7 +613,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.ok_or_eyre("actor does not have name")?;
let op_type = activity
.op_type
- .as_deref()
+ .as_ref()
.ok_or_eyre("activity does not have op type")?;
// do not add ? to these. they are here to make each branch smaller
@@ -643,8 +643,9 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
}
print!("");
+ use forgejo_api::structs::ActivityOpType;
match op_type {
- "create_repo" => {
+ ActivityOpType::CreateRepo => {
let repo = repo?;
let full_name = repo
.full_name
@@ -664,7 +665,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
}
}
}
- "rename_repo" => {
+ ActivityOpType::RenameRepo => {
let repo = repo?;
let content = content?;
let full_name = repo
@@ -673,7 +674,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.ok_or_eyre("repo does not have full name")?;
println!("{bold}{actor_name}{reset} renamed repository from {bold}{yellow}\"{content}\"{reset} to {bold}{yellow}{full_name}{reset}");
}
- "star_repo" => {
+ ActivityOpType::StarRepo => {
let repo = repo?;
let full_name = repo
.full_name
@@ -683,7 +684,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
"{bold}{actor_name}{reset} starred repository {bold}{yellow}{full_name}{reset}"
);
}
- "watch_repo" => {
+ ActivityOpType::WatchRepo => {
let repo = repo?;
let full_name = repo
.full_name
@@ -693,7 +694,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
"{bold}{actor_name}{reset} watched repository {bold}{yellow}{full_name}{reset}"
);
}
- "commit_repo" => {
+ ActivityOpType::CommitRepo => {
let repo = repo?;
let full_name = repo
.full_name
@@ -708,15 +709,15 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
println!("{bold}{actor_name}{reset} pushed to {bold}{bright_cyan}{branch}{reset} on {bold}{yellow}{full_name}{reset}");
}
}
- "create_issue" => {
+ ActivityOpType::CreateIssue => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} opened issue {bold}{yellow}{name}#{id}{reset}");
}
- "create_pull_request" => {
+ ActivityOpType::CreatePullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} created pull request {bold}{yellow}{name}#{id}{reset}");
}
- "transfer_repo" => {
+ ActivityOpType::TransferRepo => {
let repo = repo?;
let full_name = repo
.full_name
@@ -725,7 +726,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
let content = content?;
println!("{bold}{actor_name}{reset} transfered repository {bold}{yellow}{content}{reset} to {bold}{yellow}{full_name}{reset}");
}
- "push_tag" => {
+ ActivityOpType::PushTag => {
let repo = repo?;
let full_name = repo
.full_name
@@ -738,35 +739,35 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.unwrap_or(ref_name);
println!("{bold}{actor_name}{reset} pushed tag {bold}{bright_cyan}{tag}{reset} to {bold}{yellow}{full_name}{reset}");
}
- "comment_issue" => {
+ ActivityOpType::CommentIssue => {
let (name, id) = issue_name(repo?, content?)?;
println!(
"{bold}{actor_name}{reset} commented on issue {bold}{yellow}{name}#{id}{reset}"
);
}
- "merge_pull_request" | "auto_merge_pull_request" => {
+ ActivityOpType::MergePullRequest | ActivityOpType::AutoMergePullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} merged pull request {bold}{yellow}{name}#{id}{reset}");
}
- "close_issue" => {
+ ActivityOpType::CloseIssue => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} closed issue {bold}{yellow}{name}#{id}{reset}");
}
- "reopen_issue" => {
+ ActivityOpType::ReopenIssue => {
let (name, id) = issue_name(repo?, content?)?;
println!(
"{bold}{actor_name}{reset} reopened issue {bold}{yellow}{name}#{id}{reset}"
);
}
- "close_pull_request" => {
+ ActivityOpType::ClosePullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} closed pull request {bold}{yellow}{name}#{id}{reset}");
}
- "reopen_pull_request" => {
+ ActivityOpType::ReopenPullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} reopened pull request {bold}{yellow}{name}#{id}{reset}");
}
- "delete_tag" => {
+ ActivityOpType::DeleteTag => {
let repo = repo?;
let full_name = repo
.full_name
@@ -779,7 +780,7 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.unwrap_or(ref_name);
println!("{bold}{actor_name}{reset} deleted tag {bold}{bright_cyan}{tag}{reset} from {bold}{yellow}{full_name}{reset}");
}
- "delete_branch" => {
+ ActivityOpType::DeleteBranch => {
let repo = repo?;
let full_name = repo
.full_name
@@ -792,22 +793,22 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.unwrap_or(ref_name);
println!("{bold}{actor_name}{reset} deleted branch {bold}{bright_cyan}{branch}{reset} from {bold}{yellow}{full_name}{reset}");
}
- "mirror_sync_push" => {}
- "mirror_sync_create" => {}
- "mirror_sync_delete" => {}
- "approve_pull_request" => {
+ ActivityOpType::MirrorSyncPush => {}
+ ActivityOpType::MirrorSyncCreate => {}
+ ActivityOpType::MirrorSyncDelete => {}
+ ActivityOpType::ApprovePullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} approved {bold}{yellow}{name}#{id}{reset}");
}
- "reject_pull_request" => {
+ ActivityOpType::RejectPullRequest => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} suggested changes for {bold}{yellow}{name}#{id}{reset}");
}
- "comment_pull" => {
+ ActivityOpType::CommentPull => {
let (name, id) = issue_name(repo?, content?)?;
println!("{bold}{actor_name}{reset} commented on pull request {bold}{yellow}{name}#{id}{reset}");
}
- "publish_release" => {
+ ActivityOpType::PublishRelease => {
let repo = repo?;
let full_name = repo
.full_name
@@ -816,9 +817,8 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
let content = content?;
println!("{bold}{actor_name}{reset} created release {bold}{bright_cyan}\"{content}\"{reset} to {bold}{yellow}{full_name}{reset}");
}
- "pull_review_dismissed" => {}
- "pull_request_ready_for_review" => {}
- _ => eyre::bail!("invalid op type"),
+ ActivityOpType::PullReviewDismissed => {}
+ ActivityOpType::PullRequestReadyForReview => {}
}
}
Ok(())