Skip to content

Refactor Bug Conductor workflow for better automation - #22

Merged
thevalleydev merged 1 commit into
mainfrom
thevalleydev-patch-2
Mar 22, 2026
Merged

Refactor Bug Conductor workflow for better automation#22
thevalleydev merged 1 commit into
mainfrom
thevalleydev-patch-2

Conversation

@thevalleydev

Copy link
Copy Markdown
Owner

Updated the Bug Conductor workflow to trigger on issue creation and comments, added shadow PR creation, and improved handling of issue comments.

Updated the Bug Conductor workflow to trigger on issue creation and comments, added shadow PR creation, and improved handling of issue comments.
Copilot AI review requested due to automatic review settings March 22, 2026 15:07
@thevalleydev
thevalleydev merged commit 630dacf into main Mar 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Refactors the Bug Conductor GitHub Action to kick off automation on issue creation, create a “shadow” draft PR workspace for Copilot, and mirror conversation between the shadow PR and the originating issue.

Changes:

  • Trigger workflow on issues: opened, issue_comment: created, and pull_request events.
  • Add automation to create a shadow branch + draft PR and post an @copilot kickoff comment on that PR.
  • Add jobs to mirror comments from shadow PRs back to the source issue, label PRs, and close/label issues on merge.

Comment on lines +67 to +71
**Title:** ${{ github.event.issue.title }}

**Body:**
${{ github.event.issue.body }}

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

