|
| 1 | +name: 'Issue auto-implement' |
| 2 | +description: 'Assess labeled issues (or PR reviews), request more info or implement with verify loop; create PR or iterate on existing PR.' |
| 3 | +inputs: |
| 4 | + anthropic_api_key: |
| 5 | + description: 'API key for Claude (assessment and implement step)' |
| 6 | + required: true |
| 7 | + github_token: |
| 8 | + description: 'GitHub token (contents, issues, pull-requests, read:org)' |
| 9 | + required: true |
| 10 | + context_files: |
| 11 | + description: 'Comma-separated paths to repo files to include in assessment (e.g. AGENTS.md, REFERENCE.md)' |
| 12 | + required: false |
| 13 | + default: 'AGENTS.md,REFERENCE.md' |
| 14 | + assessment_reference_issue: |
| 15 | + description: 'Reference issue number for "enough information" example (e.g. 192)' |
| 16 | + required: false |
| 17 | + default: '192' |
| 18 | + label_prefix: |
| 19 | + description: 'Prefix for automation labels (e.g. automation/auto-implement, automation/needs-info, automation/pr-created)' |
| 20 | + required: false |
| 21 | + default: 'automation' |
| 22 | + verify_commands: |
| 23 | + description: 'Shell commands to run for verification (e.g. go test ./..., go build)' |
| 24 | + required: false |
| 25 | + default: 'go test ./...' |
| 26 | + max_implement_retries: |
| 27 | + description: 'Max retries for implement step on verify failure (default 3, max 5)' |
| 28 | + required: false |
| 29 | + default: '3' |
| 30 | + github_allowed_trigger_team: |
| 31 | + description: 'GitHub Team slug whose members may trigger the flow (e.g. hookdeck/automation-triggers). Set via repo variable AUTO_IMPLEMENT_ALLOWED_TRIGGER_TEAM.' |
| 32 | + required: true |
| 33 | +runs: |
| 34 | + using: 'composite' |
| 35 | + steps: |
| 36 | + - name: Check allowed trigger team |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + TEAM="${{ inputs.github_allowed_trigger_team }}" |
| 40 | + if [ -z "$TEAM" ]; then |
| 41 | + echo "::error::github_allowed_trigger_team must be set (e.g. repo variable AUTO_IMPLEMENT_ALLOWED_TRIGGER_TEAM). Only team members can trigger this workflow." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + ORG="${TEAM%/*}" |
| 45 | + SLUG="${TEAM#*/}" |
| 46 | + HTTP=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 47 | + -H "Authorization: Bearer ${{ inputs.github_token }}" \ |
| 48 | + -H "Accept: application/vnd.github+json" \ |
| 49 | + "https://api.github.com/orgs/${ORG}/teams/${SLUG}/members/${{ github.actor }}") |
| 50 | + if [ "$HTTP" != "204" ]; then |
| 51 | + echo "::error::Actor ${{ github.actor }} is not in team $TEAM (HTTP $HTTP). Only team members can trigger this workflow." |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + echo "Actor ${{ github.actor }} is in team $TEAM." |
| 55 | + - name: Ensure labels exist |
| 56 | + shell: bash |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 59 | + REPO: ${{ github.repository }} |
| 60 | + LABEL_PREFIX: ${{ inputs.label_prefix }} |
| 61 | + run: | |
| 62 | + for LABEL in auto-implement needs-info pr-created; do |
| 63 | + NAME="${LABEL_PREFIX}/${LABEL}" |
| 64 | + curl -s -o /dev/null -w "%{http_code}" \ |
| 65 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 66 | + -H "Accept: application/vnd.github+json" \ |
| 67 | + "https://api.github.com/repos/$REPO/labels" \ |
| 68 | + -d "{\"name\":\"$NAME\",\"color\":\"ededed\"}" | grep -q 201 || true |
| 69 | + done |
| 70 | + - name: Install assess script dependencies |
| 71 | + shell: bash |
| 72 | + run: cd .github/actions/issue-auto-implement/assess && npm ci --omit=dev |
| 73 | + - id: assess |
| 74 | + name: Run assess |
| 75 | + shell: bash |
| 76 | + env: |
| 77 | + ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }} |
| 78 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 79 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 80 | + ASSESSMENT_REFERENCE_ISSUE: ${{ inputs.assessment_reference_issue }} |
| 81 | + run: | |
| 82 | + RESULT=$(cd .github/actions/issue-auto-implement/assess && npx tsx index.ts) |
| 83 | + echo "action=$(echo "$RESULT" | jq -r '.action')" >> $GITHUB_OUTPUT |
| 84 | + echo "issue_number=$(echo "$RESULT" | jq -r '.issue_number // empty')" >> $GITHUB_OUTPUT |
| 85 | + echo "pr_url=$(echo "$RESULT" | jq -r '.pr_url // empty')" >> $GITHUB_OUTPUT |
| 86 | + echo "comment_body<<BODY_EOF" >> $GITHUB_OUTPUT |
| 87 | + echo "$RESULT" | jq -r '.comment_body // empty' >> $GITHUB_OUTPUT |
| 88 | + echo "BODY_EOF" >> $GITHUB_OUTPUT |
| 89 | + echo "verification_notes<<NOTES_EOF" >> $GITHUB_OUTPUT |
| 90 | + echo "$RESULT" | jq -r '.verification_notes // empty' >> $GITHUB_OUTPUT |
| 91 | + echo "NOTES_EOF" >> $GITHUB_OUTPUT |
| 92 | + - name: Handle redirect to PR |
| 93 | + if: steps.assess.outputs.action == 'redirect_to_pr' |
| 94 | + shell: bash |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 97 | + REPO: ${{ github.repository }} |
| 98 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 99 | + PR_URL: ${{ steps.assess.outputs.pr_url }} |
| 100 | + run: | |
| 101 | + BODY="A PR is open for this issue. Please review and comment on the PR: $PR_URL" |
| 102 | + curl -s -X POST \ |
| 103 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 104 | + -H "Accept: application/vnd.github+json" \ |
| 105 | + "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/comments" \ |
| 106 | + -d "{\"body\":$(echo "$BODY" | jq -Rs .)}" |
| 107 | + echo "Redirected user to PR. Exiting." |
| 108 | + exit 0 |
| 109 | + - name: Handle request more info |
| 110 | + if: steps.assess.outputs.action == 'request_info' |
| 111 | + shell: bash |
| 112 | + env: |
| 113 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 114 | + REPO: ${{ github.repository }} |
| 115 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 116 | + LABEL_PREFIX: ${{ inputs.label_prefix }} |
| 117 | + run: | |
| 118 | + COMMENT_BODY="${{ steps.assess.outputs.comment_body }}" |
| 119 | + curl -s -X POST \ |
| 120 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 121 | + -H "Accept: application/vnd.github+json" \ |
| 122 | + "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/comments" \ |
| 123 | + -d "$(jq -n --arg b "$COMMENT_BODY" '{body: $b}')" |
| 124 | + NEEDS_LABEL="${LABEL_PREFIX}/needs-info" |
| 125 | + curl -s -X POST \ |
| 126 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 127 | + -H "Accept: application/vnd.github+json" \ |
| 128 | + "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels" \ |
| 129 | + -d "{\"labels\":[\"$NEEDS_LABEL\"]}" |
| 130 | + echo "Posted request for more info. Exiting." |
| 131 | + exit 0 |
| 132 | + - name: Checkout branch for implement |
| 133 | + if: steps.assess.outputs.action == 'implement' |
| 134 | + shell: bash |
| 135 | + env: |
| 136 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 137 | + run: | |
| 138 | + BRANCH="auto-implement-issue-${ISSUE_NUMBER}" |
| 139 | + git fetch origin main |
| 140 | + if git show-ref --verify --quiet refs/remotes/origin/"$BRANCH"; then |
| 141 | + git checkout "$BRANCH" |
| 142 | + git merge origin/main --no-edit |
| 143 | + else |
| 144 | + git checkout -b "$BRANCH" origin/main |
| 145 | + fi |
| 146 | + - name: Implement |
| 147 | + if: steps.assess.outputs.action == 'implement' |
| 148 | + shell: bash |
| 149 | + env: |
| 150 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 151 | + VERIFICATION_NOTES: ${{ steps.assess.outputs.verification_notes }} |
| 152 | + ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }} |
| 153 | + run: | |
| 154 | + echo "Implement step: would run Claude Code Action or API here." |
| 155 | + echo "Verification notes: $VERIFICATION_NOTES" |
| 156 | + # Placeholder until Claude implement is wired; verify step will run next. |
| 157 | + - name: Push branch |
| 158 | + if: steps.assess.outputs.action == 'implement' |
| 159 | + shell: bash |
| 160 | + env: |
| 161 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 162 | + run: | |
| 163 | + BRANCH="auto-implement-issue-${ISSUE_NUMBER}" |
| 164 | + git push -u origin "$BRANCH" || true |
| 165 | + - id: verify_loop |
| 166 | + name: Verify (with retries) |
| 167 | + if: steps.assess.outputs.action == 'implement' |
| 168 | + shell: bash |
| 169 | + env: |
| 170 | + MAX_RETRIES: ${{ inputs.max_implement_retries }} |
| 171 | + VERIFY_CMDS: ${{ inputs.verify_commands }} |
| 172 | + run: | |
| 173 | + MAX=${MAX_RETRIES:-3} |
| 174 | + for i in $(seq 1 "$MAX"); do |
| 175 | + echo "Verify attempt $i of $MAX" |
| 176 | + if eval "$VERIFY_CMDS"; then |
| 177 | + echo "verified=true" >> $GITHUB_OUTPUT |
| 178 | + exit 0 |
| 179 | + fi |
| 180 | + done |
| 181 | + echo "verified=false" >> $GITHUB_OUTPUT |
| 182 | + echo "::error::Verification failed after $MAX attempts" |
| 183 | + exit 1 |
| 184 | + - name: Create PR |
| 185 | + if: steps.assess.outputs.action == 'implement' && steps.verify_loop.outcome == 'success' |
| 186 | + shell: bash |
| 187 | + env: |
| 188 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 189 | + REPO: ${{ github.repository }} |
| 190 | + ISSUE_NUMBER: ${{ steps.assess.outputs.issue_number }} |
| 191 | + LABEL_PREFIX: ${{ inputs.label_prefix }} |
| 192 | + run: | |
| 193 | + BRANCH="auto-implement-issue-${ISSUE_NUMBER}" |
| 194 | + TITLE="Auto-implement issue #${ISSUE_NUMBER}" |
| 195 | + BODY="Closes #${ISSUE_NUMBER}" |
| 196 | + PR_JSON=$(curl -s -X POST \ |
| 197 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 198 | + -H "Accept: application/vnd.github+json" \ |
| 199 | + "https://api.github.com/repos/$REPO/pulls" \ |
| 200 | + -d "{\"title\":\"$TITLE\",\"body\":\"$BODY\",\"head\":\"$BRANCH\",\"base\":\"main\"}") |
| 201 | + PR_URL=$(echo "$PR_JSON" | jq -r '.html_url // empty') |
| 202 | + if [ -n "$PR_URL" ]; then |
| 203 | + PR_NUM=$(echo "$PR_JSON" | jq -r '.number') |
| 204 | + NEEDS_LABEL="${LABEL_PREFIX}/pr-created" |
| 205 | + curl -s -X POST \ |
| 206 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 207 | + -H "Accept: application/vnd.github+json" \ |
| 208 | + "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels" \ |
| 209 | + -d "{\"labels\":[\"$NEEDS_LABEL\"]}" |
| 210 | + echo "Created PR: $PR_URL" |
| 211 | + fi |
0 commit comments