Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the new OpenSSF best practices url #1280

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading