Loading acorn-cli/src/cli.rs +19 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,12 @@ pub enum Commands { /// Skip schema validation /// $> acorn check --path /path/to/folder --skip analysis,validation /// /// Check file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Check file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Check { /// Path to check Loading Loading @@ -91,7 +97,7 @@ pub enum Commands { /// Choose to output a JSON issue report to stdout #[arg(short, long, value_name = "BOOL")] report: bool, /// Skip one or more available diagnostic checks /// Select one or more available diagnostic checks #[arg(default_value = "all", short, long, value_name = "LIST", value_delimiter = ',')] check: Vec<Diagnostic>, #[command(flatten)] Loading Loading @@ -126,6 +132,12 @@ pub enum Commands { /// /// $> acorn export -p /path/to/data -t poster -o /path/to/output /// /// Export file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Export file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Export { /// Path of input files to be exported Loading @@ -152,6 +164,12 @@ pub enum Commands { /// /// $> acorn format --path /path/to/folder /// /// Format file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Format file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Format { /// Path to look for files to format Loading acorn-cli/src/commands/check/mod.rs +5 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ pub fn run(path: &Option<PathBuf>, commit: &Option<String>, skip: &[Check], exit // TODO: Use JSON output to create customized and consolidated error count and output success = ResearchActivity::analyze(paths); } if skip.contains(&Check::Readability) { warn!("=> {} Readability analysis", Label::skip()); } else { // TODO: Output readability analysis } if total > 0 || !success { std::process::exit(exitcode::DATAERR); } Loading acorn-lib/src/lib.rs +32 −15 Original line number Diff line number Diff line Loading @@ -39,26 +39,43 @@ pub enum Repository { #[display("github")] GitHub { uri: String }, #[display("gitlab")] GitLab { id: u64, uri: String }, GitLab { /// Integer ID of GitLab project /// /// See <https://docs.gitlab.com/api/projects/#get-a-single-project> for more information id: u64, uri: String, }, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct BucketsConfig { pub buckets: Vec<Bucket>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] #[serde(rename_all = "camelCase")] pub struct Bucket { name: String, repository: Repository, /// Bucket name /// /// See <https://schema.org/name> pub name: String, /// Bucket description /// /// See <https://schema.org/description> pub description: Option<String>, /// Code repository data of bucket /// /// See <https://schema.org/codeRepository> #[serde(alias = "repository")] pub code_repository: Repository, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct GitlabTreeEntry { id: String, name: String, pub id: String, pub name: String, #[serde(rename = "type")] entry_type: EntryType, path: String, mode: String, pub entry_type: EntryType, pub path: String, pub mode: String, } impl Bucket { fn parse(response: reqwest::blocking::Response) -> Vec<String> { Loading @@ -84,14 +101,14 @@ impl Bucket { | Repository::GitLab { .. } => "gitlab.com".to_string(), } } match &self.repository { match &self.code_repository { | Repository::GitHub { uri } => match URI::try_from(uri.as_str()) { | Ok(uri) => uri.host().unwrap().to_string(), | Err(_) => default_domain(self.repository.clone()), | Err(_) => default_domain(self.code_repository.clone()), }, | Repository::GitLab { uri, .. } => match URI::try_from(uri.as_str()) { | Ok(uri) => uri.host().unwrap().to_string(), | Err(_) => default_domain(self.repository.clone()), | Err(_) => default_domain(self.code_repository.clone()), }, } } Loading @@ -100,7 +117,7 @@ impl Bucket { reqwest::blocking::get(url) } fn get_tree_url(&self, schema_type: SchemaType, page: u32) -> String { let id = match &self.repository { let id = match &self.code_repository { | Repository::GitHub { .. } => todo!(), | Repository::GitLab { id, .. } => id.to_string(), }; Loading @@ -120,7 +137,7 @@ impl Bucket { fn get_suffix(value: usize) -> String { (if value == 1 { "" } else { "s" }).to_string() } let counts = SCHEMA_TYPES.into_iter().map(|schema_type| match self.repository { let counts = SCHEMA_TYPES.into_iter().map(|schema_type| match self.code_repository { | Repository::GitHub { .. } => todo!(), | Repository::GitLab { ref uri, .. } => { info!("=> Downloading {} research data from {}...", schema_type, uri.clone()); Loading Loading @@ -189,7 +206,7 @@ impl Bucket { // https://docs.gitlab.com/ee/api/repositories.html fn get_file_paths(self: Bucket, schema_type: SchemaType) -> Vec<String> { const FIRST_PAGE: u32 = 1; match self.repository { match self.code_repository { | Repository::GitHub { .. } => unimplemented!(), | Repository::GitLab { .. } => { fn get_page_count(response: &reqwest::blocking::Response) -> u32 { Loading acorn-lib/src/tests/mod.rs +4 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,8 @@ fn test_bucket_config() { fn test_bucket() { let bucket: Bucket = Bucket { name: "nssd".to_string(), repository: Repository::GitLab { description: Some("Bucket for NSSD".to_string()), code_repository: Repository::GitLab { id: 1234, uri: "https://code.ornl.gov/research-enablement/buckets/nssd".to_string(), }, Loading @@ -21,7 +22,8 @@ fn test_bucket() { assert_eq!(bucket.get_domain(), "code.ornl.gov".to_string()); let bucket: Bucket = Bucket { name: "nssd".to_string(), repository: Repository::GitHub { description: Some("Bucket for NSSD".to_string()), code_repository: Repository::GitHub { uri: "https://code.ornl.gov/research-enablement/buckets/nssd".to_string(), }, }; Loading acorn-lib/src/util/mod.rs +3 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ pub mod cli { /// Static analysis of prose #[display("analysis")] Analysis, /// Readability of prose #[display("readability")] Readability, /// Schema validation via Rust type system #[display("validation")] Validation, Loading Loading
acorn-cli/src/cli.rs +19 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,12 @@ pub enum Commands { /// Skip schema validation /// $> acorn check --path /path/to/folder --skip analysis,validation /// /// Check file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Check file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Check { /// Path to check Loading Loading @@ -91,7 +97,7 @@ pub enum Commands { /// Choose to output a JSON issue report to stdout #[arg(short, long, value_name = "BOOL")] report: bool, /// Skip one or more available diagnostic checks /// Select one or more available diagnostic checks #[arg(default_value = "all", short, long, value_name = "LIST", value_delimiter = ',')] check: Vec<Diagnostic>, #[command(flatten)] Loading Loading @@ -126,6 +132,12 @@ pub enum Commands { /// /// $> acorn export -p /path/to/data -t poster -o /path/to/output /// /// Export file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Export file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Export { /// Path of input files to be exported Loading @@ -152,6 +164,12 @@ pub enum Commands { /// /// $> acorn format --path /path/to/folder /// /// Format file(s) that were changed in a given Git commit /// $> acorn format --commit <commit hash> /// /// Format file(s) that were changed in latest Git commit /// $> acorn format --commit HEAD /// #[clap(verbatim_doc_comment)] Format { /// Path to look for files to format Loading
acorn-cli/src/commands/check/mod.rs +5 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ pub fn run(path: &Option<PathBuf>, commit: &Option<String>, skip: &[Check], exit // TODO: Use JSON output to create customized and consolidated error count and output success = ResearchActivity::analyze(paths); } if skip.contains(&Check::Readability) { warn!("=> {} Readability analysis", Label::skip()); } else { // TODO: Output readability analysis } if total > 0 || !success { std::process::exit(exitcode::DATAERR); } Loading
acorn-lib/src/lib.rs +32 −15 Original line number Diff line number Diff line Loading @@ -39,26 +39,43 @@ pub enum Repository { #[display("github")] GitHub { uri: String }, #[display("gitlab")] GitLab { id: u64, uri: String }, GitLab { /// Integer ID of GitLab project /// /// See <https://docs.gitlab.com/api/projects/#get-a-single-project> for more information id: u64, uri: String, }, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct BucketsConfig { pub buckets: Vec<Bucket>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] #[serde(rename_all = "camelCase")] pub struct Bucket { name: String, repository: Repository, /// Bucket name /// /// See <https://schema.org/name> pub name: String, /// Bucket description /// /// See <https://schema.org/description> pub description: Option<String>, /// Code repository data of bucket /// /// See <https://schema.org/codeRepository> #[serde(alias = "repository")] pub code_repository: Repository, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct GitlabTreeEntry { id: String, name: String, pub id: String, pub name: String, #[serde(rename = "type")] entry_type: EntryType, path: String, mode: String, pub entry_type: EntryType, pub path: String, pub mode: String, } impl Bucket { fn parse(response: reqwest::blocking::Response) -> Vec<String> { Loading @@ -84,14 +101,14 @@ impl Bucket { | Repository::GitLab { .. } => "gitlab.com".to_string(), } } match &self.repository { match &self.code_repository { | Repository::GitHub { uri } => match URI::try_from(uri.as_str()) { | Ok(uri) => uri.host().unwrap().to_string(), | Err(_) => default_domain(self.repository.clone()), | Err(_) => default_domain(self.code_repository.clone()), }, | Repository::GitLab { uri, .. } => match URI::try_from(uri.as_str()) { | Ok(uri) => uri.host().unwrap().to_string(), | Err(_) => default_domain(self.repository.clone()), | Err(_) => default_domain(self.code_repository.clone()), }, } } Loading @@ -100,7 +117,7 @@ impl Bucket { reqwest::blocking::get(url) } fn get_tree_url(&self, schema_type: SchemaType, page: u32) -> String { let id = match &self.repository { let id = match &self.code_repository { | Repository::GitHub { .. } => todo!(), | Repository::GitLab { id, .. } => id.to_string(), }; Loading @@ -120,7 +137,7 @@ impl Bucket { fn get_suffix(value: usize) -> String { (if value == 1 { "" } else { "s" }).to_string() } let counts = SCHEMA_TYPES.into_iter().map(|schema_type| match self.repository { let counts = SCHEMA_TYPES.into_iter().map(|schema_type| match self.code_repository { | Repository::GitHub { .. } => todo!(), | Repository::GitLab { ref uri, .. } => { info!("=> Downloading {} research data from {}...", schema_type, uri.clone()); Loading Loading @@ -189,7 +206,7 @@ impl Bucket { // https://docs.gitlab.com/ee/api/repositories.html fn get_file_paths(self: Bucket, schema_type: SchemaType) -> Vec<String> { const FIRST_PAGE: u32 = 1; match self.repository { match self.code_repository { | Repository::GitHub { .. } => unimplemented!(), | Repository::GitLab { .. } => { fn get_page_count(response: &reqwest::blocking::Response) -> u32 { Loading
acorn-lib/src/tests/mod.rs +4 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,8 @@ fn test_bucket_config() { fn test_bucket() { let bucket: Bucket = Bucket { name: "nssd".to_string(), repository: Repository::GitLab { description: Some("Bucket for NSSD".to_string()), code_repository: Repository::GitLab { id: 1234, uri: "https://code.ornl.gov/research-enablement/buckets/nssd".to_string(), }, Loading @@ -21,7 +22,8 @@ fn test_bucket() { assert_eq!(bucket.get_domain(), "code.ornl.gov".to_string()); let bucket: Bucket = Bucket { name: "nssd".to_string(), repository: Repository::GitHub { description: Some("Bucket for NSSD".to_string()), code_repository: Repository::GitHub { uri: "https://code.ornl.gov/research-enablement/buckets/nssd".to_string(), }, }; Loading
acorn-lib/src/util/mod.rs +3 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ pub mod cli { /// Static analysis of prose #[display("analysis")] Analysis, /// Readability of prose #[display("readability")] Readability, /// Schema validation via Rust type system #[display("validation")] Validation, Loading