Autoformat the whole thing

I've been putting this off because I don't want to have many small
formatting commits, and I don't have any kind of pre-commit hook to do
it for me. So here it is :v
This commit is contained in:
2025-06-01 13:28:06 -05:00
parent 442c8a97f8
commit e0c21fceaf
10 changed files with 64 additions and 69 deletions

View File

@@ -1,4 +1,3 @@
pub mod packages; pub mod packages;
pub mod release; pub mod release;
pub mod release_attachment; pub mod release_attachment;

View File

@@ -1,10 +1,8 @@
pub fn list_packages() {}
pub fn list_packages(){} pub fn get_packages() {}
pub fn get_packages(){} pub fn delete_package() {}
pub fn delete_package(){} pub fn list_package_files() {}
pub fn list_package_files(){} pub fn get_latest_package_version() {}
pub fn get_latest_package_version(){} pub fn link_package() {}
pub fn link_package(){} pub fn unlink_package() {}
pub fn unlink_package(){} pub fn search_packages() {}
pub fn search_packages(){}

View File

@@ -1,12 +1,19 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
structs::{self, release::{CreateReleaseOption, Release}}, ApiError, Result ApiError, Result,
structs::{
self,
release::{CreateReleaseOption, Release},
},
}; };
pub fn get_release(id: u64) -> Result<Release> { todo!(); } pub fn get_release(id: u64) -> Result<Release> {
pub fn get_latest_release() -> Result<Release> { todo!(); } todo!();
}
pub fn get_latest_release() -> Result<Release> {
todo!();
}
pub async fn list_releases( pub async fn list_releases(
client: &reqwest::Client, client: &reqwest::Client,
@@ -14,14 +21,8 @@ pub async fn list_releases(
repo: &str, repo: &str,
) -> Result<Vec<Release>> { ) -> Result<Vec<Release>> {
let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases/"); let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases/");
let req = client let req = client.get(request_url).send().await;
.get(request_url) let response = req.map_err(|reqwest_err| crate::Error::WrappedReqwestErr(reqwest_err))?;
.send()
.await;
let response = req
.map_err(|reqwest_err| {
crate::Error::WrappedReqwestErr(reqwest_err)
})?;
let release_list = response let release_list = response
.json::<Vec<Release>>() .json::<Vec<Release>>()
.await .await
@@ -45,7 +46,7 @@ pub async fn create_release(
client: &reqwest::Client, client: &reqwest::Client,
gitea_url: &str, gitea_url: &str,
repo: &str, repo: &str,
submission: CreateReleaseOption submission: CreateReleaseOption,
) -> Result<Release> { ) -> Result<Release> {
let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases"); let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases");
let req = client let req = client
@@ -66,10 +67,13 @@ pub async fn create_release(
} else { } else {
Err(crate::Error::ApiErrorMessage(api_error)) Err(crate::Error::ApiErrorMessage(api_error))
} }
}, }
CreateResult::Empty => panic!("How can we have 200 OK and no release info? No. Crash"), CreateResult::Empty => panic!("How can we have 200 OK and no release info? No. Crash"),
} }
} }
pub fn edit_release(id: u64) -> Result<Release> { todo!(); } pub fn edit_release(id: u64) -> Result<Release> {
pub fn delete_release(id: u64) -> Result<()> { todo!(); } todo!();
}
pub fn delete_release(id: u64) -> Result<()> {
todo!();
}

View File

@@ -1,9 +1,8 @@
use std::fs; use std::fs;
pub fn check_release_match_repo() {}
pub fn check_release_match_repo(){} pub fn get_release_attachment() {}
pub fn get_release_attachment(){} pub fn list_release_attachments() {
pub fn list_release_attachments(){
todo!(); todo!();
} }
pub async fn create_release_attachment( pub async fn create_release_attachment(
@@ -14,7 +13,7 @@ pub async fn create_release_attachment(
files: Vec<String>, files: Vec<String>,
) -> crate::Result<()> { ) -> crate::Result<()> {
let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases/{release_id}/assets"); let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases/{release_id}/assets");
// Ensure all files exists before starting the uploads // Ensure all files exists before starting the uploads
for file in &files { for file in &files {
if let Err(e) = fs::exists(file) { if let Err(e) = fs::exists(file) {
@@ -27,9 +26,8 @@ pub async fn create_release_attachment(
let data = reqwest::multipart::Part::stream(fs::read(&file).unwrap()) let data = reqwest::multipart::Part::stream(fs::read(&file).unwrap())
.file_name("attachment") .file_name("attachment")
.mime_str("text/plain")?; .mime_str("text/plain")?;
let form= reqwest::multipart::Form::new() let form = reqwest::multipart::Form::new().part("attachment", data);
.part("attachment", data);
let request = client let request = client
.post(&request_url) .post(&request_url)
@@ -40,6 +38,5 @@ pub async fn create_release_attachment(
} }
Ok(()) Ok(())
} }
pub fn edit_release_attachment(){} pub fn edit_release_attachment() {}
pub fn delete_release_attachment(){} pub fn delete_release_attachment() {}

View File

@@ -35,6 +35,6 @@ pub enum Commands {
#[arg(short, long, default_value_t = false)] #[arg(short, long, default_value_t = false)]
create: bool, create: bool,
#[arg()] #[arg()]
files: Vec<String> files: Vec<String>,
} },
} }

View File

@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod cli;
pub mod api; pub mod api;
pub mod cli;
pub mod structs; pub mod structs;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@@ -26,4 +26,3 @@ impl From<reqwest::Error> for crate::Error {
} }
type Result<T> = core::result::Result<T, Error>; type Result<T> = core::result::Result<T, Error>;

View File

@@ -1,6 +1,5 @@
use gt_tools::structs::release::{CreateReleaseOption, Release};
use gt_tools::cli::Args; use gt_tools::cli::Args;
use gt_tools::structs::release::{CreateReleaseOption, Release};
use clap::Parser; use clap::Parser;
@@ -10,10 +9,10 @@ use reqwest::header::ACCEPT;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), gt_tools::Error> { async fn main() -> Result<(), gt_tools::Error> {
let args = Args::parse(); let args = Args::parse();
let mut headers = reqwest::header::HeaderMap::new(); let mut headers = reqwest::header::HeaderMap::new();
headers.append(ACCEPT, header::HeaderValue::from_static("application/json")); headers.append(ACCEPT, header::HeaderValue::from_static("application/json"));
// Gitea expects to see "token " for token auth. // Gitea expects to see "token " for token auth.
if let Ok(token) = std::env::var("RELEASE_KEY_GITEA") { if let Ok(token) = std::env::var("RELEASE_KEY_GITEA") {
let token = format!("token {token}"); let token = format!("token {token}");
@@ -26,11 +25,8 @@ async fn main() -> Result<(), gt_tools::Error> {
match args.command { match args.command {
gt_tools::cli::Commands::ListReleases => { gt_tools::cli::Commands::ListReleases => {
let releases = gt_tools::api::release::list_releases( let releases =
&client, gt_tools::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
&args.gitea_url,
&args.repo
).await?;
for release in releases { for release in releases {
println!("{:?}", release); println!("{:?}", release);
} }
@@ -51,13 +47,18 @@ async fn main() -> Result<(), gt_tools::Error> {
tag_name, tag_name,
target_commitish, target_commitish,
}; };
gt_tools::api::release::create_release(&client, &args.gitea_url, &args.repo, submission) gt_tools::api::release::create_release(
.await?; &client,
&args.gitea_url,
&args.repo,
submission,
)
.await?;
} }
gt_tools::cli::Commands::UploadRelease { gt_tools::cli::Commands::UploadRelease {
tag_name, tag_name,
create, create,
files files,
} => { } => {
println!("Uploading files to a release!"); println!("Uploading files to a release!");
println!("Release Tag: {tag_name}"); println!("Release Tag: {tag_name}");
@@ -67,15 +68,12 @@ async fn main() -> Result<(), gt_tools::Error> {
println!("--- {file}"); println!("--- {file}");
} }
// TODO: Pre-create the release, if it doesn't exist. // TODO: Pre-create the release, if it doesn't exist.
// There's only Gitea APIs to get all releases, or one by-id. // There's only Gitea APIs to get all releases, or one by-id.
// Grab all, find the one that matches the input tag. // Grab all, find the one that matches the input tag.
// Scream if there are multiple matches. // Scream if there are multiple matches.
let release_candidates = gt_tools::api::release::list_releases( let release_candidates =
&client, gt_tools::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
&args.gitea_url,
&args.repo
).await?;
if let Some(release) = match_release_by_tag(&tag_name, release_candidates) { if let Some(release) = match_release_by_tag(&tag_name, release_candidates) {
gt_tools::api::release_attachment::create_release_attachment( gt_tools::api::release_attachment::create_release_attachment(
@@ -83,8 +81,9 @@ async fn main() -> Result<(), gt_tools::Error> {
&args.gitea_url, &args.gitea_url,
&args.repo, &args.repo,
release.id, release.id,
files files,
).await?; )
.await?;
} else { } else {
println!("ERR: Couldn't find a release matching the tag \"{tag_name}\"."); println!("ERR: Couldn't find a release matching the tag \"{tag_name}\".");
} }
@@ -111,7 +110,10 @@ fn match_release_by_tag(tag: &String, releases: Vec<Release>) -> Option<Release>
// if there was already a match, begin the error diagnostic creation. // if there was already a match, begin the error diagnostic creation.
let first_id = first_release.id; let first_id = first_release.id;
let second_id = rel.id; let second_id = rel.id;
assert!(first_id != second_id, "FAILURE: Found the same release ID twice while scanning for duplicate tags. How did we get the same one twice?"); assert!(
first_id != second_id,
"FAILURE: Found the same release ID twice while scanning for duplicate tags. How did we get the same one twice?"
);
eprintln!("ERROR: Two releases have been found for the tag \"{tag}\"."); eprintln!("ERROR: Two releases have been found for the tag \"{tag}\".");
eprintln!("ERROR: first ID: {first_id}"); eprintln!("ERROR: first ID: {first_id}");
eprintln!("ERROR: second ID: {second_id}"); eprintln!("ERROR: second ID: {second_id}");
@@ -124,4 +126,3 @@ fn match_release_by_tag(tag: &String, releases: Vec<Release>) -> Option<Release>
} }
return release; return release;
} }

View File

@@ -1,3 +1,2 @@
pub mod release; pub mod release;
pub mod repo; pub mod repo;

View File

@@ -40,4 +40,3 @@ pub struct CreateReleaseOption {
} }
pub struct EditReleaseOption; pub struct EditReleaseOption;

View File

@@ -1,4 +1,3 @@
pub struct Permission; pub struct Permission;
pub struct Repository; pub struct Repository;