Skip to content

[#199] Changed token #25

[#199] Changed token

[#199] Changed token #25

name: Update Issue Status
on:
pull_request:
types: [closed]
jobs:
update-status:
runs-on: ubuntu-latest
steps:
# Step 1: Check for issue number in PR title or description
- name: Check for issue number in PR title or description
id: check-pr-for-issue
run: |
pr_title="${{ github.event.pull_request.title }}"
pr_body="${{ github.event.pull_request.body }}"
issue_number=$(echo "$pr_title" "$pr_body" | grep -oE '#[0-9]+' | head -n 1 | sed 's/#//')
if [ -z "$issue_number" ]; then
echo "No issue number found in PR title or description."
exit 1
fi
echo "Issue number found: $issue_number"
echo "issue_number=$issue_number" >> $GITHUB_ENV
# Step 2: Get organization name, project ID, status field ID, and done option ID
- name: Retrieve project details
id: get-project-details
run: |
org_name="${{ github.repository_owner }}"
project_number="1314"
echo "Fetching details for organization: $org_name, project number: $project_number"
# GraphQL query to get project fields (including "Status" field and "Done" option)
query="{\"query\": \"{ organization(login: \\\"$org_name\\\") { projectV2(number: $project_number) { id fields(first: 20) { nodes { ... on ProjectV2SingleSelectField { id name options { id name } } } } } } }\"}"
echo "Query being sent to GraphQL API: $query"
response=$(curl -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-X POST \
-H "Content-Type: application/json" \
-d "$query" \
https://api.github.com/graphql)
echo "GraphQL Response: $response"
# Extracting the status field ID and done option ID from the response
status_field_id=$(echo $response | jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Status") | .id')
done_option_id=$(echo $response | jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Status") | .options[] | select(.name == "Done") | .id')
echo "Status Field ID: $status_field_id"
echo "Done Option ID: $done_option_id"
# Set environment variables for later steps
echo "status_field_id=$status_field_id" >> $GITHUB_ENV
echo "done_option_id=$done_option_id" >> $GITHUB_ENV
# Step 3: Get Issue ID (itemId) from project
- name: Get Issue ID from project
id: get-issue-id
run: |
issue_number=${{ env.issue_number }}
query="{
organization(login: \"${{ github.repository_owner }}\") {
projectV2(number: $project_number) {
items(first: 100, orderBy: {field: POSITION, direction: DESC}) {
nodes {
id
content {
... on Issue {
number
id
}
}
}
}
}
}
}"
response=$(curl -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-X POST \
-H "Content-Type: application/json" \
-d "$query" \
https://api.github.com/graphql)
issue_id=$(echo $response | jq -r ".data.organization.projectV2.items.nodes[] | select(.content.number == $issue_number) | .id")
if [ -z "$issue_id" ]; then
echo "Issue ID not found for issue #$issue_number."
exit 1
fi
echo "Issue ID: $issue_id"
echo "issue_id=$issue_id" >> $GITHUB_ENV
# Step 4: Update 'Status' field of the issue to 'Done'
- name: Update Issue Status to 'Done'
run: |
issue_id=${{ env.issue_id }}
project_id="1314" # Dynamic project ID, if necessary
status_field_id="${{ env.status_field_id }}" # Retrieved dynamically
done_option_id="${{ env.done_option_id }}" # Retrieved dynamically
echo "Updating issue #$issue_number status to 'Done'"
# GraphQL Mutation to update status
query="mutation {
updateProjectV2ItemFieldValue(input: {
projectId: \"$project_id\",
itemId: \"$issue_id\",
fieldId: \"$status_field_id\",
value: \"$done_option_id\"
}) {
projectV2Item {
id
content {
... on Issue {
id
number
title
}
}
}
}
}"
response=$(curl -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-X POST \
-H "Content-Type: application/json" \
-d "$query" \
https://api.github.com/graphql)
echo "Response: $response"