Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jadelily18 committed Nov 8, 2023
1 parent 75b0216 commit ee98c32
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 137 deletions.
73 changes: 35 additions & 38 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn create_modpack_release(
pack_file: &PackFile,
output_file_info: &OutputFileInfo,
version_info: &VersionInfo,
changelog: &String,
changelog: &str,
) -> Result<(), anyhow::Error> {
println!("Creating GitHub release...");

Expand All @@ -74,7 +74,7 @@ pub async fn create_modpack_release(
let new_release_req_body = CreateReleaseRequest {
tag_name: pack_file.version.clone(),
name: Some(version_info.version_name.clone()),
body: Some(changelog.clone()),
body: Some(changelog.to_owned()),
};

let new_release_response =
Expand Down Expand Up @@ -116,7 +116,7 @@ pub async fn create_mod_release(
config: &ModConfig,
mod_info: &ModInfo,
mod_jars: &ModJars,
changelog: &String,
changelog: &str,
version_name: &String,
) -> Result<(), anyhow::Error> {
println!("Creating GitHub release...");
Expand All @@ -129,7 +129,7 @@ pub async fn create_mod_release(
let new_release_req_body = CreateReleaseRequest {
tag_name: mod_info.version.clone(),
name: Some(version_name.into()),
body: Some(changelog.clone()),
body: Some(changelog.to_owned()),
};

let new_release_response =
Expand Down Expand Up @@ -207,45 +207,42 @@ pub async fn upload_mod_jars(
}

// Upload sources jar
match sources_jar_contents {
Some(file_contents) => {
println!(
"Uploading sources jar as GitHub Release asset `{}`...",
&mod_jars.sources_jar.clone().unwrap().file_name
);
if let Some(file_contents) = sources_jar_contents {
println!(
"Uploading sources jar as GitHub Release asset `{}`...",
&mod_jars.sources_jar.clone().unwrap().file_name
);

match reqwest::Client::new()
.post(format!(
"https://uploads.github.com/repos/{}/{}/releases/{}/assets?name=\"{}\"",
github_config.repo_owner,
github_config.repo_name,
release_id,
match reqwest::Client::new()
.post(format!(
"https://uploads.github.com/repos/{}/{}/releases/{}/assets?name=\"{}\"",
github_config.repo_owner,
github_config.repo_name,
release_id,
&mod_jars.sources_jar.clone().unwrap().file_name
))
.header("User-Agent", env!("CARGO_PKG_NAME"))
.header("Accept", "application/vnd.github+json")
.header("Content-Type", "application/java-archive")
.bearer_auth(&token)
.body(file_contents)
.send()
.await
{
Ok(_) => {
println!(
"Successfully uploaded GitHub Release asset `{}`!",
&mod_jars.sources_jar.clone().unwrap().file_name
)
}
Err(err) => {
return Err(anyhow!(
"Failed to upload GitHub release asset `{}`: {}",
&mod_jars.sources_jar.clone().unwrap().file_name,
err
))
.header("User-Agent", env!("CARGO_PKG_NAME"))
.header("Accept", "application/vnd.github+json")
.header("Content-Type", "application/java-archive")
.bearer_auth(&token)
.body(file_contents)
.send()
.await
{
Ok(_) => {
println!(
"Successfully uploaded GitHub Release asset `{}`!",
&mod_jars.sources_jar.clone().unwrap().file_name
)
}
Err(err) => {
return Err(anyhow!(
"Failed to upload GitHub release asset `{}`: {}",
&mod_jars.sources_jar.clone().unwrap().file_name,
err
))
}
}
}
None => (),
}

Ok(())
Expand Down
48 changes: 17 additions & 31 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ enum Commands {

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
match dotenvy::dotenv() {
Ok(_) => (),
Err(_) => (),
};
let _ = dotenvy::dotenv();

let args = CliArgs::parse();

Expand Down Expand Up @@ -96,25 +93,19 @@ async fn main() -> Result<(), anyhow::Error> {
Err(err) => return Err(err),
};

match version {
Some(ver) => {
let mut new_file_contents = pack_file.clone();
new_file_contents.version = ver;
let file_contents_string = match toml::to_string(&new_file_contents) {
Ok(file) => file,
Err(err) => {
return Err(anyhow!("Failed to parse new pack data to toml: {}", err))
}
};
if let Some(ver) = version {
let mut new_file_contents = pack_file.clone();
new_file_contents.version = ver;
let file_contents_string = match toml::to_string(&new_file_contents) {
Ok(file) => file,
Err(err) => {
return Err(anyhow!("Failed to parse new pack data to toml: {}", err))
}
};

pack_file = new_file_contents;
pack_file = new_file_contents;

match write_pack_file(&tmp_info.dir_path, file_contents_string) {
Ok(_) => (),
Err(err) => return Err(err),
}
}
None => (),
write_pack_file(&tmp_info.dir_path, file_contents_string)?
}

match Command::new("packwiz")
Expand Down Expand Up @@ -220,13 +211,11 @@ async fn main() -> Result<(), anyhow::Error> {
Err(err) => return Err(anyhow!("Failed to find Java executable: {}", err)),
}

let gradlew_path: &Path;

if env::consts::OS == "windows" {
gradlew_path = Path::new(".\\gradlew.bat");
let gradlew_path: &Path = if env::consts::OS == "windows" {
Path::new(".\\gradlew.bat")
} else {
gradlew_path = Path::new("./gradlew");
}
Path::new("./gradlew")
};

if !Path::new(gradlew_path).exists() {
return Err(anyhow!(
Expand Down Expand Up @@ -256,10 +245,7 @@ async fn main() -> Result<(), anyhow::Error> {
};

// remove previously-compiled jars, if any
match fs::remove_dir(&tmp_info.dir_path.join("build").join("libs")) {
Ok(_) => (),
Err(_) => (),
}
let _ = fs::remove_dir(&tmp_info.dir_path.join("build").join("libs"));

let mut gradle_command = Command::new(gradlew_path);

Expand Down
28 changes: 14 additions & 14 deletions src/models/modrinth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ impl ModrinthUrl {
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Loader {
QUILT,
FABRIC,
NEOFORGE,
FORGE,
LITELOADER,
Quilt,
Fabric,
Neoforge,
Forge,
Liteloader,
}

impl Loader {
pub fn formatted(&self) -> String {
match self {
Self::QUILT => "Quilt",
Self::FABRIC => "Fabric",
Self::NEOFORGE => "NeoForge",
Self::FORGE => "Forge",
Self::LITELOADER => "LiteLoader",
Self::Quilt => "Quilt",
Self::Fabric => "Fabric",
Self::Neoforge => "NeoForge",
Self::Forge => "Forge",
Self::Liteloader => "LiteLoader",
}
.to_string()
}
Expand Down Expand Up @@ -83,8 +83,8 @@ pub struct GalleryObject {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum DependencyType {
REQUIRED,
OPTIONAL,
INCOMPATIBLE,
EMBEDDED,
Required,
Optional,
Incompatible,
Embedded,
}
24 changes: 12 additions & 12 deletions src/models/modrinth/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ProjectType {
MOD,
PLUGIN,
DATAPACK,
SHADER,
RESOURCEPACK,
MODPACK,
Mod,
Plugin,
Datapack,
Shader,
Resourcepack,
Modpack,
}

impl ProjectType {
pub fn formatted(&self) -> String {
match self {
Self::MOD => "Mod",
Self::PLUGIN => "Plugin",
Self::DATAPACK => "Data Pack",
Self::SHADER => "Shader",
Self::RESOURCEPACK => "Resource Pack",
Self::MODPACK => "Modpack",
Self::Mod => "Mod",
Self::Plugin => "Plugin",
Self::Datapack => "Data Pack",
Self::Shader => "Shader",
Self::Resourcepack => "Resource Pack",
Self::Modpack => "Modpack",
}
.to_string()
}
Expand Down
23 changes: 9 additions & 14 deletions src/models/modrinth/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,20 @@ pub struct VersionDependency {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum VersionType {
#[serde(rename = "release")]
RELEASE,
#[serde(rename = "beta")]
BETA,
#[serde(rename = "alpha")]
ALPHA,
Release,
Beta,
Alpha,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum VersionStatus {
#[serde(rename = "listed")]
LISTED,
#[serde(rename = "archived")]
ARCHIVED,
#[serde(rename = "draft")]
DRAFT,
#[serde(rename = "unlisted")]
UNLISTED,
Listed,
Archived,
Draft,
Unlisted,
}

impl From<ModrinthDependency> for VersionDependency {
Expand Down
8 changes: 0 additions & 8 deletions src/models/project_type/mc_mod/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ pub struct ModFile {
pub contents: Vec<u8>,
}

impl ModVersionInfo {
pub fn loaders_formatted(&self) -> String {
let loaders: &Vec<String> = &self.loaders.iter().map(|l| l.formatted()).collect();

loaders.join("/")
}
}

impl ModVersionInfo {
pub fn new(
config: &ModConfig,
Expand Down
Loading

0 comments on commit ee98c32

Please sign in to comment.