support list releases
This commit is contained in:
parent
5cd0635832
commit
f6939e9165
1 changed files with 54 additions and 15 deletions
69
src/main.rs
69
src/main.rs
|
@ -1,7 +1,8 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
// use time::OffsetDateTime;
|
||||||
use forgejo_api::Auth::Token;
|
use forgejo_api::Auth::Token;
|
||||||
use forgejo_api::Forgejo;
|
use forgejo_api::Forgejo;
|
||||||
use forgejo_api::structs::CreateReleaseOption;
|
use forgejo_api::structs::{CreateReleaseOption, RepoListReleasesQuery};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
@ -27,7 +28,7 @@ enum Commands {
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
enum ReleaseSubCommands {
|
enum ReleaseSubCommands {
|
||||||
/// A sub-subcommand
|
/// A sub-subcommand
|
||||||
NewRelease {
|
New {
|
||||||
alias: String,
|
alias: String,
|
||||||
tag: String,
|
tag: String,
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
|
@ -35,9 +36,8 @@ enum ReleaseSubCommands {
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Another sub-subcommand
|
/// Another sub-subcommand
|
||||||
ListReleases {
|
List {
|
||||||
#[clap(short, long)]
|
alias: String,
|
||||||
output: String,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,10 @@ async fn handle_new_release(
|
||||||
|
|
||||||
let option = CreateReleaseOption {
|
let option = CreateReleaseOption {
|
||||||
tag_name: tag.to_string(),
|
tag_name: tag.to_string(),
|
||||||
name: Some(format!("Release {}", tag)),
|
name: Some(format!("{}", tag)),
|
||||||
body: Some(format!("Release notes for {}", tag)),
|
body: Some(format!("Release notes for {}", tag)),
|
||||||
hide_archive_links: Some(false),
|
hide_archive_links: Some(false),
|
||||||
target_commitish: Some(tag.to_string()),
|
target_commitish: target.clone(),
|
||||||
draft: None,
|
draft: None,
|
||||||
prerelease: None,
|
prerelease: None,
|
||||||
};
|
};
|
||||||
|
@ -89,12 +89,51 @@ async fn handle_new_release(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_another_sub_sub_command(output: &str) {
|
async fn handle_list_releases(config: &config::Config, alias: &str) -> Result<(), String> {
|
||||||
println!("Executing AnotherSubSubCommand with output: {}", output);
|
println!("Listing releases for all repositories");
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_another_command(option: &str) {
|
let repo = config.repos.get(alias).map_or_else(
|
||||||
println!("Executing AnotherCommand with option: {}", option);
|
|| Err(format!("No repository found with alias: {}", alias)),
|
||||||
|
|repo| {
|
||||||
|
println!("Using repository: {} owned by {}", repo.repo, repo.owner);
|
||||||
|
// Here you would typically call the Forgejo API to create a new release
|
||||||
|
// For example:
|
||||||
|
Ok(repo)
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let token = Token(&repo.token);
|
||||||
|
let url = Url::parse(&repo.hostname).map_err(|e| {
|
||||||
|
eprintln!("Failed to parse URL: {}", e);
|
||||||
|
e.to_string()
|
||||||
|
})?;
|
||||||
|
let forgejo = Forgejo::new(token, url).map_err(|e| {
|
||||||
|
eprintln!("Failed to create Forgejo client: {}", e);
|
||||||
|
e.to_string()
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let query = forgejo_api::structs::RepoListReleasesQuery {
|
||||||
|
draft: None,
|
||||||
|
page: None,
|
||||||
|
q: None,
|
||||||
|
pre_release: None,
|
||||||
|
limit: Some(100),
|
||||||
|
};
|
||||||
|
let result_query = forgejo.repo_list_releases(&repo.owner, &repo.repo, query).await.map_err(|e| {
|
||||||
|
eprintln!("Failed to list releases: {}", e);
|
||||||
|
e.to_string()
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for release in result_query.1 {
|
||||||
|
println!(
|
||||||
|
"Release: {}, Tag: {}, Created at: {}",
|
||||||
|
release.name.unwrap_or_default(),
|
||||||
|
release.tag_name.unwrap_or("N/A".to_string()),
|
||||||
|
release.created_at.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -106,11 +145,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
match args.command {
|
match args.command {
|
||||||
Commands::Release(subcommand) => {
|
Commands::Release(subcommand) => {
|
||||||
match subcommand {
|
match subcommand {
|
||||||
ReleaseSubCommands::NewRelease { alias, tag, target } => {
|
ReleaseSubCommands::New { alias, tag, target } => {
|
||||||
handle_new_release(&config, &alias, &tag, &target).await?
|
handle_new_release(&config, &alias, &tag, &target).await?
|
||||||
}
|
}
|
||||||
ReleaseSubCommands::ListReleases { output } => {
|
ReleaseSubCommands::List { alias } => {
|
||||||
handle_another_sub_sub_command(&output)
|
handle_list_releases(&config, &alias).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Uncomment the following lines if you want to use the dispatch macro
|
// Uncomment the following lines if you want to use the dispatch macro
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue