release-dep 0.1.0

A Rust library for fetching and downloading release binaries from multiple Git repositories (GitHub and Gitee) with semver version matching.
Documentation
# Release Dependency Manager

A Rust library for fetching and downloading release binaries from multiple Git repositories (GitHub and Gitee) with semantic version matching.

## Features

- **Multi-platform support**: Fetch releases from both GitHub and Gitee
- **Semantic versioning**: Use semver requirements to match compatible versions
- **Concurrent fetching**: Parallel requests to multiple repositories for faster results
- **Flexible configuration**: Customizable timeout, download directory, and repository priorities
- **Automatic binary download**: Downloads matching binary assets automatically

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
release-dep = "0.1.0"
```

## Quick Start

```rust
use release_dep::{Config, get_release};
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config {
        package: "your-package-name",
        version: "^1.0.0",  // semver requirement
        repo: &[
            "https://github.com/owner/repo",
            "https://gitee.com/owner/repo",
        ],
        download_dir: Some("./downloads"),
        timeout: Some(Duration::from_secs(30)),
    };

    match get_release(config) {
        Ok(release_dep) => {
            println!("Found release:");
            println!("  Name: {}", release_dep.name);
            println!("  Version: {}", release_dep.version);
            println!("  Binary: {:?}", release_dep.binary);
        }
        Err(e) => {
            println!("Error: {e}");
        }
    }

    Ok(())
}
```

## Configuration

The `Config` struct accepts the following parameters:

- `package`: The name of the package/binary to search for
- `version`: A semver requirement string (e.g., "^1.0.0", ">=0.2.0", "1.2.3")
- `repo`: An array of repository URLs in order of priority
- `download_dir`: Optional download directory (defaults to system temp directory)
- `timeout`: Optional timeout duration (defaults to no timeout)

## Supported Repository Providers

### GitHub

- **URL format**: `https://github.com/owner/repo`
- **API**: Uses GitHub REST API v3
- **Rate limits**: Subject to GitHub API rate limits

### Gitee

- **URL format**: `https://gitee.com/owner/repo`
- **API**: Uses Gitee REST API v5
- **Rate limits**: Subject to Gitee API rate limits

## Version Matching

The library supports full semver requirements:

- Exact version: `"1.0.0"`
- Caret requirements: `"^1.0.0"` (compatible with 1.x.x)
- Tilde requirements: `"~1.0.0"` (compatible with 1.0.x)
- Range requirements: `">=1.0.0, <2.0.0"`
- Wildcard: `"*"` (any version)

## Examples

### Single Repository

```rust
use release_dep::{Config, get_release};

let config = Config {
    package: "my-binary",
    version: "0.2.0",
    repo: &["https://github.com/owner/repo"],
    download_dir: Some("./downloads"),
    timeout: None,
};

let release = get_release(config)?;
```

### Multiple Repositories with Timeout

```rust
use release_dep::{Config, get_release};
use std::time::Duration;

let config = Config {
    package: "my-binary",
    version: "^1.0.0",
    repo: &[
        "https://gitee.com/owner/repo",    // Try Gitee first
        "https://github.com/owner/repo",  // Fallback to GitHub
    ],
    download_dir: Some("./target/downloads"),
    timeout: Some(Duration::from_secs(30)),
};

let release = get_release(config)?;
```

## How It Works

1. **Parse Configuration**: Validates the semver requirement and repository URLs
2. **Concurrent Requests**: Sends parallel requests to all specified repositories
3. **Version Matching**: Checks each release against the semver requirement
4. **Binary Search**: Looks for assets containing the package name
5. **Download**: Downloads the first matching binary found
6. **Return Results**: Returns the `ReleaseDep` with download information

## Return Type

The `get_release` function returns a `ReleaseDep` struct:

```rust
pub struct ReleaseDep {
    pub name: String,       // Package name
    pub version: Version,   // Exact version found
    pub binary: PathBuf,    // Path to downloaded binary
}
```

## Error Handling

The library returns detailed error messages for common scenarios:

- Invalid semver requirements
- Unsupported repository providers
- Network connection issues
- No matching releases found
- Download failures
- Timeout exceeded

## Requirements

- Rust 1.70 or later
- Internet connection for API access
- Write permissions for download directory

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Changelog

### 0.1.0

- Initial release
- Support for GitHub and Gitee repositories
- Semantic version matching
- Concurrent repository fetching
- Automatic binary download