summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-03-21 22:48:39 +0100
committerCyborus <cyborus@cyborus.xyz>2024-03-21 22:48:39 +0100
commit6cbd80e19f7212d5b7a07c327d87919efc8016f7 (patch)
tree7ecf707fc5c894d90e29d40a385d01c6b9a39948 /src
parentMerge pull request 'update `forgejo-api`' (#36) from update-api into main (diff)
downloadforgejo-cli-6cbd80e19f7212d5b7a07c327d87919efc8016f7.tar.xz
forgejo-cli-6cbd80e19f7212d5b7a07c327d87919efc8016f7.zip
update to new version of `forgejo-api`
Diffstat (limited to '')
-rw-r--r--src/issues.rs264
-rw-r--r--src/release.rs214
-rw-r--r--src/repo.rs43
3 files changed, 367 insertions, 154 deletions
diff --git a/src/issues.rs b/src/issues.rs
index cb33549..1f1d07d 100644
--- a/src/issues.rs
+++ b/src/issues.rs
@@ -1,6 +1,9 @@
use clap::Subcommand;
use eyre::eyre;
-use forgejo_api::{Comment, CreateIssueCommentOption, EditIssueOption, Forgejo, IssueCommentQuery};
+use forgejo_api::structs::{
+ Comment, CreateIssueCommentOption, CreateIssueOption, EditIssueOption, IssueGetCommentsQuery,
+};
+use forgejo_api::Forgejo;
use crate::repo::RepoInfo;
@@ -52,11 +55,11 @@ pub enum State {
Closed,
}
-impl From<State> for forgejo_api::State {
+impl From<State> for forgejo_api::structs::IssueListIssuesQueryState {
fn from(value: State) -> Self {
match value {
- State::Open => forgejo_api::State::Open,
- State::Closed => forgejo_api::State::Closed,
+ State::Open => forgejo_api::structs::IssueListIssuesQueryState::Open,
+ State::Closed => forgejo_api::structs::IssueListIssuesQueryState::Closed,
}
}
}
@@ -133,30 +136,52 @@ async fn create_issue(
}
};
let issue = api
- .create_issue(
+ .issue_create_issue(
repo.owner(),
repo.name(),
- forgejo_api::CreateIssueOption {
+ CreateIssueOption {
body: Some(body),
title,
- ..Default::default()
+ assignee: None,
+ assignees: None,
+ closed: None,
+ due_date: None,
+ labels: None,
+ milestone: None,
+ r#ref: None,
},
)
.await?;
- eprintln!("created issue #{}: {}", issue.number, issue.title);
+ let number = issue
+ .number
+ .ok_or_else(|| eyre::eyre!("issue does not have number"))?;
+ let title = issue
+ .title
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("issue does not have title"))?;
+ eprintln!("created issue #{}: {}", number, title);
Ok(())
}
async fn view_issue(repo: &RepoInfo, api: &Forgejo, id: u64) -> eyre::Result<()> {
- let issue = api
- .get_issue(repo.owner(), repo.name(), id)
- .await?
- .ok_or_else(|| eyre!("issue {id} does not exist"))?;
- println!("#{}: {}", id, issue.title);
- println!("By {}", issue.user.login);
- if !issue.body.is_empty() {
+ let issue = api.issue_get_issue(repo.owner(), repo.name(), id).await?;
+ let title = issue
+ .title
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("issue does not have title"))?;
+ let user = issue
+ .user
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("issue 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 {}", username);
+ if let Some(body) = &issue.body {
println!();
- println!("{}", issue.body);
+ println!("{}", body);
}
Ok(())
}
@@ -172,16 +197,22 @@ async fn view_issues(
let labels = labels
.map(|s| s.split(',').map(|s| s.to_string()).collect::<Vec<_>>())
.unwrap_or_default();
- let query = forgejo_api::IssueQuery {
- query: query_str,
- labels,
+ let query = forgejo_api::structs::IssueListIssuesQuery {
+ q: query_str,
+ labels: Some(labels.join(",")),
created_by: creator,
assigned_by: assignee,
state: state.map(|s| s.into()),
- ..Default::default()
+ r#type: None,
+ milestones: None,
+ since: None,
+ before: None,
+ mentioned_by: None,
+ page: None,
+ limit: None,
};
let issues = api
- .get_repo_issues(repo.owner(), repo.name(), query)
+ .issue_list_issues(repo.owner(), repo.name(), query)
.await?;
if issues.len() == 1 {
println!("1 issue");
@@ -189,58 +220,97 @@ async fn view_issues(
println!("{} issues", issues.len());
}
for issue in issues {
- println!(
- "#{}: {} (by {})",
- issue.number, issue.title, issue.user.login
- );
+ let number = issue
+ .number
+ .ok_or_else(|| eyre::eyre!("issue does not have number"))?;
+ let title = issue
+ .title
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("issue does not have title"))?;
+ let user = issue
+ .user
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("issue does not have creator"))?;
+ let username = user
+ .login
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("user does not have login"))?;
+ println!("#{}: {} (by {})", number, title, username);
}
Ok(())
}
async fn view_comment(repo: &RepoInfo, api: &Forgejo, id: u64, idx: usize) -> eyre::Result<()> {
+ let query = IssueGetCommentsQuery {
+ since: None,
+ before: None,
+ };
let comments = api
- .get_issue_comments(repo.owner(), repo.name(), id, IssueCommentQuery::default())
+ .issue_get_comments(repo.owner(), repo.name(), id, query)
.await?;
let comment = comments
.get(idx)
.ok_or_else(|| eyre!("comment {idx} doesn't exist"))?;
- print_comment(&comment);
+ print_comment(&comment)?;
Ok(())
}
async fn view_comments(repo: &RepoInfo, api: &Forgejo, id: u64) -> eyre::Result<()> {
+ let query = IssueGetCommentsQuery {
+ since: None,
+ before: None,
+ };
let comments = api
- .get_issue_comments(repo.owner(), repo.name(), id, IssueCommentQuery::default())
+ .issue_get_comments(repo.owner(), repo.name(), id, query)
.await?;
for comment in comments {
- print_comment(&comment);
+ print_comment(&comment)?;
}
Ok(())
}
-fn print_comment(comment: &Comment) {
- println!("{} said:", comment.user.login);
- println!("{}", comment.body);
- if !comment.assets.is_empty() {
- println!("({} attachments)", comment.assets.len());
+fn print_comment(comment: &Comment) -> eyre::Result<()> {
+ let body = comment
+ .body
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("comment does not have body"))?;
+ let user = comment
+ .user
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("comment does not have user"))?;
+ let username = user
+ .login
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("user does not have login"))?;
+ println!("{} said:", username);
+ println!("{}", body);
+ let assets = comment
+ .assets
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("comment does not have assets"))?;
+ if !assets.is_empty() {
+ println!("({} attachments)", assets.len());
}
+ Ok(())
}
async fn browse_issue(repo: &RepoInfo, api: &Forgejo, id: Option<u64>) -> eyre::Result<()> {
match id {
Some(id) => {
- let issue = api
- .get_issue(repo.owner(), repo.name(), id)
- .await?
- .ok_or_else(|| eyre!("issue {id} does not exist"))?;
- open::that(issue.html_url.as_str())?;
+ 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
- .get_repo(repo.owner(), repo.name())
- .await?
- .ok_or_else(|| eyre!("repo {}/{} does not exist", repo.owner(), repo.name()))?;
- open::that(format!("{}/issues", repo.html_url))?;
+ 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))?;
}
}
Ok(())
@@ -260,13 +330,13 @@ async fn add_comment(
body
}
};
- api.create_comment(
+ api.issue_create_comment(
repo.owner(),
repo.name(),
issue,
- forgejo_api::CreateIssueCommentOption {
+ forgejo_api::structs::CreateIssueCommentOption {
body,
- ..Default::default()
+ updated_at: None,
},
)
.await?;
@@ -282,12 +352,14 @@ async fn edit_title(
let new_title = match new_title {
Some(s) => s,
None => {
- let mut issue_info = api
- .get_issue(repo.owner(), repo.name(), issue)
- .await?
- .ok_or_else(|| eyre!("issue {issue} does not exist"))?;
- crate::editor(&mut issue_info.title, Some("md")).await?;
- issue_info.title
+ let issue_info = api
+ .issue_get_issue(repo.owner(), repo.name(), issue)
+ .await?;
+ let mut title = issue_info
+ .title
+ .ok_or_else(|| eyre::eyre!("issue does not have title"))?;
+ crate::editor(&mut title, Some("md")).await?;
+ title
}
};
if new_title.is_empty() {
@@ -296,13 +368,21 @@ async fn edit_title(
if new_title.contains('\n') {
eyre::bail!("title cannot contain newlines");
}
- api.edit_issue(
+ api.issue_edit_issue(
repo.owner(),
repo.name(),
issue,
- forgejo_api::EditIssueOption {
+ forgejo_api::structs::EditIssueOption {
title: Some(new_title.trim().to_owned()),
- ..Default::default()
+ assignee: None,
+ assignees: None,
+ body: None,
+ due_date: None,
+ milestone: None,
+ r#ref: None,
+ state: None,
+ unset_due_date: None,
+ updated_at: None,
},
)
.await?;
@@ -318,21 +398,31 @@ async fn edit_body(
let new_body = match new_body {
Some(s) => s,
None => {
- let mut issue_info = api
- .get_issue(repo.owner(), repo.name(), issue)
- .await?
- .ok_or_else(|| eyre!("issue {issue} does not exist"))?;
- crate::editor(&mut issue_info.body, Some("md")).await?;
- issue_info.body
+ let issue_info = api
+ .issue_get_issue(repo.owner(), repo.name(), issue)
+ .await?;
+ let mut body = issue_info
+ .body
+ .ok_or_else(|| eyre::eyre!("issue does not have body"))?;
+ crate::editor(&mut body, Some("md")).await?;
+ body
}
};
- api.edit_issue(
+ api.issue_edit_issue(
repo.owner(),
repo.name(),
issue,
- forgejo_api::EditIssueOption {
+ forgejo_api::structs::EditIssueOption {
body: Some(new_body),
- ..Default::default()
+ assignee: None,
+ assignees: None,
+ due_date: None,
+ milestone: None,
+ r#ref: None,
+ state: None,
+ title: None,
+ unset_due_date: None,
+ updated_at: None,
},
)
.await?;
@@ -347,11 +437,14 @@ async fn edit_comment(
new_body: Option<String>,
) -> eyre::Result<()> {
let comments = api
- .get_issue_comments(
+ .issue_get_comments(
repo.owner(),
repo.name(),
issue,
- forgejo_api::IssueCommentQuery::default(),
+ IssueGetCommentsQuery {
+ since: None,
+ before: None,
+ },
)
.await?;
let comment = comments
@@ -360,18 +453,24 @@ async fn edit_comment(
let new_body = match new_body {
Some(s) => s,
None => {
- let mut body = comment.body.clone();
+ let mut body = comment
+ .body
+ .clone()
+ .ok_or_else(|| eyre::eyre!("issue does not have body"))?;
crate::editor(&mut body, Some("md")).await?;
body
}
};
- api.edit_comment(
+ let id = comment
+ .id
+ .ok_or_else(|| eyre::eyre!("comment does not have id"))?;
+ api.issue_edit_comment(
repo.owner(),
repo.name(),
- comment.id,
- forgejo_api::EditIssueCommentOption {
+ id,
+ forgejo_api::structs::EditIssueCommentOption {
body: new_body,
- ..Default::default()
+ updated_at: None,
},
)
.await?;
@@ -394,16 +493,27 @@ async fn close_issue(
}
};
- let opt = CreateIssueCommentOption { body };
- api.create_comment(repo.owner(), repo.name(), issue, opt)
+ let opt = CreateIssueCommentOption {
+ body,
+ updated_at: None,
+ };
+ api.issue_create_comment(repo.owner(), repo.name(), issue, opt)
.await?;
}
let edit = EditIssueOption {
- state: Some(forgejo_api::State::Closed),
- ..Default::default()
+ state: Some("closed".into()),
+ assignee: None,
+ assignees: None,
+ body: None,
+ due_date: None,
+ milestone: None,
+ r#ref: None,
+ title: None,
+ unset_due_date: None,
+ updated_at: None,
};
- api.edit_issue(repo.owner(), repo.name(), issue, edit)
+ api.issue_edit_issue(repo.owner(), repo.name(), issue, edit)
.await?;
Ok(())
diff --git a/src/release.rs b/src/release.rs
index 9661fb5..12e4923 100644
--- a/src/release.rs
+++ b/src/release.rs
@@ -1,6 +1,9 @@
use clap::Subcommand;
use eyre::{bail, eyre};
-use forgejo_api::Forgejo;
+use forgejo_api::{
+ structs::{RepoCreateReleaseAttachmentQuery, RepoListReleasesQuery},
+ Forgejo,
+};
use tokio::io::AsyncWriteExt;
use crate::{keys::KeyInfo, repo::RepoInfo};
@@ -170,12 +173,12 @@ async fn create_release(
(Some(tag), None) => tag,
(None, Some(tag)) => {
let tag = tag.unwrap_or_else(|| name.clone());
- let opt = forgejo_api::CreateTagOption {
+ let opt = forgejo_api::structs::CreateTagOption {
message: None,
tag_name: tag.clone(),
target: branch,
};
- api.create_tag(repo.owner(), repo.name(), opt).await?;
+ api.repo_create_tag(repo.owner(), repo.name(), opt).await?;
tag
}
(Some(_), Some(_)) => {
@@ -184,25 +187,25 @@ async fn create_release(
};
let body = match body {
- Some(Some(body)) => body,
+ Some(Some(body)) => Some(body),
Some(None) => {
let mut s = String::new();
crate::editor(&mut s, Some("md")).await?;
- s
+ Some(s)
}
- None => String::new(),
+ None => None,
};
- let release_opt = forgejo_api::CreateReleaseOption {
+ let release_opt = forgejo_api::structs::CreateReleaseOption {
body,
- draft,
- name,
- prerelease,
+ draft: Some(draft),
+ name: Some(name),
+ prerelease: Some(prerelease),
tag_name,
target_commitish: None,
};
let release = api
- .create_release(repo.owner(), repo.name(), release_opt)
+ .repo_create_release(repo.owner(), repo.name(), release_opt)
.await?;
for attachment in attachments {
@@ -218,12 +221,18 @@ async fn create_release(
(file, asset)
}
};
- api.create_release_attachment(
+ let query = RepoCreateReleaseAttachmentQuery {
+ name: Some(asset.into()),
+ };
+ let id = release
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ api.repo_create_release_attachment(
repo.owner(),
repo.name(),
- release.id,
- asset,
+ id,
tokio::fs::read(file).await?,
+ query,
)
.await?;
}
@@ -245,13 +254,16 @@ async fn edit_release(
let body = match body {
Some(Some(body)) => Some(body),
Some(None) => {
- let mut s = release.body.clone();
+ let mut s = release
+ .body
+ .clone()
+ .ok_or_else(|| eyre::eyre!("release does not have body"))?;
crate::editor(&mut s, Some("md")).await?;
Some(s)
}
None => None,
};
- let release_edit = forgejo_api::EditReleaseOption {
+ let release_edit = forgejo_api::structs::EditReleaseOption {
name: rename,
tag_name: tag,
body,
@@ -259,7 +271,10 @@ async fn edit_release(
prerelease,
target_commitish: None,
};
- api.edit_release(repo.owner(), repo.name(), release.id, release_edit)
+ let id = release
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ api.repo_edit_release(repo.owner(), repo.name(), id, release_edit)
.await?;
Ok(())
}
@@ -270,15 +285,31 @@ async fn list_releases(
prerelease: bool,
draft: bool,
) -> eyre::Result<()> {
- let query = forgejo_api::ReleaseQuery {
- prerelease: Some(prerelease),
+ let query = forgejo_api::structs::RepoListReleasesQuery {
+ pre_release: Some(prerelease),
draft: Some(draft),
- ..Default::default()
+ per_page: None,
+ page: None,
+ limit: None,
};
- let releases = api.get_releases(repo.owner(), repo.name(), query).await?;
+ let releases = api
+ .repo_list_releases(repo.owner(), repo.name(), query)
+ .await?;
for release in releases {
- print!("{}", release.name);
- match (release.draft, release.prerelease) {
+ let name = release
+ .name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have name"))?;
+ let draft = release
+ .draft
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have draft"))?;
+ let prerelease = release
+ .prerelease
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have prerelease"))?;
+ print!("{}", name);
+ match (draft, prerelease) {
(false, false) => (),
(true, false) => print!(" (draft)"),
(false, true) => print!(" (prerelease)"),
@@ -296,30 +327,56 @@ async fn view_release(
by_tag: bool,
) -> eyre::Result<()> {
let release = if by_tag {
- api.get_release_by_tag(repo.owner(), repo.name(), &name)
+ api.repo_get_release_by_tag(repo.owner(), repo.name(), &name)
.await?
- .ok_or_else(|| eyre!("release not found"))?
} else {
find_release(repo, api, &name).await?
};
- println!("{}", release.name);
- print!("By {} on ", release.author.login);
- release.created_at.format_into(
+ let name = release
+ .name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have name"))?;
+ let author = release
+ .author
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have author"))?;
+ let login = author
+ .login
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("autho does not have login"))?;
+ let created_at = release
+ .created_at
+ .ok_or_else(|| eyre::eyre!("release does not have created_at"))?;
+ println!("{}", name);
+ print!("By {} on ", login);
+ created_at.format_into(
&mut std::io::stdout(),
&time::format_description::well_known::Rfc2822,
)?;
println!();
- if !release.body.is_empty() {
+ let body = release
+ .body
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have body"))?;
+ if !body.is_empty() {
println!();
- for line in release.body.lines() {
+ for line in body.lines() {
println!("> {line}");
}
println!();
}
- if !release.assets.is_empty() {
- println!("{} assets", release.assets.len() + 2);
- for asset in release.assets {
- println!("- {}", asset.name);
+ let assets = release
+ .assets
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have assets"))?;
+ if !assets.is_empty() {
+ println!("{} assets", assets.len() + 2);
+ for asset in assets {
+ let name = asset
+ .name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("asset does not have name"))?;
+ println!("- {}", name);
}
println!("- source.zip");
println!("- source.tar.gz");
@@ -331,7 +388,11 @@ async fn browse_release(repo: &RepoInfo, api: &Forgejo, name: Option<String>) ->
match name {
Some(name) => {
let release = find_release(repo, api, &name).await?;
- open::that(release.html_url.as_str())?;
+ let html_url = release
+ .html_url
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have html_url"))?;
+ open::that(html_url.as_str())?;
}
None => {
let mut url = repo.url().clone();
@@ -360,13 +421,19 @@ async fn create_asset(
(&*file, asset)
}
};
- let id = find_release(repo, api, &release).await?.id;
- api.create_release_attachment(
+ let id = find_release(repo, api, &release)
+ .await?
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ let query = RepoCreateReleaseAttachmentQuery {
+ name: Some(asset.to_owned()),
+ };
+ api.repo_create_release_attachment(
repo.owner(),
repo.name(),
id,
- asset,
tokio::fs::read(file).await?,
+ query,
)
.await?;
@@ -380,12 +447,21 @@ async fn delete_asset(
asset: String,
) -> eyre::Result<()> {
let release = find_release(repo, api, &release).await?;
- let asset = release
+ let assets = release
.assets
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have assets"))?;
+ let asset = assets
.iter()
- .find(|a| a.name == asset)
+ .find(|a| a.name.as_ref() == Some(&asset))
.ok_or_else(|| eyre!("asset not found"))?;
- api.delete_release_attachment(repo.owner(), repo.name(), release.id, asset.id)
+ let release_id = release
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ let asset_id = asset
+ .id
+ .ok_or_else(|| eyre::eyre!("asset does not have id"))?;
+ api.repo_delete_release_attachment(repo.owner(), repo.name(), release_id, asset_id)
.await?;
Ok(())
}
@@ -400,24 +476,41 @@ async fn download_asset(
let release = find_release(repo, api, &release).await?;
let file = match &*asset {
"source.zip" => {
- api.download_zip_archive(repo.owner(), repo.name(), &release.tag_name)
+ let tag_name = release
+ .tag_name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have tag_name"))?;
+ api.repo_get_archive(repo.owner(), repo.name(), &format!("{}.zip", tag_name))
.await?
}
"source.tar.gz" => {
- api.download_tarball_archive(repo.owner(), repo.name(), &release.tag_name)
+ let tag_name = release
+ .tag_name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have tag_name"))?;
+ api.repo_get_archive(repo.owner(), repo.name(), &format!("{}.tar.gz", tag_name))
.await?
}
name => {
- let asset = release
+ let assets = release
.assets
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("release does not have assets"))?;
+ let asset = assets
.iter()
- .find(|a| a.name == name)
+ .find(|a| a.name.as_deref() == Some(name))
.ok_or_else(|| eyre!("asset not found"))?;
- api.download_release_attachment(repo.owner(), repo.name(), release.id, asset.id)
+ let release_id = release
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ let asset_id = asset
+ .id
+ .ok_or_else(|| eyre::eyre!("asset does not have id"))?;
+ api.download_release_attachment(repo.owner(), repo.name(), release_id, asset_id)
.await?
+ .to_vec()
}
};
- let file = file.ok_or_else(|| eyre!("asset not found"))?;
let output = output
.as_deref()
.unwrap_or_else(|| std::path::Path::new(&asset));
@@ -436,17 +529,20 @@ async fn find_release(
repo: &RepoInfo,
api: &Forgejo,
name: &str,
-) -> eyre::Result<forgejo_api::Release> {
+) -> eyre::Result<forgejo_api::structs::Release> {
+ let query = RepoListReleasesQuery {
+ draft: None,
+ pre_release: None,
+ per_page: None,
+ page: None,
+ limit: None,
+ };
let mut releases = api
- .get_releases(
- repo.owner(),
- repo.name(),
- forgejo_api::ReleaseQuery::default(),
- )
+ .repo_list_releases(repo.owner(), repo.name(), query)
.await?;
let idx = releases
.iter()
- .position(|r| r.name == name)
+ .position(|r| r.name.as_deref() == Some(name))
.ok_or_else(|| eyre!("release not found"))?;
Ok(releases.swap_remove(idx))
}
@@ -458,11 +554,15 @@ async fn delete_release(
by_tag: bool,
) -> eyre::Result<()> {
if by_tag {
- api.delete_release_by_tag(repo.owner(), repo.name(), &name)
+ api.repo_delete_release_by_tag(repo.owner(), repo.name(), &name)
.await?;
} else {
- let id = find_release(repo, api, &name).await?.id;
- api.delete_release(repo.owner(), repo.name(), id).await?;
+ let id = find_release(repo, api, &name)
+ .await?
+ .id
+ .ok_or_else(|| eyre::eyre!("release does not have id"))?;
+ api.repo_delete_release(repo.owner(), repo.name(), id)
+ .await?;
}
Ok(())
}
diff --git a/src/repo.rs b/src/repo.rs
index a3521a4..c02cf9d 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -1,6 +1,6 @@
use clap::Subcommand;
use eyre::eyre;
-use forgejo_api::CreateRepoOption;
+use forgejo_api::structs::CreateRepoOption;
use url::Url;
pub struct RepoInfo {
@@ -110,26 +110,34 @@ impl RepoCommand {
let host = Url::parse(&host)?;
let api = keys.get_api(&host)?;
let repo_spec = CreateRepoOption {
- auto_init: false,
- default_branch: "main".into(),
+ auto_init: Some(false),
+ default_branch: Some("main".into()),
description,
- gitignores: String::new(),
- issue_labels: String::new(),
- license: String::new(),
+ gitignores: None,
+ issue_labels: None,
+ license: None,
name: repo.clone(),
- private,
- readme: String::new(),
- template: false,
- trust_model: forgejo_api::TrustModel::Default,
+ private: Some(private),
+ readme: Some(String::new()),
+ template: Some(false),
+ trust_model: Some(forgejo_api::structs::CreateRepoOptionTrustModel::Default),
};
- let new_repo = api.create_repo(repo_spec).await?;
- eprintln!("created new repo at {}", host.join(&new_repo.full_name)?);
+ let new_repo = api.create_current_user_repo(repo_spec).await?;
+ let full_name = new_repo
+ .full_name
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("new_repo does not have full_name"))?;
+ eprintln!("created new repo at {}", host.join(&full_name)?);
if set_upstream.is_some() || push {
let repo = git2::Repository::open(".")?;
let upstream = set_upstream.as_deref().unwrap_or("origin");
- let mut remote = repo.remote(upstream, new_repo.clone_url.as_str())?;
+ let clone_url = new_repo
+ .clone_url
+ .as_ref()
+ .ok_or_else(|| eyre::eyre!("new_repo does not have clone_url"))?;
+ let mut remote = repo.remote(upstream, clone_url.as_str())?;
if push {
let head = repo.head()?;
@@ -153,13 +161,8 @@ impl RepoCommand {
RepoCommand::Info => {
let repo = RepoInfo::get_current(remote_name)?;
let api = keys.get_api(&repo.host_url())?;
- let repo = api.get_repo(repo.owner(), repo.name()).await?;
- match repo {
- Some(repo) => {
- dbg!(repo);
- }
- None => eprintln!("repo not found"),
- }
+ let repo = api.repo_get(repo.owner(), repo.name()).await?;
+ dbg!(repo);
}
RepoCommand::Browse => {
let repo = RepoInfo::get_current(remote_name)?;