-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The check has been renamed from FOSSA badge to License scanning - It's now able to detect Snyk badges in README files - A link to the license scanning report is stored and exposed in the UI - In addition to FOSSA and Snyk, it's now possible to provide a custom license scanning url in the `.clomonitor.yml` metadata file Closes #50 Signed-off-by: Sergio Castaño Arteaga <[email protected]> Signed-off-by: Cintia Sanchez Garcia <[email protected]> Co-authored-by: Sergio Castaño Arteaga <[email protected]> Co-authored-by: Cintia Sanchez Garcia <[email protected]>
- Loading branch information
1 parent
2308d3c
commit 83615b6
Showing
18 changed files
with
272 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use anyhow::Error; | ||
use serde::Deserialize; | ||
use std::ffi::OsStr; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
/// Metadata file name. | ||
pub const METADATA_FILE: &str = ".clomonitor.yml"; | ||
|
||
/// CloMonitor metadata. | ||
#[derive(Debug, Deserialize)] | ||
pub struct Metadata { | ||
pub license_scanning: Option<LicenseScanning>, | ||
} | ||
|
||
impl Metadata { | ||
/// Create a new metadata instance from the contents of the file located at | ||
/// the path provided. | ||
pub fn from<P: AsRef<OsStr>>(path: P) -> Result<Option<Self>, Error> { | ||
if !Path::new(&path).exists() { | ||
return Ok(None); | ||
} | ||
let content = fs::read_to_string(path.as_ref())?; | ||
Ok(serde_yaml::from_str(&content)?) | ||
} | ||
} | ||
|
||
/// License scanning section of the metadata. | ||
#[derive(Debug, Deserialize)] | ||
pub struct LicenseScanning { | ||
pub url: Option<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
const TESTDATA_PATH: &str = "src/linter/testdata"; | ||
|
||
#[test] | ||
fn metadata_from_path_success() { | ||
assert_eq!( | ||
Metadata::from(Path::new(TESTDATA_PATH).join(METADATA_FILE)) | ||
.unwrap() | ||
.unwrap() | ||
.license_scanning | ||
.unwrap() | ||
.url | ||
.unwrap(), | ||
"https://license-scanning.url" | ||
); | ||
} | ||
|
||
#[test] | ||
fn metadata_from_path_not_found() { | ||
assert!(matches!( | ||
Metadata::from(Path::new(TESTDATA_PATH).join("not-found")), | ||
Ok(None) | ||
)); | ||
} | ||
|
||
#[test] | ||
fn metadata_from_path_invalid_metadata_file() { | ||
assert!(matches!( | ||
Metadata::from(Path::new(TESTDATA_PATH).join("LICENSE")), | ||
Err(_) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
license_scanning: | ||
url: https://license-scanning.url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.