mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-28 13:30:56 +01:00
123 lines
4.4 KiB
YAML
123 lines
4.4 KiB
YAML
name: Update Issues to Complete on Merge to Main
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
types:
|
|
- closed
|
|
|
|
jobs:
|
|
update-issues-status:
|
|
if: ${{ github.event.pull_request.merged && github.event.pull_request.head.ref == 'x' }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Get all issues with status "Testing"
|
|
id: get-testing-issues
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
|
PROJECT_ID: "PVT_kwDOCjbMFM4AjuUh"
|
|
run: |
|
|
echo "Fetching all issues with status 'Testing'"
|
|
QUERY='
|
|
query($project:ID!) {
|
|
node(id: $project) {
|
|
... on ProjectV2 {
|
|
items(first: 100) {
|
|
nodes {
|
|
id
|
|
content {
|
|
... on Issue {
|
|
number
|
|
}
|
|
}
|
|
fieldValues(first: 10) {
|
|
nodes {
|
|
... on ProjectV2ItemFieldSingleSelectValue {
|
|
name
|
|
field {
|
|
... on ProjectV2SingleSelectField {
|
|
name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}'
|
|
items=$(gh api graphql -f query="$QUERY" -f project=$PROJECT_ID --jq '.data.node.items.nodes[] | select(.fieldValues.nodes[] | select(.name == "Testing")) | .id')
|
|
items=$(echo $items | tr '\n' ' ')
|
|
echo "Items with 'Testing' status: $items"
|
|
echo "TESTING_ITEMS=$items" >> $GITHUB_ENV
|
|
|
|
- name: Get single select field ID and option ID for "Complete"
|
|
id: get-complete-option-id
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
|
PROJECT_ID: "PVT_kwDOCjbMFM4AjuUh"
|
|
run: |
|
|
echo "Fetching field ID and options for status"
|
|
QUERY='
|
|
query($project:ID!) {
|
|
node(id: $project) {
|
|
... on ProjectV2 {
|
|
fields(first: 100) {
|
|
nodes {
|
|
... on ProjectV2SingleSelectField {
|
|
id
|
|
name
|
|
options {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}'
|
|
field_data=$(gh api graphql -f query="$QUERY" -f project=$PROJECT_ID --jq '.data.node.fields.nodes[] | select(.name == "Status")')
|
|
field_id=$(echo $field_data | jq -r '.id')
|
|
complete_option_id=$(echo $field_data | jq -r '.options[] | select(.name == "Complete") | .id')
|
|
if [ -z "$field_id" ] || [ -z "$complete_option_id" ]; then
|
|
echo "Error: Field ID or Complete option ID not found"
|
|
exit 1
|
|
else
|
|
echo "Field ID: $field_id"
|
|
echo "Complete option ID: $complete_option_id"
|
|
echo "FIELD_ID=$field_id" >> $GITHUB_ENV
|
|
echo "COMPLETE_OPTION_ID=$complete_option_id" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Set status to Complete for all items
|
|
if: steps.get-testing-issues.outputs.TESTING_ITEMS != ''
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
|
FIELD_ID: ${{ env.FIELD_ID }}
|
|
COMPLETE_OPTION_ID: ${{ env.COMPLETE_OPTION_ID }}
|
|
TESTING_ITEMS: ${{ steps.get-testing-issues.outputs.TESTING_ITEMS }}
|
|
run: |
|
|
IFS=' ' read -ra items <<< "$TESTING_ITEMS"
|
|
for item in "${items[@]}"; do
|
|
echo "Setting status to Complete for Project Item ID: $item"
|
|
result=$(gh api graphql -f query='
|
|
mutation($project:ID!, $item:ID!, $fieldId:ID!, $value:String!) {
|
|
updateProjectV2ItemFieldValue(input: {
|
|
projectId: $project
|
|
itemId: $item
|
|
fieldId: $fieldId
|
|
value: {
|
|
singleSelectOptionId: $value
|
|
}
|
|
}) {
|
|
projectV2Item {
|
|
id
|
|
}
|
|
}
|
|
}' -f project="PVT_kwDOCjbMFM4AjuUh" -f item="$item" -f fieldId="${FIELD_ID}" -f value="${COMPLETE_OPTION_ID}")
|
|
echo "Set status result: $result"
|
|
done
|