summaryrefslogtreecommitdiffstats
path: root/src/repo.rs
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/repo.rs
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/repo.rs43
1 files changed, 23 insertions, 20 deletions
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)?;