Skip to content

[#199] Updated api request to use new github projects beta api #16

[#199] Updated api request to use new github projects beta api

[#199] Updated api request to use new github projects beta api #16

name: Update Issue Status and Move to Done in Project
on:
pull_request:
types: [closed]
jobs:
update-status:
runs-on: ubuntu-latest
steps:
# Step 1: Get the Issue Number from PR Title or Body
- name: Get Issue Number from PR Title or Body
id: get_issue_number
run: |
# Try to extract issue number from PR title or body using regex
issue_number=$(echo "${{ github.event.pull_request.title }}" | grep -o '#[0-9]\+' | sed 's/#//')
if [ -z "$issue_number" ]; then
issue_number=$(echo "${{ github.event.pull_request.body }}" | grep -o '#[0-9]\+' | sed 's/#//')
fi
if [ -z "$issue_number" ]; then
echo "No issue number found in the PR title or body."
exit 1
fi
echo "Found issue number: $issue_number"
echo "issue_number=$issue_number" >> $GITHUB_ENV
# Step 2: Add 'Status: Done' comment to the issue
- name: Add 'Status Done' comment to the issue
run: |
issue_number=${{ env.issue_number }}
echo "Adding 'Status: Done' comment to issue #$issue_number."
curl -X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-d '{"body": "Status: Done"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue_number/comments"
# Step 3: Move Issue to 'Done' in Project
- name: Move Issue to 'Done' in Project
run: |
issue_number=${{ env.issue_number }}
project_id="1314"
echo "Moving issue #$issue_number to project with ID $project_id"
# Use GraphQL API to add the issue to the project
query='
mutation {
addProjectV2ItemById(input: {projectId: "'$project_id'", contentId: "Issue/'$issue_number'"}) {
item {
id
content {
... on Issue {
title
number
}
}
}
}
}'
response=$(curl -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-X POST -d "{\"query\": \"$query\"}" \
https://api.github.com/graphql)
echo "$response"