From 21211afb7089e871195f8d027a7d02898e72accd Mon Sep 17 00:00:00 2001 From: Belle P Date: Mon, 18 Nov 2024 13:50:07 -0800 Subject: [PATCH] Get project and column id --- .github/workflows/update-issue-status.yml | 36 ++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-issue-status.yml b/.github/workflows/update-issue-status.yml index 50b8cd4..924504f 100644 --- a/.github/workflows/update-issue-status.yml +++ b/.github/workflows/update-issue-status.yml @@ -50,16 +50,14 @@ jobs: 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) + # Get the list of project cards associated with the issue + project_cards=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -s "https://api.github.com/repos/${{ github.repository }}/projects/columns/cards?issue=$issue_number") # 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) + # Check if project cards exist and extract the first card ID project_card_id=$(echo "$project_cards" | jq -r '.[0].id') if [ -z "$project_card_id" ]; then @@ -69,16 +67,34 @@ jobs: echo "Found project card ID: $project_card_id" - # Specify the 'Done' column ID (replace this with your actual column ID) - done_column_id= + # Dynamically get the project ID by listing the 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" + + # Dynamically get the 'Done' column ID by listing the columns in the project + 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 ID not set. Please provide a valid column ID." + echo "Done column not found. Please ensure the column exists in the project." exit 1 fi + echo "Found 'Done' column ID: $done_column_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 }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}