From d4b4880e0d2d9b31ff445681e186e79b422d62d8 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Tue, 2 Jun 2026 11:52:47 +0200 Subject: [PATCH] fix(pocketbase-bot): recognize /pocketbase command on any line of a comment - Job gate uses contains() instead of startsWith() so comments with leading text still trigger the bot - Script scans all lines for the first one starting with /pocketbase, instead of only reading line 0 - Command-line detection moved above the permission check so mid-sentence mentions exit silently without a "not authorized" reply Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/pocketbase-bot.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pocketbase-bot.yml b/.github/workflows/pocketbase-bot.yml index 3c649b973..9d824348d 100644 --- a/.github/workflows/pocketbase-bot.yml +++ b/.github/workflows/pocketbase-bot.yml @@ -13,8 +13,8 @@ jobs: pocketbase-bot: runs-on: self-hosted - # Only act on /pocketbase commands - if: startsWith(github.event.comment.body, '/pocketbase') + # Act on comments that contain a /pocketbase command line (precise line check happens in-script) + if: contains(github.event.comment.body, '/pocketbase') steps: - name: Execute PocketBase bot command @@ -257,6 +257,22 @@ jobs: if (!res.ok) console.warn('Could not post comment:', res.body); } + // ── Locate the command line ──────────────────────────────────────── + // Accept /pocketbase at the start of ANY line (leading whitespace ok), + // so the command works even when preceded by other text. Mid-sentence + // mentions and blockquoted ("> ...") examples are ignored. + const commentBody = process.env.COMMENT_BODY || ''; + const cmdLine = commentBody + .split('\n') + .map(l => l.trim()) + .find(l => l.startsWith('/pocketbase')); + + if (!cmdLine) { + console.log('No /pocketbase command line found — ignoring comment.'); + process.exit(0); + } + const withoutCmd = cmdLine.replace(/^\/pocketbase\s*/, '').trim(); + // ── Permission check ─────────────────────────────────────────────── const association = process.env.ACTOR_ASSOCIATION; if (association !== 'OWNER' && association !== 'MEMBER') { @@ -272,10 +288,6 @@ jobs: await addReaction('eyes'); // ── Parse command ────────────────────────────────────────────────── - const commentBody = process.env.COMMENT_BODY || ''; - const lines = commentBody.trim().split('\n'); - const firstLine = lines[0].trim(); - const withoutCmd = firstLine.replace(/^\/pocketbase\s+/, '').trim(); function extractCodeBlock(body) { const m = body.match(/```[^\n]*\n([\s\S]*?)```/);