Skip to content

Commit

Permalink
chore: merge pull request #11 from websublime/feature/repo-url
Browse files Browse the repository at this point in the history
feat: method to format repo url
  • Loading branch information
miguelramos authored Jul 11, 2024
2 parents 597930c + c5d825c commit 77e6315
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ path = "src/lib.rs"

[dependencies]
execute = "0.2.13"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
regex = "1.10.3"
wax = { version = "0.6.0", features = ["walk"] }
napi-derive = "2.16.8"
Expand Down
4 changes: 4 additions & 0 deletions packages/package-a/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"repository": {
"url": "git+ssh://git@github.com/websublime/workspace-node-binding-tools.git",
"type": "git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.mjs"
Expand Down
4 changes: 4 additions & 0 deletions packages/package-b/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"repository": {
"url": "git+ssh://git@github.com/websublime/workspace-node-binding-tools.git",
"type": "git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.mjs"
Expand Down
32 changes: 16 additions & 16 deletions src/git/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use version_compare::{Cmp, Version};

use crate::{
filesystem::paths::get_project_root_path,
monorepo::{packages::PackageInfo, utils::package_scope_name_version},
monorepo::{
packages::PackageInfo, packages::PackageRepositoryInfo, utils::package_scope_name_version,
},
};

use super::conventional::{ConventionalPackage, ConventionalPackageOptions};
Expand Down Expand Up @@ -509,37 +511,35 @@ impl Git {

let convention_options = match conventional_options {
Some(options) => ConventionalPackageOptions {
owner: options.owner.or(Some(String::from("orga"))),
repo: options.repo.or(Some(String::from("tenant"))),
version: options.version.or(Some(String::from("0.0.0"))),
domain: options.domain.or(Some(String::from("https://github.com"))),
title: options.title,
},
None => ConventionalPackageOptions {
owner: Some(String::from("orga")),
repo: Some(String::from("tenant")),
version: Some(String::from("0.0.0")),
domain: Some(String::from("https://github.com")),
title: None,
},
};

let repo_info = package_info.repository_info.clone();
let repository_info = match repo_info {
Some(info) => info,
None => PackageRepositoryInfo {
orga: String::from("my-orga"),
project: String::from("my-repo"),
domain: String::from("https://github.com"),
},
};

let commits_since = Self::get_commits_since(
Some(current_working_dir),
hash,
Some(package_info.package_relative_path.clone()),
);
let mut conventional_package = ConventionalPackage::new(package_info);
let conventional_config = conventional_package.define_config(
convention_options
.owner
.expect("Owner repo needs to be defined"),
convention_options
.repo
.expect("Repo scope needs to be defined"),
convention_options
.domain
.expect("Github main domain url need to be defined"),
repository_info.orga,
repository_info.project,
repository_info.domain,
convention_options.title,
None,
);
Expand Down
3 changes: 0 additions & 3 deletions src/git/conventional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ pub struct ConventionalPackage {
#[napi(object)]
#[derive(Debug, Clone)]
pub struct ConventionalPackageOptions {
pub owner: Option<String>,
pub repo: Option<String>,
pub version: Option<String>,
pub domain: Option<String>,
pub title: Option<String>,
}

Expand Down
42 changes: 42 additions & 0 deletions src/monorepo/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::fmt::{Display, Error, Formatter};

#[derive(Debug)]
pub enum PackageJsonErrorEnum {
InvalidName(String),
InvalidDescription(String),
InvalidVersion(String),
InvalidRepository(String),
InvalidFiles(String),
InvalidLicense(String),
UnknownErr,
}

impl std::error::Error for PackageJsonErrorEnum {}

impl Display for PackageJsonErrorEnum {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
match self {
PackageJsonErrorEnum::InvalidName(message) => {
write!(f, "{}", message)
}
PackageJsonErrorEnum::InvalidDescription(message) => {
write!(f, "{}", message)
}
PackageJsonErrorEnum::InvalidVersion(message) => {
write!(f, "{}", message)
}
PackageJsonErrorEnum::InvalidRepository(message) => {
write!(f, "{}", message)
}
PackageJsonErrorEnum::InvalidFiles(message) => {
write!(f, "{}", message)
}
PackageJsonErrorEnum::InvalidLicense(message) => {
write!(f, "{}", message)
}
_ => todo!(),
}
}
}

// Err(PackageJsonErrorEnum::InvalidName("No valid name"))
1 change: 1 addition & 0 deletions src/monorepo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod errors;
pub mod packages;
pub mod utils;
Loading

0 comments on commit 77e6315

Please sign in to comment.