pub fn is_important(rel_fname: &str) -> bool {
if IMPORTANT_FILES.contains(&rel_fname) {
return true;
}
if rel_fname.starts_with(".github/workflows/") && rel_fname.ends_with(".yml") {
return true;
}
false
}
pub fn filter_important_files<'a>(files: &[&'a str]) -> Vec<&'a str> {
files.iter().copied().filter(|f| is_important(f)).collect()
}
pub static IMPORTANT_FILES: &[&str] = &[
".gitignore",
".gitattributes",
"README",
"README.md",
"README.txt",
"README.rst",
"CONTRIBUTING",
"CONTRIBUTING.md",
"CONTRIBUTING.txt",
"CONTRIBUTING.rst",
"LICENSE",
"LICENSE.md",
"LICENSE.txt",
"CHANGELOG",
"CHANGELOG.md",
"CHANGELOG.txt",
"CHANGELOG.rst",
"SECURITY",
"SECURITY.md",
"SECURITY.txt",
"CODEOWNERS",
"requirements.txt",
"Pipfile",
"Pipfile.lock",
"pyproject.toml",
"setup.py",
"setup.cfg",
"package.json",
"package-lock.json",
"yarn.lock",
"npm-shrinkwrap.json",
"Gemfile",
"Gemfile.lock",
"composer.json",
"composer.lock",
"pom.xml",
"build.gradle",
"build.gradle.kts",
"build.sbt",
"go.mod",
"go.sum",
"Cargo.toml",
"Cargo.lock",
"mix.exs",
"rebar.config",
"project.clj",
"Podfile",
"Cartfile",
"dub.json",
"dub.sdl",
".env",
".env.example",
".editorconfig",
"tsconfig.json",
"jsconfig.json",
".babelrc",
"babel.config.js",
".eslintrc",
".eslintignore",
".prettierrc",
".stylelintrc",
"tslint.json",
".pylintrc",
".flake8",
".rubocop.yml",
".scalafmt.conf",
".dockerignore",
".gitpod.yml",
"sonar-project.properties",
"renovate.json",
"dependabot.yml",
".pre-commit-config.yaml",
"mypy.ini",
"tox.ini",
".yamllint",
"pyrightconfig.json",
"webpack.config.js",
"rollup.config.js",
"parcel.config.js",
"gulpfile.js",
"Gruntfile.js",
"build.xml",
"build.boot",
"project.json",
"build.cake",
"MANIFEST.in",
"pytest.ini",
"phpunit.xml",
"karma.conf.js",
"jest.config.js",
"cypress.json",
".nycrc",
".nycrc.json",
".travis.yml",
".gitlab-ci.yml",
"Jenkinsfile",
"azure-pipelines.yml",
"bitbucket-pipelines.yml",
"appveyor.yml",
"circle.yml",
".circleci/config.yml",
".github/dependabot.yml",
"codecov.yml",
".coveragerc",
"Dockerfile",
"docker-compose.yml",
"docker-compose.override.yml",
"serverless.yml",
"firebase.json",
"now.json",
"netlify.toml",
"vercel.json",
"app.yaml",
"terraform.tf",
"main.tf",
"cloudformation.yaml",
"cloudformation.json",
"ansible.cfg",
"kubernetes.yaml",
"k8s.yaml",
"schema.sql",
"liquibase.properties",
"flyway.conf",
"next.config.js",
"nuxt.config.js",
"vue.config.js",
"angular.json",
"gatsby-config.js",
"gridsome.config.js",
"swagger.yaml",
"swagger.json",
"openapi.yaml",
"openapi.json",
".nvmrc",
".ruby-version",
".python-version",
"Vagrantfile",
".codeclimate.yml",
"mkdocs.yml",
"_config.yml",
"book.toml",
"readthedocs.yml",
".readthedocs.yaml",
".npmrc",
".yarnrc",
".isort.cfg",
".markdownlint.json",
".markdownlint.yaml",
".bandit",
".secrets.baseline",
".pypirc",
".gitkeep",
".npmignore",
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_important_exact_match() {
assert!(is_important("README.md"));
assert!(is_important("Cargo.toml"));
assert!(is_important("package.json"));
assert!(is_important(".gitignore"));
assert!(is_important("Dockerfile"));
}
#[test]
fn is_important_github_workflows() {
assert!(is_important(".github/workflows/ci.yml"));
assert!(is_important(".github/workflows/release.yml"));
assert!(is_important(".github/workflows/test.yml"));
}
#[test]
fn is_not_important() {
assert!(!is_important("src/main.rs"));
assert!(!is_important("lib/utils.py"));
assert!(!is_important("random.txt"));
assert!(!is_important("workflows/ci.yml"));
assert!(!is_important(".github/workflows/config.yaml"));
}
#[test]
fn filter_important() {
let files = vec![
"README.md",
"src/main.rs",
"Cargo.toml",
"lib/utils.rs",
".github/workflows/ci.yml",
];
let important = filter_important_files(&files);
assert_eq!(important.len(), 3);
assert!(important.contains(&"README.md"));
assert!(important.contains(&"Cargo.toml"));
assert!(important.contains(&".github/workflows/ci.yml"));
assert!(!important.contains(&"src/main.rs"));
}
#[test]
fn important_list_coverage() {
assert!(IMPORTANT_FILES.contains(&".gitignore")); assert!(IMPORTANT_FILES.contains(&"README.md")); assert!(IMPORTANT_FILES.contains(&"package.json")); assert!(IMPORTANT_FILES.contains(&"tsconfig.json")); assert!(IMPORTANT_FILES.contains(&"Dockerfile")); assert!(IMPORTANT_FILES.contains(&".travis.yml")); }
}