Skip to content

Conversation

@LonMcGregor
Copy link
Contributor

@LonMcGregor LonMcGregor commented Dec 10, 2025

Adds a file validator for PR submissions.

The directory files should be changed in is defined in an issue body, in a comment, like so:

<!---
CHANGE_DIR=^Sprint-1/
--->
  • If it is not present, the bot does not do this check

  • If it is present, this regexp is checked against every changed file present in a PR submission

  • If any fail to match, i.e. something in a wrong directory was changed, then the bot issues a warning

  • If no files are submitted at all, the bot issues a warning

  • I propose any metadata that needs checked be included in these style of comments, and this metadata will need to be added for every task submission before the bot will be able to perform checks

  • Currently only supports checking a single directory, but could be extended to have multiple, could also extend to do things like checking max number of committed files or any other metadata visible to PRs

You can see an example of output of this check here: CodeYourFuture/Module-Structuring-and-Testing-Data#873

@LonMcGregor LonMcGregor marked this pull request as ready for review December 10, 2025 16:02
@LonMcGregor
Copy link
Contributor Author

@illicitonion Here is the validator for checking the right files are committed. Let me know what you think, in particular if I've made any faux-pas in rust, re the matching and error handling. I'm still getting used to that.

Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here! This looks good, but I left a few comments about some general Rust things :)

@LonMcGregor
Copy link
Contributor Author

Thanks for the suggestions, Ive made some changes to improve them. I am a bit unhappy about how I am accessing the assignment issue ids, notably my comment in line 256 of pr-metadata-validator seems to be hinting at me that there's probably a cleaner way to access these. But it works now.

Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit unhappy about how I am accessing the assignment issue ids, notably my comment in line 256 of pr-metadata-validator seems to be hinting at me that there's probably a cleaner way to access these.

Yeah... Not suggesting necessarily making a change, but it feels like the mismatch here is that the existing APIs are very "match all the PRs" centric, whereas the API you really want in this functionality is "match me this one PR" - in the type system we're losing the information that "this one PR has already been matched" so you need to assert it. If we wanted to change this in a simple way, I think it would take the shape of combining lines 210-214 into this check, into a function on ModuleWithSubmissions along the lines of:

fn get_matched_pr(&self, pr_number: u64) -> Option<Submission>

whose body largely matches get_descriptor_id_for_pr (but returning the Submission rather than the u64) so that lines 210-214 would become something like:

let Some(Submission::PullRequest { assignment_issue_id, .. }) = matched.get_matched_pr(pr_number) else {
    return Ok(ValidationResult::CouldNotMatch);
}

and then you wouldn't need to separately check for the descriptor ID.

Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, thank you!

Co-authored-by: Daniel Wagner-Hall <daniel@codeyourfuture.io>
@LonMcGregor LonMcGregor merged commit 4585cad into main Dec 23, 2025
3 checks passed
@LonMcGregor LonMcGregor deleted the file-count-validator branch December 23, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants