|
| 1 | +name: Engineering Task Handler |
| 2 | + |
| 3 | +# Controls when the workflow will run |
| 4 | +on: |
| 5 | + # Trigger only on pull request merge to master |
| 6 | + pull_request: |
| 7 | + types: [closed] |
| 8 | + branches: [master] |
| 9 | + |
| 10 | + # Manual trigger for testing |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +# A workflow run is made up of one or more jobs |
| 14 | +jobs: |
| 15 | + handle-engineering-task: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + # Only run if PR was actually merged (not just closed) |
| 18 | + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + pull-requests: read |
| 22 | + steps: |
| 23 | + - name: Checkout Code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Send Engineering Task Webhook |
| 27 | + run: | |
| 28 | + echo "Processing merged PR to master branch..." |
| 29 | +
|
| 30 | + # Get the complete GitHub event payload |
| 31 | + EVENT_PAYLOAD='${{ toJson(github.event) }}' |
| 32 | +
|
| 33 | + # Extract key information for logging |
| 34 | + PR_NUMBER="${{ github.event.pull_request.number }}" |
| 35 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 36 | + PR_AUTHOR="${{ github.event.pull_request.user.login }}" |
| 37 | + REPO="${{ github.repository }}" |
| 38 | +
|
| 39 | + echo "PR #${PR_NUMBER}: ${PR_TITLE}" |
| 40 | + echo "Author: ${PR_AUTHOR}" |
| 41 | + echo "Repository: ${REPO}" |
| 42 | + echo "Sending complete event payload to webhook..." |
| 43 | +
|
| 44 | + # Send POST request to the engineering task webhook with complete event data |
| 45 | + HTTP_STATUS=$(curl -w "%{http_code}" -s -o /tmp/webhook_response.txt \ |
| 46 | + -X POST \ |
| 47 | + -H "Content-Type: application/json" \ |
| 48 | + -H "User-Agent: GitHub-Actions-AI-Agent-Service" \ |
| 49 | + -H "X-GitHub-Event: pull_request" \ |
| 50 | + -H "X-GitHub-Repository: ${{ github.repository }}" \ |
| 51 | + --data "$EVENT_PAYLOAD" \ |
| 52 | + "${{ secrets.ENGINEERING_TASK_WEBHOOK_URL }}") |
| 53 | +
|
| 54 | + echo "HTTP Status Code: $HTTP_STATUS" |
| 55 | + echo "Response body:" |
| 56 | + cat /tmp/webhook_response.txt |
| 57 | +
|
| 58 | + # Check if the request was successful |
| 59 | + if [[ "$HTTP_STATUS" -ge 200 && "$HTTP_STATUS" -lt 300 ]]; then |
| 60 | + echo "✅ Engineering task webhook sent successfully" |
| 61 | + echo "PR merge event processed for engineering tasks" |
| 62 | + else |
| 63 | + echo "❌ Engineering task webhook failed with status: $HTTP_STATUS" |
| 64 | + echo "Response:" |
| 65 | + cat /tmp/webhook_response.txt |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + # Handle webhook failures |
| 70 | + - name: Handle Webhook Failure |
| 71 | + if: failure() |
| 72 | + run: | |
| 73 | + echo "🚨 Engineering task webhook failed!" |
| 74 | + echo "PR #${{ github.event.pull_request.number }} merge event could not be processed" |
| 75 | + echo "Repository: ${{ github.repository }}" |
| 76 | + echo "Author: ${{ github.event.pull_request.user.login }}" |
| 77 | + echo "Please check the webhook endpoint manually or contact the engineering team" |
| 78 | +
|
| 79 | + # Optional: Send a fallback notification (if you have Slack webhook configured) |
| 80 | + if [[ -n "${{ secrets.DEV_CHANNEL_SLACK_WEBHOOK_URL }}" ]]; then |
| 81 | + echo "Sending failure notification to Slack..." |
| 82 | + curl -X POST -H 'Content-type: application/json' \ |
| 83 | + --data '{ |
| 84 | + "text": "🚨 AI Agent Service: Engineering Task Webhook Failed", |
| 85 | + "attachments": [{ |
| 86 | + "color": "#d73a49", |
| 87 | + "blocks": [ |
| 88 | + { |
| 89 | + "type": "header", |
| 90 | + "text": { |
| 91 | + "type": "plain_text", |
| 92 | + "text": "Engineering Task Alert" |
| 93 | + } |
| 94 | + }, |
| 95 | + { |
| 96 | + "type": "section", |
| 97 | + "text": { |
| 98 | + "type": "mrkdwn", |
| 99 | + "text": "*Webhook Failure*\nFailed to process PR merge event for engineering tasks.\n\n*PR:* #${{ github.event.pull_request.number }}\n*Repository:* ${{ github.repository }}\n*Author:* ${{ github.event.pull_request.user.login }}" |
| 100 | + } |
| 101 | + }, |
| 102 | + { |
| 103 | + "type": "actions", |
| 104 | + "elements": [ |
| 105 | + { |
| 106 | + "type": "button", |
| 107 | + "text": { |
| 108 | + "type": "plain_text", |
| 109 | + "text": "View PR" |
| 110 | + }, |
| 111 | + "url": "${{ github.event.pull_request.html_url }}", |
| 112 | + "style": "primary" |
| 113 | + } |
| 114 | + ] |
| 115 | + } |
| 116 | + ] |
| 117 | + }] |
| 118 | + }' \ |
| 119 | + ${{ secrets.DEV_CHANNEL_SLACK_WEBHOOK_URL }} || echo "Slack notification also failed" |
| 120 | + fi |
0 commit comments