Skip to content

Commit

Permalink
add docs and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Just-Nans committed Jan 8, 2025
1 parent 411063c commit 89c6bd8
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-mover"
version = "1.0.1"
version = "1.0.2"
edition = "2021"
keywords = ["utility", "git", "cli"]
categories = ["command-line-utilities"]
Expand Down
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Command line options for the git-mover tool
use crate::{config::Config, platform::PlatformType, utils::main_sync};
use clap::Parser;
use serde::Deserialize;
use std::path::PathBuf;

/// Command line options for the git-mover tool
#[derive(Parser, Deserialize, Default, Clone, Debug)]
pub struct GitMoverCli {
/// The source platform (github, gitlab, codeberg)
Expand All @@ -26,6 +28,7 @@ pub struct GitMoverCli {
pub verbose: u8,
}

/// Run the git-mover tool with the provided command line options
pub async fn cli_main() {
let args = GitMoverCli::parse();
let mut config = match &args.config {
Expand Down
4 changes: 4 additions & 0 deletions src/codeberg/config.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
//! Codeberg configuration
use super::platform::CodebergPlatform;
use crate::{config::Config, config_value_wrap};
use serde::{Deserialize, Serialize};

/// Codeberg configuration
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct CodebergConfig {
/// Codeberg username
pub username: Option<String>,

/// Codeberg token
pub token: Option<String>,
}

impl CodebergConfig {
/// Get the codeberg platform
pub fn get_plateform(config: &mut Config) -> CodebergPlatform {
let username = config_value_wrap!(
config,
Expand Down
3 changes: 2 additions & 1 deletion src/codeberg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

//! Codeberg API module.
pub(crate) mod config;
pub(crate) mod platform;
pub(crate) mod repo;

/// Codeberg URL
const CODEBERG_URL: &str = "codeberg.org";
11 changes: 7 additions & 4 deletions src/codeberg/platform.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use std::pin::Pin;

//! Codeberg platform implementation
use reqwest::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};
use serde::{Deserialize, Serialize};
use std::pin::Pin;

use super::{repo::CodebergRepo, CODEBERG_URL};
use crate::{
errors::{GitMoverError, GitMoverErrorKind},
platform::Platform,
utils::Repo,
};

use super::{repo::CodebergRepo, CODEBERG_URL};

/// Codeberg platform
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct CodebergPlatform {
/// Codeberg username
pub username: String,
/// Codeberg token
pub token: String,
}

impl CodebergPlatform {
/// Create a new codeberg platform
pub fn new(username: String, token: String) -> Self {
Self { username, token }
}
Expand Down
12 changes: 10 additions & 2 deletions src/codeberg/repo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use serde::{Deserialize, Serialize};

//! Codeberg repository
use crate::utils::Repo;
use serde::{Deserialize, Serialize};

/// Codeberg repository
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct CodebergRepo {
/// Name of the repository
pub name: String,

/// Description of the repository
pub description: String,

/// Whether the repository is private
pub private: bool,

/// Whether the repository is a fork
#[serde(skip_serializing)]
pub fork: bool,
}
Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Configuration handling
use std::{
fs::{create_dir_all, read_to_string, File},
io::Write,
Expand All @@ -12,6 +13,7 @@ use crate::{
gitlab::config::GitlabConfig,
};

/// Configuration data
#[derive(Deserialize, Default, Clone, Debug)]
pub struct Config {
/// debug level
Expand All @@ -23,15 +25,19 @@ pub struct Config {
/// actual configuration data
pub config_data: ConfigData,

/// CLI arguments
pub cli_args: Option<GitMoverCli>,
}

#[derive(Deserialize, Serialize, Default, Clone, Debug)]
pub struct ConfigData {
/// Gitlab configuration
pub gitlab: Option<GitlabConfig>,

/// Github configuration
pub github: Option<GithubConfig>,

/// Codeberg configuration
pub codeberg: Option<CodebergConfig>,
}

Expand All @@ -53,12 +59,15 @@ impl Config {
}
}

/// Set the config arguments
pub fn with_cli_args(mut self, cli_args: GitMoverCli) -> Self {
self.cli_args = Some(cli_args);
self
}

/// Create a new Config object from the default path
/// # Panics
/// Panics if the config file can't be opened
pub fn new() -> Config {
let config_path = Config::get_config_path();
let contents = read_to_string(config_path.clone())
Expand All @@ -67,6 +76,8 @@ impl Config {
}

/// Save the config data to the config file
/// # Panics
/// Panics if the config file can't be created or written to
pub fn save(&self) {
let config_str = toml::to_string(&self.config_data).expect("Unable to serialize config");
let mut file = File::create(&self.config_path).expect("Unable to create config file");
Expand All @@ -75,6 +86,8 @@ impl Config {
}

/// Create a new Config object from a custom path
/// # Panics
/// Panics if the config file can't be opened
pub fn new_from_path(custom_path: &PathBuf) -> Config {
let contents = read_to_string(custom_path.clone())
.unwrap_or_else(|_| panic!("Unable to open {:?}", custom_path));
Expand All @@ -88,6 +101,8 @@ impl Config {
}

/// Get the path to the config file
/// # Panics
/// Panics if the home directory can't be found
pub fn get_config_path() -> PathBuf {
let home_dir = match home_dir() {
Some(path) if !path.as_os_str().is_empty() => Ok(path),
Expand Down
26 changes: 26 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
//! Error handling for the git-mover crate.
use std::{error::Error as StdError, fmt};

/// Error type for the git-mover crate.
#[derive(Debug)]
pub struct GitMoverError {
/// Inner error.
inner: Box<Inner>,
}

impl GitMoverError {
/// Create a new error.
pub(crate) fn new(kind: GitMoverErrorKind) -> Self {
Self {
inner: Box::new(Inner { kind, source: None }),
}
}

/// Create a new error with a source.
pub(crate) fn with_text(mut self, text: &str) -> Self {
self.inner.source = Some(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
Expand All @@ -21,24 +26,45 @@ impl GitMoverError {
}
}

/// Type alias for a boxed error.
pub(crate) type BoxError = Box<dyn StdError + Send + Sync>;

/// Inner error type for the git-mover crate.
#[derive(Debug)]
struct Inner {
/// Error kind.
kind: GitMoverErrorKind,
/// Source error.
source: Option<BoxError>,
}

#[derive(Debug)]
pub(crate) enum GitMoverErrorKind {
/// Error related to the platform.
Platform,

/// Error related to the reqwest crate.
Reqwest,

/// Error related to serde.
Serde,

/// Error related to the configuration.
Unimplemented,

/// Error related to the RepoEdition func.
RepoEdition,

/// Error related to the GetAllRepo func.
GetAllRepos,

/// Error related to the GetRepo func.
GetRepo,

/// Error related to the RepoCreation func.
RepoNotFound,

/// Error related to the RepoDeletion func.
RepoDeletion,
}

Expand Down
4 changes: 4 additions & 0 deletions src/github/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Github configuration
use super::platform::GithubPlatform;
use serde::{Deserialize, Serialize};

Expand All @@ -6,12 +7,15 @@ use crate::{config::Config, config_value_wrap};
/// Github configuration
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct GithubConfig {
/// Github username
pub username: Option<String>,

/// Github token
pub token: Option<String>,
}

impl GithubConfig {
/// Get the github platform
pub fn get_plateform(config: &mut Config) -> GithubPlatform {
let username = config_value_wrap!(
config,
Expand Down
2 changes: 2 additions & 0 deletions src/github/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! GitHub API module.
pub(crate) mod config;
pub(crate) mod platform;
pub(crate) mod repo;

/// GitHub URL
const GITHUB_URL: &str = "github.com";
6 changes: 6 additions & 0 deletions src/github/platform.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Github Platform
use super::GITHUB_URL;
use crate::{
errors::{GitMoverError, GitMoverErrorKind},
Expand All @@ -12,13 +13,18 @@ use reqwest::{
use serde::{Deserialize, Serialize};
use std::pin::Pin;

/// Github Platform
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct GithubPlatform {
/// Github username
pub username: String,

/// Github token
pub token: String,
}

impl GithubPlatform {
/// Create a new GithubPlatform
pub fn new(username: String, token: String) -> Self {
Self { username, token }
}
Expand Down
16 changes: 14 additions & 2 deletions src/github/repo.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
use serde::{Deserialize, Serialize};

//! Github Repo struct and conversion to Repo struct
use crate::utils::Repo;
use serde::{Deserialize, Serialize};

/// Github Repo
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct RepoGithub {
/// Repository ID
pub id: u64,

/// Repository name
pub name: String,

/// Repository description
pub description: Option<String>,

/// Repository private status
pub private: bool,

/// Repository URL
pub html_url: String,

/// Repository fork status
pub fork: bool,
}

Expand Down
4 changes: 4 additions & 0 deletions src/gitlab/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Gitlab configuration
use super::platform::GitlabPlatform;
use crate::config::Config;
use crate::config_value_wrap;
Expand All @@ -6,12 +7,15 @@ use serde::{Deserialize, Serialize};
/// Gitlab configuration
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
pub struct GitlabConfig {
/// Gitlab username
pub username: Option<String>,

/// Gitlab token
pub token: Option<String>,
}

impl GitlabConfig {
/// Get Gitlab platform
pub fn get_plateform(config: &mut Config) -> GitlabPlatform {
let username = config_value_wrap!(
config,
Expand Down
2 changes: 2 additions & 0 deletions src/gitlab/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Gitlab API module
pub(crate) mod config;
pub(crate) mod platform;
pub(crate) mod repo;

/// Gitlab URL
const GITLAB_URL: &str = "gitlab.com";
Loading

0 comments on commit 89c6bd8

Please sign in to comment.