The PR body heredoc directly interpolates ${{ github.event.issue.title }} and ${{ github.event.issue.body }} into a shell run: step. Issue content is user-controlled; this can break the script or enable shell injection if it contains quotes, $(), backticks, or EOF markers. Pass these values via env: and use a quoted heredoc (<<'EOF') / --body-file to prevent evaluation.

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +98
PR_NUMBER=$(gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
--label "copilot-shadow" \
--label "agent-analyzing" \

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

This assumes the PR labels copilot-shadow and agent-analyzing already exist. GitHub API/CLI calls will fail if the labels are missing (common in forks/new repos). Consider creating labels if absent or using a fallback behavior.

Suggested change
PR_NUMBER=$(gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
--label "copilot-shadow" \
--label "agent-analyzing" \
LABEL_ARGS=""
# Ensure labels exist, then build LABEL_ARGS safely.
if gh label list --limit 1000 | grep -q "^copilot-shadow\b"; then
LABEL_ARGS="$LABEL_ARGS --label copilot-shadow"
else
if gh label create "copilot-shadow" --color "5319e7" --description "Shadow PR for Copilot analysis"; then
LABEL_ARGS="$LABEL_ARGS --label copilot-shadow"
fi
fi
if gh label list --limit 1000 | grep -q "^agent-analyzing\b"; then
LABEL_ARGS="$LABEL_ARGS --label agent-analyzing"
else
if gh label create "agent-analyzing" --color "0e8a16" --description "PR currently under Copilot analysis"; then
LABEL_ARGS="$LABEL_ARGS --label agent-analyzing"
fi
fi
PR_NUMBER=$(gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
$LABEL_ARGS \

Copilot uses AI. Check for mistakes.
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE=${{ github.event.issue.number }}
gh issue edit "$ISSUE" --add-label "triage" --add-label "agent-analyzing"

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

This step adds triage and agent-analyzing labels via gh issue edit. If those labels don’t already exist, the command will fail and stop the workflow (and they aren’t defined in-repo like bug/article). Consider ensuring labels exist (create if missing) or making labeling best-effort.

Suggested change
gh issue edit "$ISSUE" --add-label "triage" --add-label "agent-analyzing"
gh issue edit "$ISSUE" --add-label "triage" --add-label "agent-analyzing" || echo "Labeling failed, continuing without labels."

Copilot uses AI. Check for mistakes.
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR=${{ github.event.issue.number }}
ISSUE=$(gh pr view "$PR" --json body --jq '.body' | sed -n 's/.*Source Issue: #\([0-9]\+\).*/\1/p')

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

Issue number extraction likely won’t work: the PR body uses **Source Issue:** #<n> but the sed pattern looks for Source Issue: #<n> (no **). This will produce an empty issue number and break mirroring; adjust the regex to tolerate the markdown or store the source issue in a more machine-readable way (e.g., PR label, branch name, or PR metadata).

Suggested change
ISSUE=$(gh pr view "$PR" --json body --jq '.body' | sed -n 's/.*Source Issue: #\([0-9]\+\).*/\1/p')
ISSUE=$(gh pr view "$PR" --json body --jq '.body' | sed -n 's/.*\*\*Source Issue:\*\* #\([0-9]\+\).*/\1/p')

Copilot uses AI. Check for mistakes.

for I in $ISSUES; do
gh issue edit "$I" --remove-label "agent-analyzing" --add-label "fixed"
gh issue close "$I" --comment "Closed automatically because PR #${PR} was merged."

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

This attempts to close issues referenced by Closes #... on every merged PR. GitHub often auto-closes these already, so gh issue close can become non-idempotent and fail when the issue is already closed. Consider checking issue state first (or tolerating "already closed"), and/or scoping this behavior to PRs managed by the bug conductor only.

Suggested change
gh issue close "$I" --comment "Closed automatically because PR #${PR} was merged."
STATE=$(gh issue view "$I" --json state -q '.state' || echo "")
if [ "$STATE" = "OPEN" ]; then
gh issue close "$I" --comment "Closed automatically because PR #${PR} was merged."
fi

Copilot uses AI. Check for mistakes.
if: github.event.label.name == 'bug'

create-shadow-pr:
if: github.event_name == 'issues' && github.event.action == 'opened'

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

create-shadow-pr runs on every newly opened issue. Since issue templates label bugs as bug and other issue types exist (e.g., article), this should be gated (e.g., require the bug label) to avoid creating shadow PRs for non-bug issues.

Suggested change
if: github.event_name == 'issues' && github.event.action == 'opened'
if: github.event_name == 'issues' && github.event.action == 'opened' && contains(github.event.issue.labels.*.name, 'bug')

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +18
DEFAULT_BRANCH: main
REPO_URL: https://github.com/thevalleydev/uncommitted

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

This workflow hard-codes DEFAULT_BRANCH and REPO_URL. That will break links/PR bases when running in forks or if the default branch changes; prefer ${{ github.event.repository.default_branch }} and ${{ github.server_url }}/${{ github.repository }}.

Suggested change
DEFAULT_BRANCH: main
REPO_URL: https://github.com/thevalleydev/uncommitted
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +100
PR_NUMBER=$(gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
--label "copilot-shadow" \
--label "agent-analyzing" \
--json number --jq '.number')

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

gh pr create is invoked with --json/--jq flags here. Those flags are not consistently supported for gh pr create across GH CLI versions and will likely fail at runtime. Prefer capturing the PR URL output and resolving the number via gh pr view, or use gh api to create the PR and parse the response JSON.

Suggested change
PR_NUMBER=$(gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
--label "copilot-shadow" \
--label "agent-analyzing" \
--json number --jq '.number')
gh pr create \
--draft \
--title "agent/issue-${ISSUE}-analysis" \
--body "$BODY" \
--base "${DEFAULT_BRANCH}" \
--head "$BRANCH" \
--label "copilot-shadow" \
--label "agent-analyzing"
PR_NUMBER=$(gh pr view "$BRANCH" --json number --jq '.number')

Copilot uses AI. Check for mistakes.
Comment on lines +184 to +187
run: |
ISSUE=${{ steps.issue.outputs.issue }}
AUTHOR="${{ github.event.comment.user.login }}"
BODY="${{ github.event.comment.body }}"

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

AUTHOR and especially BODY are populated by directly interpolating ${{ github.event.comment.* }} into a shell script. PR comments are user-controlled input and can inject shell syntax (quotes, $(), backticks), leading to command execution on the runner. Pass these values through env: (or read from $GITHUB_EVENT_PATH) and avoid direct expression interpolation inside run:.

Suggested change
run: |
ISSUE=${{ steps.issue.outputs.issue }}
AUTHOR="${{ github.event.comment.user.login }}"
BODY="${{ github.event.comment.body }}"
AUTHOR: ${{ github.event.comment.user.login }}
BODY: ${{ github.event.comment.body }}
run: |
ISSUE=${{ steps.issue.outputs.issue }}

Copilot uses AI. Check for mistakes.
Comment on lines +195 to +199
if: github.event_name == 'pull_request' && github.event.action == 'opened'
runs-on: ubuntu-latest

steps:
- name: Add labels to fix PR

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

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

This job runs on every PR opened event and will label all PRs as agent-fix, including unrelated PRs and the shadow PR created by this workflow. Add additional gating (e.g., head branch starts with agent/, exclude copilot-shadow, or require a specific author/label) before applying the label.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants