Skip to content

Commit

Permalink
feat!: remove single repo commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Sep 30, 2024
1 parent d0b07e6 commit c64eda5
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 135 deletions.
30 changes: 0 additions & 30 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ pub async fn figure() -> anyhow::Result<(String, bool)> {
},
Some(Commands::GhCommand {}) => Ok(GH_COMMAND.to_string()),
Some(Commands::InitGlobal {}) => init::global_example(),
Some(Commands::Init {}) => init::example(),
Some(Commands::Markdown) => Ok(clap_markdown::help_markdown::<Cli>()),
Some(Commands::Check { token, org, repo }) => {
gh::check_licenses_on(&token, org, repo).await
}
Some(Commands::Deps { token, org, repo }) => gh::get_deps(&token, org, repo).await,
None => Ok("try dy --help for information on how to use dreamy".to_string()),
};

Expand All @@ -74,34 +69,9 @@ enum Commands {
/// [STABLE] print markdown doc of qwit to std out
Markdown,

/// [STABLE] creates an example config
Init {},
/// [STABLE] creates an global example config
InitGlobal {},

/// [PREVIEW] checks licenses on github
Check {
#[arg(short, long, env = "GITHUB_TOKEN")]
token: String,

#[arg(short, long, env = "DY_ORG")]
org: Option<String>,

#[arg(short, long, env = "DY_REPO")]
repo: Option<String>,
},
/// [PREVIEW] get all deps of an repo
Deps {
#[arg(short, long, env = "GITHUB_TOKEN")]
token: String,

#[arg(short, long, env = "DY_ORG")]
org: Option<String>,

#[arg(short, long, env = "DY_REPO")]
repo: Option<String>,
},

/// [STABLE] gh cli command to get all repos
GhCommand {},

Expand Down
23 changes: 0 additions & 23 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,22 @@ use serde_derive::Serialize;

#[derive(Serialize, Deserialize, Clone)]
pub struct Config {
pub report_title: Option<String>,
pub allowed_licenses: Option<Vec<String>>,
pub forbid_unknown: Option<bool>,
forbidden_licenses: Option<Vec<String>>,
pub org: String,
pub repo: Option<String>,
}

impl Config {
pub fn example() -> Self {
Self {
report_title: Some("very good title".to_string()),
allowed_licenses: None,
forbidden_licenses: Some(vec![]),
forbid_unknown: Some(false),
org: "acme".to_string(),
repo: Some("some_repo".to_string()),
}
}

pub fn global_example() -> Self {
Self {
org: "acme".to_string(),
report_title: None,
allowed_licenses: None,
forbidden_licenses: None,
forbid_unknown: None,
repo: None,
}
}

pub fn forbidden_unknown(&self) -> bool {
self.forbid_unknown.unwrap_or(false)
}

pub fn forbidden_licenses(&self) -> Vec<String> {
self.forbidden_licenses.clone().unwrap_or_default()
}
Expand All @@ -59,10 +40,6 @@ impl Config {
allowed.contains(&license)
}

pub fn is_forbidden_license(&self, license: String) -> bool {
self.forbidden_licenses().contains(&license)
}

pub fn from_file() -> Self {
let raw = fs::read_to_string("dy.toml").expect("no file found called dy.toml");
toml::from_str(&raw).expect("could not read toml file")
Expand Down
75 changes: 0 additions & 75 deletions src/gh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,6 @@ use crate::html;

pub mod remote;

pub async fn check_licenses_on(
token: &str,
org: Option<String>,
repo: Option<String>,
) -> anyhow::Result<String> {
let config = config::Config::from_file();

let gh_cl = Github::new();

let Some(org) = org.or(Some(config.clone().org)) else {
return Err(anyhow!("no org"));
};

let Some(repo) = repo.or(config.clone().repo) else {
return Err(anyhow!("no repo"));
};

let res = gh_cl.get_graph(&org, &repo, token).await?;

let source: remote::Source = remote::Source(res);

let not_allowed_licenses: Vec<GitHubDep> = source
.0
.clone()
.iter()
.filter(|&dep| config.clone().is_forbidden_license(dep.clone().license))
.cloned()
.collect();

let not_found: Vec<GitHubDep> = source
.0
.clone()
.iter()
.filter(|dep| dep.license == "not found")
.cloned()
.collect();

if !not_allowed_licenses.is_empty() {
let pretty = serde_json::to_string_pretty(&not_allowed_licenses)?;
return Err(anyhow!(pretty));
}
if config.forbidden_unknown() && (!not_found.is_empty()) {
let pretty = serde_json::to_string_pretty(&not_found)?;
return Err(anyhow!(pretty));
}

Ok("All good, no license violation found".to_string())
}

pub async fn get_deps(
token: &str,
org: Option<String>,
repo: Option<String>,
) -> anyhow::Result<String> {
let config = config::Config::from_file();

let gh_cl = Github::new();

let Some(org) = org.or(Some(config.clone().org)) else {
return Err(anyhow!("no org"));
};

let Some(repo) = repo.or(config.clone().repo) else {
return Err(anyhow!("no repo"));
};

let res = gh_cl.get_graph(&org, &repo, token).await?;

let source: remote::Source = remote::Source(res);

let pretty = serde_json::to_string_pretty(&source.0)?;

Ok(pretty)
}

async fn global_deps(
token: &str,
org: Option<String>,
Expand Down
7 changes: 0 additions & 7 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ use std::fs;

use crate::config;

pub fn example() -> anyhow::Result<String> {
let c = config::Config::example();
let as_toml = toml::to_string_pretty(&c)?;
fs::write("dy.toml", as_toml).expect("Unable to write file");
Ok("config file created, please adjust to your needs".to_string())
}

pub fn global_example() -> anyhow::Result<String> {
let c = config::Config::global_example();
let as_toml = toml::to_string_pretty(&c)?;
Expand Down

0 comments on commit c64eda5

Please sign in to comment.