[#199] Fixed the API URL to get project cards in update-issue-status.yml #10
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..." | |
# Get the project ID by listing projects in the repository | |
project_name="My Project" # Replace this with the name of your project | |
project_id=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-s "https://api.github.com/repos/${{ github.repository }}/projects" | \ | |
jq -r ".[] | select(.name == \"$project_name\") | .id") | |
if [ -z "$project_id" ]; then | |
echo "Project '$project_name' not found in the repository." | |
exit 1 | |
fi | |
echo "Found project ID: $project_id" | |
# Get all columns in the project to find the 'Done' column | |
done_column_id=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-s "https://api.github.com/repos/${{ github.repository }}/projects/${project_id}/columns" | \ | |
jq -r '.[] | select(.name == "Done") | .id') | |
if [ -z "$done_column_id" ]; then | |
echo "Done column not found. Please ensure the column exists in the project." | |
exit 1 | |
fi | |
echo "Found 'Done' column ID: $done_column_id" | |
# Get all project cards in the project | |
project_cards=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-s "https://api.github.com/repos/${{ github.repository }}/projects/${project_id}/columns/cards") | |
# Look for the project card that matches the issue number | |
project_card_id=$(echo "$project_cards" | jq -r '.[] | select(.content_url | contains("/issues/'$issue_number'")) | .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" | |
# 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 }} | |