[#199] Resolving issue with update-issue-status #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Issue Status and Project | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
check-pr-for-issue: | |
runs-on: ubuntu-latest | |
outputs: | |
issue-number: ${{ steps.check-issue.outputs.issue-number }} | |
steps: | |
- name: Get PR Title and Body | |
id: get-pr-data | |
run: | | |
echo "PR Title: ${{ github.event.pull_request.title }}" | |
echo "PR Body: ${{ github.event.pull_request.body }}" | |
echo "::set-output name=pr-title::${{ github.event.pull_request.title }}" | |
echo "::set-output name=pr-body::${{ github.event.pull_request.body }}" | |
- name: Check for Issue Number in PR Title or Body | |
id: check-issue | |
run: | | |
# Look for issue numbers in PR title or body | |
issue_number=$(echo "${{ steps.get-pr-data.outputs.pr-title }} ${{ steps.get-pr-data.outputs.pr-body }}" | grep -oP '#([0-9]+)' | head -n 1 | sed 's/#//') | |
if [[ -z "$issue_number" ]]; then | |
echo "No issue number found." | |
echo "::set-output name=issue-number::none" | |
else | |
echo "Found issue number: $issue_number" | |
echo "::set-output name=issue-number::$issue_number" | |
fi | |
update-status: | |
needs: check-pr-for-issue | |
runs-on: ubuntu-latest | |
if: needs.check-pr-for-issue.outputs.issue-number != 'none' # Only run if issue number is found | |
steps: | |
- name: Update Issue Status to "Done" | |
uses: peter-evans/create-or-update-comment@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ needs.check-pr-for-issue.outputs.issue-number }} | |
body: "Status: Done" | |
- name: Move Issue Card to 'Done' Column in Project | |
run: | | |
# Ensure the issue number is properly assigned | |
issue_number=${{ needs.check-pr-for-issue.outputs.issue-number }} | |
echo "Moving issue #$issue_number to 'Done' column in the project..." | |
# Fetch the issue details (we'll use the GitHub API to find the project cards) | |
project_url="https://api.github.com/repos/${{ github.repository }}/issues/$issue_number" | |
# Get the project cards associated with the issue | |
project_cards=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s $project_url) | |
# Debug: Print the project cards JSON to check the structure | |
echo "Project Cards: $project_cards" | |
# Extract the first project card ID from the JSON response (if it exists) | |
project_card_id=$(echo "$project_cards" | jq -r '.[0].id') | |
if [ -z "$project_card_id" ]; then | |
echo "No project card found for issue #$issue_number" | |
exit 1 | |
fi | |
echo "Found project card ID: $project_card_id" | |
# Specify the 'Done' column ID (replace this with your actual column ID) | |
done_column_id=<YOUR_DONE_COLUMN_ID> | |
if [ -z "$done_column_id" ]; then | |
echo "Done column ID not set. Please provide a valid column ID." | |
exit 1 | |
fi | |
# Move the project card to the 'Done' column | |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-d '{"column_id": "'$done_column_id'"}' \ | |
"https://api.github.com/projects/columns/cards/$project_card_id/moves" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |