Skip to content
This repository has been archived by the owner on Jan 11, 2025. It is now read-only.

Add Curseforge Support #21

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

Add Curseforge Support #21

wants to merge 19 commits into from

Conversation

Kiwifuit
Copy link
Owner

@Kiwifuit Kiwifuit commented Sep 23, 2024

yay

this pr fixes #5

Summary by Sourcery

Add support for Curseforge by introducing new types and structures to handle Curseforge mod data, and refactor existing code for improved readability and maintainability.

New Features:

  • Introduce support for Curseforge by adding new types and structures to handle Curseforge mod data.

Enhancements:

  • Refactor existing code to improve readability and maintainability by adjusting indentation and formatting across multiple files.

Copy link

sourcery-ai bot commented Sep 23, 2024

Reviewer's Guide by Sourcery

This pull request adds Curseforge support to the project by introducing a new module with initial functionality and tests. It also includes refactoring of existing code across multiple files to improve readability and maintainability, as well as enhancements to error handling and logging.

File-Level Changes

Change Details Files
Added initial Curseforge support
  • Created new files for Curseforge types and structures
  • Implemented CurseResponse wrapper for API responses
  • Added CurseMod, CurseModLinks, CurseCategory, CurseAuthor, and CurseAsset structures
  • Created a serializable CurseMods collection
  • Added an example for dependency resolution
curseforge/src/types/project.rs
curseforge/src/types/mod.rs
curseforge/src/types/query.rs
curseforge/examples/dep-resolve.rs
curseforge/src/lib.rs
Refactored code for improved readability and consistency
  • Adjusted indentation from 4 spaces to 2 spaces across multiple files
  • Reformatted code structure and spacing for better readability
  • Updated some variable names for clarity
modparser/src/types/forge.rs
denji/src/shell.rs
modrinth/src/types/mod.rs
mar/src/types.rs
modrinth/src/api/dependency.rs
modparser/src/unzip.rs
modparser/src/types/fabric.rs
modrinth/src/types/project.rs
modrinth/src/api/version.rs
hangar/src/types/version.rs
hangar/src/api/version.rs
hangar/src/types/project.rs
modrinth/src/types/version.rs
mar/src/repository.rs
hangar/src/types/query/search.rs
denji/src/shell/post.rs
modrinth/src/types/query/facets.rs
modrinth/src/types/result.rs
modrinth/src/api/mod.rs
hangar/src/types/mod.rs
mar/src/types/deserialize.rs
hangar/src/types/version/details.rs
mparse/src/types/mod.rs
Enhanced error handling and logging
  • Updated error messages for better clarity
  • Improved logging statements across the project
denji/src/shell.rs
modrinth/src/api/dependency.rs
modrinth/src/api/project.rs
hangar/src/api/project.rs
Updated dependencies and configuration
  • Added dotenv dependency for environment variable loading
  • Updated example code to use dotenv for configuration
curseforge/examples/dep-resolve.rs

Sequence Diagram

No sequence diagram generated.


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Kiwifuit - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

modparser/src/types/forge.rs Outdated Show resolved Hide resolved
modparser/src/types/forge.rs Outdated Show resolved Hide resolved
denji/src/shell.rs Show resolved Hide resolved
modrinth/src/api/dependency.rs Outdated Show resolved Hide resolved
modparser/src/unzip.rs Show resolved Hide resolved
@Kiwifuit
Copy link
Owner Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Kiwifuit - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

modparser/src/types/forge.rs Show resolved Hide resolved
@Kiwifuit
Copy link
Owner Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Kiwifuit - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

where
E: serde::de::Error,
{
if value == "*" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding more specific error handling

While the simplification of the ModLoaderVersionVisitor is good for readability, consider adding more specific error messages for different cases to maintain detailed error reporting.

if value == "*" {
    Ok(ForgeModVersion::Any)
} else if value.is_empty() {
    Err(E::custom("Empty version string"))
} else if !value.chars().all(|c| c.is_ascii_digit() || c == '.' || c == '-') {
    Err(E::custom("Invalid characters in version string"))
} else {
    Ok(ForgeModVersion::Specific(value.to_string()))
}

@@ -14,91 +14,91 @@ const MODRINTH_META: &str = "modrinth.index.json";

#[derive(Debug, Error)]
pub enum UnzipError {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using an enum for error types instead of hardcoded strings

Using an enum for error types would make the code more maintainable and allow for better error matching downstream. This can improve error handling and make it easier to add new error types in the future.

pub enum UnzipError {
    IoError(std::io::Error),
    ZipError(zip::result::ZipError),
    InvalidArchive,
    ExtractionFailed,
}

}

impl CurseCategory {
fn from_id<'de, D>(deserializer: D) -> Result<Self, D::Error>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Implement CurseCategory::from_id properly or add a TODO comment

The current implementation creates a dummy category with hardcoded values. This could lead to incorrect data being used. Either implement this function properly or add a TODO comment if it's intentionally left for future work.

inner: T,
}

impl<T> Deref for CurseResponse<T> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using #[derive(Deref, DerefMut)] for CurseResponse

You can simplify the Deref implementation by using #[derive(Deref, DerefMut)] from the derive_more crate. This would make the code more concise and easier to maintain.

use derive_more::{Deref, DerefMut};

#[derive(Deref, DerefMut)]
pub struct CurseResponse<T> {
    #[deref]
    #[deref_mut]
    pub data: T,
}

formatter.write_str("valid string or struct representing ModLoaderVersion variant")
}

fn visit_str<E>(self, value: &str) -> Result<ForgeModVersion, E>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring the visit_str method to improve readability and maintainability.

The changes to the visit_str method in ModLoaderVersionVisitor have increased complexity and reduced readability. Consider refactoring this section to improve clarity while maintaining the new functionality. Here's a suggested approach:

fn visit_str<E>(self, value: &str) -> Result<ForgeModVersion, E>
where
    E: serde::de::Error,
{
    match value {
        "*" => Ok(ForgeModVersion::Any),
        v if v.starts_with('[') => Ok(ForgeModVersion::VersionRange(
            v.parse().map_err(serde::de::Error::custom)?,
        )),
        v => Ok(ForgeModVersion::SpecificVersion(
            v.parse().map_err(serde::de::Error::custom)?,
        )),
    }
}

This refactored version:

  1. Uses a match expression for better readability
  2. Handles the "*" case first
  3. Checks for version ranges starting with '['
  4. Treats all other cases as specific versions

This approach simplifies the logic while maintaining the new behavior. It also removes the commented-out code, reducing noise in the codebase. If there are specific edge cases that this doesn't cover, consider adding them as additional match arms with clear comments explaining their purpose.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Curseforge support
1 participant