name: π Webhook Event Handler
# Central event router for GitHub OS Event Bus
# Addresses Issue #5 - Phase B: Event Bus Implementation
on:
issues:
types: [opened, labeled, closed, assigned, milestoned]
pull_request:
types: [opened, synchronize, closed, review_requested]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
push:
branches: [main]
workflow_run:
workflows: ["*"]
types: [completed]
permissions:
issues: write
pull-requests: write
actions: write
contents: read
jobs:
route-event:
runs-on: ubuntu-latest
name: Route Event to Appropriate Handler
steps:
- uses: actions/checkout@v4
- name: Log Event
run: |
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "π WEBHOOK EVENT RECEIVED"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "Event: ${{ github.event_name }}"
echo "Action: ${{ github.event.action }}"
echo "Actor: ${{ github.actor }}"
echo "Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"
- name: Route to Agent - Issue Opened
if: github.event_name == 'issues' && github.event.action == 'opened'
run: |
echo "π€ Routing to: IssueAgent"
echo "Task: Analyze new Issue #${{ github.event.issue.number }}"
# Check if Issue has agent-related labels
LABELS="${{ toJson(github.event.issue.labels.*.name) }}"
if echo "$LABELS" | grep -q "π€agent"; then
echo "β
Agent label detected, will auto-process"
# TODO: Trigger IssueAgent workflow when implemented
else
echo "βΉοΈ Regular issue, manual triage required"
fi
- name: Route to Agent - Issue Labeled with Execute
if: |
github.event_name == 'issues' &&
github.event.action == 'labeled' &&
github.event.label.name == 'π€agent-execute'
run: |
echo "π AGENT EXECUTION TRIGGERED"
echo "Issue: #${{ github.event.issue.number }}"
echo "Title: ${{ github.event.issue.title }}"
# Trigger CoordinatorAgent workflow
gh workflow run agent-runner.yml \
-f issue_number=${{ github.event.issue.number }} \
-f mode=autonomous \
|| echo "β οΈ agent-runner.yml not found yet (will be created in Issue #4)"
- name: Route to Agent - PR Opened
if: github.event_name == 'pull_request' && github.event.action == 'opened'
run: |
echo "π Routing to: ReviewAgent"
echo "PR: #${{ github.event.pull_request.number }}"
echo "Draft: ${{ github.event.pull_request.draft }}"
if [ "${{ github.event.pull_request.draft }}" == "false" ]; then
echo "β
Ready for review, triggering ReviewAgent"
# TODO: Trigger ReviewAgent workflow
else
echo "βΉοΈ Draft PR, skipping auto-review"
fi
- name: Route to Agent - Comment Command
if: github.event_name == 'issue_comment' && github.event.action == 'created'
run: |
COMMENT_BODY="${{ github.event.comment.body }}"
if echo "$COMMENT_BODY" | grep -q "^/agent"; then
echo "π¬ Agent command detected in comment"
echo "Command: $COMMENT_BODY"
# Parse command
COMMAND=$(echo "$COMMENT_BODY" | sed 's/^\/agent //')
case "$COMMAND" in
"analyze")
echo "π Triggering IssueAgent for analysis"
;;
"execute")
echo "π Triggering CoordinatorAgent for execution"
;;
"review")
echo "π Triggering ReviewAgent for code review"
;;
"status")
echo "π Fetching current status"
;;
*)
echo "β Unknown command: $COMMAND"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
-f body="β Unknown command: \`$COMMAND\`
Available commands:
- \`/agent analyze\` - Analyze Issue
- \`/agent execute\` - Start autonomous execution
- \`/agent review\` - Request code review
- \`/agent status\` - Check current status"
;;
esac
fi
- name: Route to Agent - PR Merged
if: |
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true
run: |
echo "π PR #${{ github.event.pull_request.number }} merged!"
echo "Branch: ${{ github.event.pull_request.head.ref }} β ${{ github.event.pull_request.base.ref }}"
# If merged to main, may trigger deployment
if [ "${{ github.event.pull_request.base.ref }}" == "main" ]; then
echo "π Merged to main, considering deployment..."
# TODO: Trigger DeploymentAgent if applicable
fi
- name: Route to Agent - Workflow Failed
if: |
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'failure'
run: |
echo "π¨ WORKFLOW FAILURE DETECTED"
echo "Workflow: ${{ github.event.workflow_run.name }}"
echo "Conclusion: ${{ github.event.workflow_run.conclusion }}"
echo "Run ID: ${{ github.event.workflow_run.id }}"
# Escalate to Guardian for critical failures
if echo "${{ github.event.workflow_run.name }}" | grep -qE "(agent-runner|economic-circuit-breaker)"; then
echo "π¨ Critical workflow failed, escalating to Guardian"
gh issue create \
--title "π¨ Critical Workflow Failure: ${{ github.event.workflow_run.name }}" \
--label "π₯Sev.1-Critical,π€AI-γ·γΉγγ " \
--assignee "${{ github.repository_owner }}" \
--body "## π¨ Critical Workflow Failure
**Workflow**: ${{ github.event.workflow_run.name }}
**Conclusion**: ${{ github.event.workflow_run.conclusion }}
**Run ID**: ${{ github.event.workflow_run.id }}
**Run URL**: ${{ github.event.workflow_run.html_url }}
This workflow is critical to Agentic OS operations. Immediate Guardian attention required.
### Next Steps
1. Review workflow logs
2. Identify root cause
3. Fix or rollback changes
4. Re-run workflow
---
**Escalated by**: Webhook Handler
**Timestamp**: $(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|| echo "β οΈ Failed to create escalation Issue"
fi
- name: Event Summary
if: always()
run: |
echo ""
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "π EVENT ROUTING SUMMARY"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β
Event processed: ${{ github.event_name }}.${{ github.event.action }}"
echo "π― Routing completed at: $(date -u +%H:%M:%S)"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββ"