Skip to content

Instantly share code, notes, and snippets.

@arthurpalves
Created February 11, 2021 17:51
Show Gist options
  • Save arthurpalves/59f019c602b91cb91c310c6387ed9300 to your computer and use it in GitHub Desktop.
Save arthurpalves/59f019c602b91cb91c310c6387ed9300 to your computer and use it in GitHub Desktop.
Close Github Issues when the corresponding Project Card is moved to column "Done"
name: "Close issue"
on:
project_card:
types: [moved]
jobs:
close-issue:
name: "Close issue when card moves to Done column"
runs-on: ubuntu-latest
steps:
- name: Close issue
run: |
CARD=$(curl \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
https://api.github.com/projects/columns/cards/${{ github.event.project_card.id }})
COLUMN_URL=$(echo $CARD | jq -r '.column_url')
COLUMN_NAME=$(curl \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.inertia-preview+json" \
$COLUMN_URL \
| jq -r '.name')
if [[ $COLUMN_NAME == *"Done"* ]]; then
ISSUE_URL=$(echo $CARD | jq -r '.content_url')
echo "Closing issue: $ISSUE_URL"
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
$ISSUE_URL \
-d '{"state":"closed"}'
else
echo "Not closing issue as it was moved to column $COLUMN_NAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment