Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mghilardelli authored Oct 16, 2024
1 parent ddef09c commit d9a403d
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
types: [created]

permissions:
issues: write
issues: write # Grant permission to write to issues

jobs:
approval:
runs-on: ubuntu-latest
Expand All @@ -17,20 +17,40 @@ jobs:
ISSUE_NUMBER=${{ github.event.issue.number }}
APPROVER=${{ github.actor }}
# Add approval label based on the approver
if [[ "$APPROVER" == "product-owner-username" ]]; then
# 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 -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
-d '{"labels":["Product Owner Approved"]}'
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\"]}"
# Update the issue body with the approver's name
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)
# Append the checkbox to the existing body
NEW_BODY="$(echo "$ISSUE_BODY" | jq -r '.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\"}"

0 comments on commit d9a403d

Please sign in to comment.