Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ jobs:
return 1
}

comment_from_user() {
if [[ "${COMMENT_USER_TYPE}" == "Bot" ]]; then
echo "::notice::Skipping dispatch for bot comment"
return 1
fi
return 0
}
comment_from_authorized_user() {
if ! is_authorized; then
echo "::notice::Skipping dispatch for unauthorized comment from ${COMMENT_USER_LOGIN}"
return 1
fi
return comment_from_user
}
Comment on lines +110 to +123

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Dispatch routing checks out-of-sync 📘 Rule violation ⚙ Maintainability

internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml centralizes bot/authorization
checks into comment_from_user/comment_from_authorized_user with notice annotations, but
.github/workflows/reusable-dispatch.yml still uses the older inline COMMENT_USER_TYPE != "Bot" +
is_authorized checks. This violates the requirement to keep dispatch routing logic in sync across
the two workflows and can cause different behavior/diagnostics between scaffolded repos and the
reusable workflow.
Agent Prompt
## Issue description
The bot/authorization gating and skip-notice behavior was updated in `internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml` (via `comment_from_user` and `comment_from_authorized_user` helpers), but the reusable workflow `.github/workflows/reusable-dispatch.yml` still uses the previous inline checks. This breaks the compliance requirement that routing/dispatch logic stays aligned across both workflows.

## Issue Context
PR intent is to "Emit notice annotations when bot or unauthorized comments are ignored, and centralize those checks in shared helpers." Only the scaffold dispatch workflow was updated.

## Fix Focus Areas
- .github/workflows/reusable-dispatch.yml[180-243]
- internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml[110-190]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +117 to +123

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Bad bash return value 🐞 Bug ≡ Correctness

comment_from_authorized_user() uses return comment_from_user, but return requires a numeric
status, so the function errors and returns non-zero even for authorized human comments. As a result,
every if comment_from_authorized_user; then ... branch is skipped and comment-triggered stages
won’t dispatch.
Agent Prompt
## Issue description
`comment_from_authorized_user()` attempts to delegate to `comment_from_user()` via `return comment_from_user`, which is invalid in bash because `return` accepts only an integer exit code. This causes authorized human comments to fail the `if comment_from_authorized_user; then` checks and prevents `STAGE` from being set.

## Issue Context
This is inside the `Determine stage` script (`set -euo pipefail`). The helper is used as the gate for multiple slash commands.

## Fix Focus Areas
- internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml[110-123]

## Suggested change
Replace the invalid return with actually calling the function and returning its exit status, e.g.:
```bash
comment_from_authorized_user() {
  if ! is_authorized; then
    echo "::notice::Skipping dispatch for unauthorized comment from ${COMMENT_USER_LOGIN}" 
    return 1
  fi
  comment_from_user
  return $?
}
```
(or make `comment_from_user` the last command without an explicit `return` argument).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +110 to +123

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Bot notice precedence wrong 🐞 Bug ◔ Observability

comment_from_authorized_user() checks is_authorized before the bot filter, so an unauthorized
bot comment emits the “unauthorized comment” notice and never emits the intended bot-skip notice.
This also performs an unnecessary permission check (gh api) for bot comments that could be
rejected immediately.
Agent Prompt
## Issue description
For comment-triggered dispatches, the new helper logs skip reasons. However, `comment_from_authorized_user()` checks authorization first and only then calls the bot filter, which means bot comments that aren’t authorized get logged as “unauthorized” instead of “bot comment”, and still incur a permission API call.

## Issue Context
`is_authorized()` calls `has_write_permission()`, which uses `gh api` to query collaborator permissions.

## Fix Focus Areas
- internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml[60-86]
- internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml[110-123]

## Suggested change
Reorder the checks so bot filtering happens first:
```bash
comment_from_authorized_user() {
  if ! comment_from_user; then
    return 1
  fi
  if ! is_authorized; then
    echo "::notice::Skipping dispatch for unauthorized comment from ${COMMENT_USER_LOGIN}"
    return 1
  fi
  return 0
}
```
This ensures bot comments always produce the bot notice and avoids calling the permission API for bots.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


# Extract the first word of the comment as the command
COMMAND=""
if [[ -n "${COMMENT_BODY:-}" ]]; then
Expand All @@ -117,34 +132,34 @@ jobs:
issue_comment)
case "${COMMAND}" in
/fs-triage)
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
STAGE="triage"
fi
;;
/fs-code)
if [[ "${ISSUE_HAS_PR}" == "false" ]]; then
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
STAGE="code"
fi
fi
;;
/fs-review)
if [[ "${ISSUE_HAS_PR}" == "true" ]]; then
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
STAGE="review"
fi
fi
;;
/fs-fix)
if [[ "${ISSUE_HAS_PR}" == "true" ]]; then
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
STAGE="fix"
TRIGGER_SOURCE="${COMMENT_USER_LOGIN}"
fi
fi
;;
/fs-retro|/fullsend)
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
if [[ "${COMMAND}" == "/fullsend" ]]; then
SECOND_WORD="$(printf '%s\n' "${COMMENT_BODY}" | head -1 | tr -d '\r' | awk '{print $2}')"
if [[ "${SECOND_WORD}" == "retro" ]]; then
Expand All @@ -156,7 +171,7 @@ jobs:
fi
;;
/fs-prioritize)
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]] && is_authorized; then
if comment_from_authorized_user; then
STAGE="prioritize"
fi
;;
Expand All @@ -165,7 +180,7 @@ jobs:
# re-trigger triage by providing clarification on needs-info
# issues. Full write-permission check is not required here.
if has_label "needs-info" && ! has_label "feature"; then
if [[ "${COMMENT_USER_TYPE}" != "Bot" ]]; then
if comment_from_user; then
if [[ "${COMMENT_AUTHOR_ASSOC}" != "NONE" ]] || is_issue_author; then
STAGE="triage"
fi
Expand Down
8 changes: 6 additions & 2 deletions internal/scaffold/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,13 @@ func TestDispatchWorkflowContent(t *testing.T) {
assert.Contains(t, s, `COMMENT_AUTHOR_ASSOC`)
// Auto-triage requires assoc != NONE or issue author
assert.Contains(t, s, "is_issue_author")
// Bot filtering
// Bot filtering and skip notices via shared helpers
assert.Contains(t, s, `COMMENT_USER_TYPE`)
assert.Contains(t, s, `!= "Bot"`)
assert.Contains(t, s, `comment_from_user`)
assert.Contains(t, s, `comment_from_authorized_user`)
assert.Contains(t, s, `== "Bot"`)
assert.Contains(t, s, `Skipping dispatch for bot comment`)
assert.Contains(t, s, `Skipping dispatch for unauthorized comment`)
// No-fix label check (uses PR_LABELS for pull_request_review events)
assert.Contains(t, s, "fullsend-no-fix")
assert.Contains(t, s, "PR_LABELS")
Expand Down
Loading