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 release;
pub mod release_attachment;
pub mod release_attachment;

View File

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

View File

@@ -1,12 +1,19 @@
use serde::{Deserialize, Serialize};
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_latest_release() -> Result<Release> { todo!(); }
pub fn get_release(id: u64) -> Result<Release> {
todo!();
}
pub fn get_latest_release() -> Result<Release> {
todo!();
}
pub async fn list_releases(
client: &reqwest::Client,
@@ -14,14 +21,8 @@ pub async fn list_releases(
repo: &str,
) -> Result<Vec<Release>> {
let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases/");
let req = client
.get(request_url)
.send()
.await;
let response = req
.map_err(|reqwest_err| {
crate::Error::WrappedReqwestErr(reqwest_err)
})?;
let req = client.get(request_url).send().await;
let response = req.map_err(|reqwest_err| crate::Error::WrappedReqwestErr(reqwest_err))?;
let release_list = response
.json::<Vec<Release>>()
.await
@@ -45,7 +46,7 @@ pub async fn create_release(
client: &reqwest::Client,
gitea_url: &str,
repo: &str,
submission: CreateReleaseOption
submission: CreateReleaseOption,
) -> Result<Release> {
let request_url = format!("{gitea_url}/api/v1/repos/{repo}/releases");
let req = client
@@ -66,10 +67,13 @@ pub async fn create_release(
} else {
Err(crate::Error::ApiErrorMessage(api_error))
}
},
}
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 delete_release(id: u64) -> Result<()> { todo!(); }
pub fn edit_release(id: u64) -> Result<Release> {
todo!();
}
pub fn delete_release(id: u64) -> Result<()> {
todo!();
}

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
pub mod cli;
pub mod api;
pub mod cli;
pub mod structs;
#[derive(Debug, Deserialize, Serialize)]
@@ -26,4 +26,3 @@ impl From<reqwest::Error> for crate::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::structs::release::{CreateReleaseOption, Release};
use clap::Parser;
@@ -10,10 +9,10 @@ use reqwest::header::ACCEPT;
#[tokio::main]
async fn main() -> Result<(), gt_tools::Error> {
let args = Args::parse();
let mut headers = reqwest::header::HeaderMap::new();
headers.append(ACCEPT, header::HeaderValue::from_static("application/json"));
// Gitea expects to see "token " for token auth.
if let Ok(token) = std::env::var("RELEASE_KEY_GITEA") {
let token = format!("token {token}");
@@ -26,11 +25,8 @@ async fn main() -> Result<(), gt_tools::Error> {
match args.command {
gt_tools::cli::Commands::ListReleases => {
let releases = gt_tools::api::release::list_releases(
&client,
&args.gitea_url,
&args.repo
).await?;
let releases =
gt_tools::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
for release in releases {
println!("{:?}", release);
}
@@ -51,13 +47,18 @@ async fn main() -> Result<(), gt_tools::Error> {
tag_name,
target_commitish,
};
gt_tools::api::release::create_release(&client, &args.gitea_url, &args.repo, submission)
.await?;
gt_tools::api::release::create_release(
&client,
&args.gitea_url,
&args.repo,
submission,
)
.await?;
}
gt_tools::cli::Commands::UploadRelease {
tag_name,
create,
files
files,
} => {
println!("Uploading files to a release!");
println!("Release Tag: {tag_name}");
@@ -67,15 +68,12 @@ async fn main() -> Result<(), gt_tools::Error> {
println!("--- {file}");
}
// TODO: Pre-create the release, if it doesn't exist.
// There's only Gitea APIs to get all releases, or one by-id.
// Grab all, find the one that matches the input tag.
// Scream if there are multiple matches.
let release_candidates = gt_tools::api::release::list_releases(
&client,
&args.gitea_url,
&args.repo
).await?;
let release_candidates =
gt_tools::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
if let Some(release) = match_release_by_tag(&tag_name, release_candidates) {
gt_tools::api::release_attachment::create_release_attachment(
@@ -83,8 +81,9 @@ async fn main() -> Result<(), gt_tools::Error> {
&args.gitea_url,
&args.repo,
release.id,
files
).await?;
files,
)
.await?;
} else {
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.
let first_id = first_release.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: first ID: {first_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;
}

View File

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

View File

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

View File

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