Repository navigation
feat: implement issue #591 — bug(initiative-planner): claude-code-action rejects discussion events — the idea:approved auto-trigger never plans
#618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| # redispatch.sh — bridge a `discussion [labeled]` event to a supported event. | ||
| # | ||
| # The initiative planner's documented primary trigger is a maintainer adding | ||
| # `idea:approved` to an Ideas Discussion, which fires `on: discussion [labeled]`. | ||
| # But the planner's "Plan the initiative" step uses claude-code-action, which | ||
| # only recognizes issues / pull_request / issue_comment / workflow_dispatch event | ||
| # contexts and aborts on a `discussion` event: | ||
| # | ||
| # Action failed with error: Unsupported event type: discussion | ||
| # | ||
| # So on the discussion event we DON'T plan inline; we resolve the discussion | ||
| # number and re-invoke the SAME workflow via workflow_dispatch, under which the | ||
| # action runs cleanly. The `idea:approved` label stays the human gate; the | ||
| # re-dispatch is an invisible bridge. | ||
| # | ||
| # IMPORTANT — the re-dispatch requires a PAT, not GITHUB_TOKEN: | ||
| # GitHub does not start new workflow runs from events created with the default | ||
| # GITHUB_TOKEN (loop prevention). A workflow_dispatch fired with GITHUB_TOKEN | ||
| # would be accepted but would NEVER start a run, so the caller MUST provide a | ||
| # PAT (GH_PAT_WORKFLOWS) as GH_TOKEN. This is the same constraint documented in | ||
| # scripts/initiative-driver.sh for the dev-lead label trigger. | ||
| # | ||
| # Env: | ||
| # REPO owner/repo (required) | ||
| # DISCUSSION_NUMBER Ideas Discussion number to plan (required) | ||
| # WORKFLOW_FILE workflow to dispatch (default: initiative-planner.yml) | ||
| # GH_TOKEN a PAT with workflow scope (required at the call site) | ||
| set -euo pipefail | ||
|
|
||
| REPO="${REPO:?REPO required}" | ||
| DISCUSSION_NUMBER="${DISCUSSION_NUMBER:?DISCUSSION_NUMBER required}" | ||
| WORKFLOW_FILE="${WORKFLOW_FILE:-initiative-planner.yml}" | ||
|
|
||
| # Validate before the value reaches the gh command line. | ||
| [[ "$DISCUSSION_NUMBER" =~ ^[0-9]+$ ]] || { | ||
| echo "::error::DISCUSSION_NUMBER must be a positive integer, got: '$DISCUSSION_NUMBER'" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| # Map DRY_RUN to a boolean string for the workflow input | ||
| if [[ "${DRY_RUN:-}" == "1" || "${DRY_RUN:-}" == "true" ]]; then | ||
| DISPATCH_DRY_RUN="true" | ||
| else | ||
| DISPATCH_DRY_RUN="false" | ||
| fi | ||
|
|
||
| # Use GITHUB_REF if it is a branch or tag to support testing on feature branches | ||
| REF_FLAGS=() | ||
| if [[ -n "${GITHUB_REF:-}" && ( "$GITHUB_REF" =~ ^refs/heads/ || "$GITHUB_REF" =~ ^refs/tags/ ) ]]; then | ||
| REF_FLAGS=(--ref "$GITHUB_REF") | ||
| fi | ||
|
|
||
| echo "Discussion event → re-dispatching ${WORKFLOW_FILE} for discussion #${DISCUSSION_NUMBER} via workflow_dispatch." | ||
| gh workflow run "$WORKFLOW_FILE" --repo "$REPO" "${REF_FLAGS[@]}" \ | ||
| -f discussion="$DISCUSSION_NUMBER" \ | ||
| -f dry_run="$DISPATCH_DRY_RUN" | ||
| echo "Dispatched ${WORKFLOW_FILE} (discussion=${DISCUSSION_NUMBER}, dry_run=${DISPATCH_DRY_RUN})." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env bats | ||
| # Unit tests for scripts/initiative-planner/redispatch.sh | ||
| # | ||
| # The planner's primary trigger is a `discussion [labeled]` event, but | ||
| # claude-code-action aborts on `discussion` event contexts. redispatch.sh bridges | ||
| # that gap by re-invoking the workflow via workflow_dispatch. These tests mock the | ||
| # gh CLI to avoid network calls and assert on the dispatched command. | ||
| # | ||
| # Run with: bats tests/test_initiative_planner_redispatch.bats | ||
|
|
||
| SCRIPT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)/scripts/initiative-planner/redispatch.sh" | ||
|
|
||
| setup() { | ||
| MOCK_BIN="$(mktemp -d)" | ||
| GH_LOG="$(mktemp)" | ||
| export GH_LOG | ||
| export PATH="$MOCK_BIN:$PATH" | ||
| export REPO="petry-projects/.github-private" | ||
| export DISCUSSION_NUMBER="572" | ||
| export GH_TOKEN="pat" | ||
|
|
||
| cat > "$MOCK_BIN/gh" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| printf '%s\n' "$*" >> "$GH_LOG" | ||
| exit 0 | ||
| EOF | ||
| chmod +x "$MOCK_BIN/gh" | ||
| } | ||
|
|
||
| teardown() { | ||
| rm -rf "${MOCK_BIN:-}" | ||
| rm -f "${GH_LOG:-}" | ||
| } | ||
|
|
||
| @test "re-dispatches the planner workflow via workflow_dispatch" { | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF "workflow run initiative-planner.yml" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "threads the discussion number and forces dry_run=false" { | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF -- "-f discussion=572" "$GH_LOG" | ||
| grep -qF -- "-f dry_run=false" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "targets the correct repo" { | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF -- "--repo petry-projects/.github-private" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "fails when DISCUSSION_NUMBER is unset" { | ||
| unset DISCUSSION_NUMBER | ||
| run bash "$SCRIPT" | ||
| [ "$status" -ne 0 ] | ||
| [ ! -s "$GH_LOG" ] | ||
| } | ||
|
|
||
| @test "rejects a non-numeric DISCUSSION_NUMBER without dispatching" { | ||
| export DISCUSSION_NUMBER="572; rm -rf /" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -ne 0 ] | ||
| [[ "$output" == *"positive integer"* ]] | ||
| [ ! -s "$GH_LOG" ] | ||
| } | ||
|
|
||
| @test "fails when REPO is unset" { | ||
| unset REPO | ||
| run bash "$SCRIPT" | ||
| [ "$status" -ne 0 ] | ||
| } | ||
|
|
||
| @test "honors a WORKFLOW_FILE override" { | ||
| export WORKFLOW_FILE="other-planner.yml" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF "workflow run other-planner.yml" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "honors DRY_RUN=1 or DRY_RUN=true" { | ||
| export DRY_RUN="1" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF -- "-f dry_run=true" "$GH_LOG" | ||
|
|
||
| export DRY_RUN="true" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF -- "-f dry_run=true" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "passes GITHUB_REF if it is a branch or tag" { | ||
| export GITHUB_REF="refs/heads/feature-branch" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -qF -- "--ref refs/heads/feature-branch" "$GH_LOG" | ||
| } | ||
|
|
||
| @test "ignores GITHUB_REF if it is a pull request ref" { | ||
| export GITHUB_REF="refs/pull/123/merge" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| ! grep -qF -- "--ref" "$GH_LOG" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.