From f87e481b12d8c6d1f98cf2a004684a1e6a78a17f Mon Sep 17 00:00:00 2001 From: Mic Date: Wed, 17 Sep 2025 23:18:23 +0200 Subject: [PATCH] added a wf to add a comment on a bug issue without the integration reported --- .../issues-validate-integration-field.yml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/.github/workflows/issues-validate-integration-field.yml b/.github/workflows/issues-validate-integration-field.yml index e69de29b..83f2153a 100644 --- a/.github/workflows/issues-validate-integration-field.yml +++ b/.github/workflows/issues-validate-integration-field.yml @@ -0,0 +1,75 @@ +name: Validate Integration Field + +on: + issues: + types: [opened, edited] + +permissions: + issues: write + +jobs: + check-integration: + runs-on: ubuntu-latest + steps: + - name: Validate dropdown selection (only for bug report form) + uses: actions/github-script@v7 + with: + script: | + const issue = context.payload.issue; + const bodyText = issue.body || ""; + + // ---- Guard: only act if this looks like a Bug Report form ---- + if (!bodyText.includes("### The problem")) { + core.info("Skipped: This issue does not contain '### The problem', so it is not a Bug Report."); + return; + } + core.info("Detected a Bug Report issue. Proceeding with validation..."); + + // Extract selection under "Which integration are you using?" + const header = "### Which integration are you using?"; + const nextHeaderRegex = /\n### /; + let selection = ""; + + const startIdx = bodyText.indexOf(header); + if (startIdx !== -1) { + const afterHeader = bodyText.slice(startIdx + header.length).replace(/^\r?\n+/, ""); + const nextHeaderIdx = afterHeader.search(nextHeaderRegex); + selection = (nextHeaderIdx === -1 ? afterHeader : afterHeader.slice(0, nextHeaderIdx)).trim(); + } + + core.info(`Integration field extracted: "${selection}"`); + + const isInvalid = !selection || selection.startsWith("-- Select an option"); + if (isInvalid) { + core.info("Integration field is invalid or not selected."); + } else { + core.info("Integration field is valid. Nothing to do."); + } + + const owner = context.repo.owner; + const repo = context.repo.repo; + const issue_number = issue.number; + + // Avoid duplicate comments + const marker = "please specify **Which integration are you using?**"; + const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number }); + const alreadyCommented = comments.some(c => c.body && c.body.includes(marker)); + + if (isInvalid) { + if (!alreadyCommented) { + core.info("No existing reminder found. Posting a new comment..."); + await github.rest.issues.createComment({ + owner, repo, issue_number, + body: [ + `👋 Hello @${issue.user.login}!`, + `To complete your bug report, please specify which integration you are using.`, + "", + "Right now the field `**Which integration are you using?**` is set to `-- Select an option --`.", + "", + "Click **Edit** at the top right of the issue, choose a valid option from the dropdown, and save.", + ].join("\n") + }); + } else { + core.info("Reminder comment already exists. Skipping new comment."); + } + }