Skip to content

test10

test10 #12

name: Add Issue to Project
on:
issues:
types: [opened]
jobs:
add-issue-to-project:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get issue ID
id: get_issue_id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
issue_number=${{ github.event.issue.number }}
issue_id=$(gh api graphql -F owner='${{ github.repository_owner }}' -F name='${{ github.event.repository.name }}' -F issueNumber=$issue_number -f query='
query ($owner: String!, $name: String!, $issueNumber: Int!) {
repository(owner: $owner, name: $name) {
issue(number: $issueNumber) {
id
}
}
}' -q .data.repository.issue.id)
echo "ISSUE_ID=$issue_id" >> $GITHUB_ENV
- name: Verify DEV_PROJECT_ID
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEV_PROJECT_ID: ${{ secrets.DEV_PROJECT_ID }}
ORG: ${{ github.repository_owner }}
run: |
result=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/$ORG/projects/$DEV_PROJECT_ID")
echo "Project response: $result"
if echo "$result" | jq -e . >/dev/null 2>&1; then
project_state=$(echo $result | jq -r '.state')
if [ "$project_state" != "open" ]; then
echo "Project is not open or not found"
exit 1
fi
else
echo "Failed to parse project response as JSON."
exit 1
fi
- name: Get columns in project
id: get_columns
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEV_PROJECT_ID: ${{ secrets.DEV_PROJECT_ID }}
ORG: ${{ github.repository_owner }}
run: |
columns=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.inertia-preview+json" \
"https://api.github.com/projects/$DEV_PROJECT_ID/columns")
echo "Columns response: $columns"
if echo "$columns" | jq -e . >/dev/null 2>&1; then
column_id=$(echo $columns | jq -r '.[] | select(.name == "No Status") | .id')
if [ -n "$column_id" ]; then
echo "COLUMN_ID=$column_id" >> $GITHUB_ENV
else
echo "No column found with the name 'No Status'."
exit 1
fi
else
echo "Failed to parse columns response as JSON."
exit 1
fi
- name: Add issue to project
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PROJECT_CARD_URL="https://api.github.com/projects/columns/$COLUMN_ID/cards"
# Create a project card for the issue in the specified column
curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
$PROJECT_CARD_URL \
-d '{"content_id": "'"${ISSUE_ID}"'", "content_type": "Issue"}'