From 974f1f7db11f37bdb6d300498967818744779af7 Mon Sep 17 00:00:00 2001 From: Sebastian Szewczyk Date: Tue, 26 Sep 2023 20:50:19 +0200 Subject: [PATCH] Detecting when PR description has been changed --- .../actions/javascript/authorChecklist/authorChecklist.js | 8 +++++++- .github/actions/javascript/authorChecklist/index.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/actions/javascript/authorChecklist/authorChecklist.js b/.github/actions/javascript/authorChecklist/authorChecklist.js index 258a9006b050..d021da3843f1 100644 --- a/.github/actions/javascript/authorChecklist/authorChecklist.js +++ b/.github/actions/javascript/authorChecklist/authorChecklist.js @@ -114,6 +114,7 @@ async function generateDynamicChecksAndCheckForCompletion() { let [contentBeforeChecklist, checklist, contentAfterChecklist] = partitionWithChecklist(body); let isPassing = true; + let checklistChanged = false; for (const check of checks) { // Check if it's already in the PR body, capturing the whether or not it's already checked const regex = new RegExp(`- \\[([ x])] ${_.escapeRegExp(check)}\n`); @@ -122,6 +123,7 @@ async function generateDynamicChecksAndCheckForCompletion() { // Add it to the PR body isPassing = false; checklist += `- [ ] ${check}\n`; + checklistChanged = true; } else { const isChecked = match[1] === 'x'; if (!isChecked) { @@ -132,12 +134,16 @@ async function generateDynamicChecksAndCheckForCompletion() { const allChecks = _.flatten(_.map(_.values(CHECKLIST_CATEGORIES), 'items')); for (const check of allChecks) { if (!checks.has(check)) { + console.log('new check', check); // Check if some dynamic check has been added with previous commit, but the check is not relevant anymore const regex = new RegExp(`- \\[([ x])] ${_.escapeRegExp(check)}\n`); const match = regex.exec(checklist); + console.log('match', match); if (match) { // Remove it from the PR body checklist = checklist.replace(match[0], ''); + checklistChanged = true; + } } } @@ -146,7 +152,7 @@ async function generateDynamicChecksAndCheckForCompletion() { const newBody = contentBeforeChecklist + checklistStartsWith + checklist + checklistEndsWith + contentAfterChecklist; // Update the PR body - if (checks.size > 0) { + if (checklistChanged) { await GithubUtils.octokit.pulls.update({ owner: CONST.GITHUB_OWNER, repo: CONST.APP_REPO, diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 91436bb78121..56db8a3503ce 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -124,6 +124,7 @@ async function generateDynamicChecksAndCheckForCompletion() { let [contentBeforeChecklist, checklist, contentAfterChecklist] = partitionWithChecklist(body); let isPassing = true; + let checklistChanged = false; for (const check of checks) { // Check if it's already in the PR body, capturing the whether or not it's already checked const regex = new RegExp(`- \\[([ x])] ${_.escapeRegExp(check)}\n`); @@ -132,6 +133,7 @@ async function generateDynamicChecksAndCheckForCompletion() { // Add it to the PR body isPassing = false; checklist += `- [ ] ${check}\n`; + checklistChanged = true; } else { const isChecked = match[1] === 'x'; if (!isChecked) { @@ -142,12 +144,16 @@ async function generateDynamicChecksAndCheckForCompletion() { const allChecks = _.flatten(_.map(_.values(CHECKLIST_CATEGORIES), 'items')); for (const check of allChecks) { if (!checks.has(check)) { + console.log('new check', check); // Check if some dynamic check has been added with previous commit, but the check is not relevant anymore const regex = new RegExp(`- \\[([ x])] ${_.escapeRegExp(check)}\n`); const match = regex.exec(checklist); + console.log('match', match); if (match) { // Remove it from the PR body checklist = checklist.replace(match[0], ''); + checklistChanged = true; + } } } @@ -156,7 +162,7 @@ async function generateDynamicChecksAndCheckForCompletion() { const newBody = contentBeforeChecklist + checklistStartsWith + checklist + checklistEndsWith + contentAfterChecklist; // Update the PR body - if (checks.size > 0) { + if (checklistChanged) { await GithubUtils.octokit.pulls.update({ owner: CONST.GITHUB_OWNER, repo: CONST.APP_REPO,