From 628c829d195434a99c1d83e8119cf0d4d53c167c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20W=C3=B6rmann?= Date: Thu, 1 Feb 2024 19:31:10 +0100 Subject: [PATCH] GH Actions PR review bot: Check only for substrings in checkbox text when validating PR template (#31262) check only for substrings in checkbox text --- .github/workflows/auto_pr_review.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_review.yaml b/.github/workflows/auto_pr_review.yaml index 820801a2c76400..abb6c38d6be010 100644 --- a/.github/workflows/auto_pr_review.yaml +++ b/.github/workflows/auto_pr_review.yaml @@ -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, @@ -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!");