Skip to content

Commit

Permalink
GH Actions PR review bot: Check only for substrings in checkbox text …
Browse files Browse the repository at this point in the history
…when validating PR template (commaai#31262)

check only for substrings in checkbox text
  • Loading branch information
mowoe authored Feb 1, 2024
1 parent 056b330 commit 628c829
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/auto_pr_review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ jobs:
return subset.every((item) => superset.includes(item));
};
// Utility function to check if a list of checkboxes is a subset of another list of checkboxes
isCheckboxSubset = (templateCheckBoxTexts, prTextCheckBoxTexts) => {
// Check if each template checkbox text is a substring of at least one PR checkbox text
// (user should be allowed to add additional text)
return templateCheckBoxTexts.every((item) => prTextCheckBoxTexts.some((element) => element.includes(item)))
}
// Get filenames of all currently checked-in PR templates
const template_contents = await github.rest.repos.getContent({
owner: context.repo.owner,
Expand Down Expand Up @@ -146,7 +153,7 @@ jobs:
template.checkboxes + "]"
);
if (
isSubset(template.checkboxes, pr_checkboxes) &&
isCheckboxSubset(template.checkboxes, pr_checkboxes) &&
isSubset(template.headings, pr_headings)
) {
console.debug("Found matching template!");
Expand Down

0 comments on commit 628c829

Please sign in to comment.