Skip to content

My Story

My Story #9

Workflow file for this run

name: Approval Tracking
on:
issue_comment:
types: [created]
permissions:
issues: write # Grant permission to write to issues
jobs:
approval:
runs-on: ubuntu-latest
steps:
- name: Check for approval comment
if: contains(github.event.comment.body, '/approve')
run: |
ISSUE_NUMBER=${{ github.event.issue.number }}
APPROVER=${{ github.actor }}
# Determine the appropriate label based on the approver
if [[ "$APPROVER" == "mghilardelli" ]]; then
LABEL="Product Owner Approved"
CHECKBOX="Product Owner: @${APPROVER} - ✅"
elif [[ "$APPROVER" == "developer-username" ]]; then
LABEL="Developer Approved"
CHECKBOX="Developer: @${APPROVER} - ✅"
elif [[ "$APPROVER" == "qa-username" ]]; then
LABEL="QA Approved"
CHECKBOX="QA: @${APPROVER} - ✅"
else
echo "User not authorized to approve."
exit 1
fi
# Add the appropriate label
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/labels \
-d "{\"labels\":[\"$LABEL\"]}"
# Fetch the current issue body
ISSUE_BODY=$(curl -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER)
# Extract the current body and append the checkbox
CURRENT_BODY=$(echo "$ISSUE_BODY" | jq -r '.body')
NEW_BODY="${CURRENT_BODY}\n- [x] ${CHECKBOX}"
# Update the issue with the new body
curl -X PATCH \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER \
-d "{\"body\":\"${NEW_BODY}\"}"