Skip to content

Commit e5edbce

Browse files
authored
Add a max file count check for PRs (#55)
I meant to add this in the original file validation update, but forgot. I've since seen this happen in a few PRs. If there are more than 100 files, the trainee probably committed some package files or venv into that task's directory. Is 100 a reasonable number? There are no PRs (to my knowledge) that require more than 100 files to be changed. --------- Co-authored-by: l <l>
1 parent b6ccc33 commit e5edbce

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/bin/pr-metadata-validator.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async fn main() {
7878
expected_files_pattern,
7979
} => &format!("{}`{}`", WRONG_FILES, expected_files_pattern),
8080
ValidationResult::NoFiles => NO_FILES,
81+
ValidationResult::TooManyFiles => TOO_MANY_FILES,
8182
};
8283

8384
let full_message = format!(
@@ -145,6 +146,10 @@ const NO_FILES: &str = r#"This PR is missing any submitted files.
145146
146147
Please check that you committed the right files and pushed to the repository"#;
147148

149+
const TOO_MANY_FILES: &str = r#"There are too many files committed in this pull request.
150+
151+
Please check and make sure you have not accidentally committed a cache, virtual environment, or npm package directory."#;
152+
148153
#[derive(strum_macros::Display)]
149154
enum ValidationResult {
150155
Ok,
@@ -154,6 +159,7 @@ enum ValidationResult {
154159
UnknownRegion,
155160
WrongFiles { expected_files_pattern: String },
156161
NoFiles,
162+
TooManyFiles,
157163
}
158164

159165
async fn validate_pr(
@@ -307,6 +313,10 @@ async fn check_pr_file_changes(
307313
return Ok(ValidationResult::NoFiles); // no files committed
308314
}
309315

316+
if pr_files.len() > 100 {
317+
return Ok(ValidationResult::TooManyFiles); // too many files probably a venv or npm cache
318+
}
319+
310320
// check each file and error if one is in unexpected place
311321
for pr_file in pr_files {
312322
if pr_file.filename == ".gitignore" {

0 commit comments

Comments
 (0)