Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Workflow for closing issues on merging PR #131

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/close-on-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Close Issues on PR Merge

on:
pull_request:
types: [closed]

jobs:
close-issues:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Close linked issues
if: github.event.pull_request.merged == true
run: |
# Extract issue numbers from the PR body
ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#')

# Loop through each extracted issue number and close the issue
for ISSUE in $ISSUES
do
echo "Closing issue #$ISSUE"
# Post a comment to the issue indicating it was closed by the merged PR
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/comments \
-d "{\"body\":\"Closed by PR #${{ github.event.pull_request.number }}\"}"
# Close the issue by updating its state to "closed"
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 \
-d "{\"state\":\"closed\"}"
done
Loading