Skip to content

Commit

Permalink
Add support for the new OpenSSF best practices url (#1280)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Sep 26, 2023
1 parent 4f676ef commit 2f8f472
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions clomonitor-core/src/linter/checks/openssf_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ pub(crate) const CHECK_SETS: [CheckSet; 1] = [CheckSet::Code];
lazy_static! {
#[rustfmt::skip]
static ref OPENSSF_URL: Regex = Regex::new(
r"(https://bestpractices.coreinfrastructure.org/projects/\d+)",
r"(https://www.bestpractices.dev/projects/\d+)",
).expect("exprs in OPENSSF_URL to be valid");

#[rustfmt::skip]
static ref OPENSSF_URL_LEGACY: Regex = Regex::new(
r"(https://bestpractices.coreinfrastructure.org/projects/\d+)",
).expect("exprs in OPENSSF_URL_LEGACY to be valid");
}

/// Check main function.
pub(crate) fn check(input: &CheckInput) -> Result<CheckOutput> {
// Reference in README file
if let Some(url) = readme_capture(&input.li.root, &[&OPENSSF_URL])? {
if let Some(url) = readme_capture(&input.li.root, &[&OPENSSF_URL, &OPENSSF_URL_LEGACY])? {
return Ok(CheckOutput::passed().url(Some(url)));
}

Expand All @@ -40,7 +45,15 @@ mod tests {
#[test]
fn openssf_url_extract() {
assert_eq!(
OPENSSF_URL.captures("[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4106/badge)](https://bestpractices.coreinfrastructure.org/projects/4106)").unwrap()[1].to_string(),
OPENSSF_URL.captures("[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/4106/badge)](https://www.bestpractices.dev/projects/4106)").unwrap()[1].to_string(),
"https://www.bestpractices.dev/projects/4106"
);
}

#[test]
fn openssf_url_legacy_extract() {
assert_eq!(
OPENSSF_URL_LEGACY.captures("[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4106/badge)](https://bestpractices.coreinfrastructure.org/projects/4106)").unwrap()[1].to_string(),
"https://bestpractices.coreinfrastructure.org/projects/4106"
);
}
Expand Down
1 change: 1 addition & 0 deletions docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ This check passes if:
- An `OpenSSF` best practices badge is found in the repository's `README` file. Regexps used:

```sh
"(https://www.bestpractices.dev/projects/\d+)"
"(https://bestpractices.coreinfrastructure.org/projects/\d+)"
```

Expand Down

0 comments on commit 2f8f472

Please sign in to comment.