Skip to content

New Story

New Story #28

Workflow file for this run

name: Approval Tracking
on:
issues:
types: [edited]
permissions:
issues: write
jobs:
check_checkbox:
runs-on: ubuntu-latest
steps:
- name: Check if checkbox was edited
id: check_checkbox
run: |
echo "Issue Body: ${{ github.event.issue.body }}"
echo "User: ${{ github.event.issue.user.login }}"
# Extract previous issue body from the webhook event
PREVIOUS_BODY="${{ github.event.changes.body.from }}"
echo "Previous Body: $PREVIOUS_BODY"
# Extract currently checked checkboxes
CURRENT_CHECKED=$(echo "${{ github.event.issue.body }}" | grep -E '\- \[x\]')
echo "Current: $CURRENT_CHECKED"
PREVIOUS_CHECKED=$(echo "$PREVIOUS_BODY" | grep -E '\- \[x\]')
echo "Previous: $PREVIOUS_CHECKED"
# Check if there are new checked checkboxes
NEW_CHECKED_LINES=$(echo "$CURRENT_CHECKED" | grep -Fxv -f <(echo "$PREVIOUS_CHECKED"))
echo "New: $NEW_CHECKED_LINES"
# Check if any checkbox is checked
if [ -n "$NEW_CHECKED_LINES" ]; then
echo "Newly checked checkboxes found:"
echo "$NEW_CHECKED_LINES"
echo "checkbox_checked=true" >> $GITHUB_OUTPUT
echo "new_checked_lines=$NEW_CHECKED_LINES" >> $GITHUB_OUTPUT
else
echo "No checkbox checked."
echo "checkbox_checked=false" >> $GITHUB_OUTPUT
fi
- name: Comment on Issue
if: steps.check_checkbox.outputs.checkbox_checked == 'true'
run: |
USERNAME="${{ github.event.issue.user.login }}"
NEW_CHECKED_LINES="${{ steps.check_checkbox.outputs.new_checked_lines }}"
COMMENT="Checkboxes newly checked by @$USERNAME:\n$NEW_CHECKED_LINES"
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
-d "{\"body\": \"$COMMENT\"}"