Skip to content

Example Bug

Example Bug #38

name: Add Issue to Project
on:
issues:
types: [opened]
jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- name: Add to Project
id: add-to-project
uses: actions/[email protected]
with:
project-url: https://github.com/orgs/Dictionarry-Hub/projects/1
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
- name: Get project item ID
id: get-project-item-id
env:
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
PROJECT_ID: "PVT_kwDOCjbMFM4AjuUh"
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
echo "Fetching project item ID for issue number: $ISSUE_NUMBER"
item_id=$(gh api graphql -f query='
query($project:ID!) {
node(id: $project) {
... on ProjectV2 {
items(first: 100) {
nodes {
id
content {
... on Issue {
number
}
}
}
}
}
}
}' -f project=$PROJECT_ID --jq ".data.node.items.nodes[] | select(.content.number == $ISSUE_NUMBER) | .id" -F number=$ISSUE_NUMBER)
if [ -z "$item_id" ]; then
echo "Error: Project item ID not found for issue number $ISSUE_NUMBER"
exit 1
else
echo "Project item ID found: $item_id"
echo "PROJECT_ITEM_ID=$item_id" >> $GITHUB_OUTPUT
fi
- name: Set component, type, and status
env:
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
PROJECT_ITEM_ID: ${{ steps.get-project-item-id.outputs.PROJECT_ITEM_ID }}
run: |
echo "Setting fields for Project Item ID: ${PROJECT_ITEM_ID}"
# Set component to "Profilarr"
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="${PROJECT_ITEM_ID}" -f fieldId="PVTSSF_lADOCjbMFM4AjuUhzgcCr_E" -f value="48fc49c7")
echo "Set component result: $result"
# Set status to "Backlog"
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="${PROJECT_ITEM_ID}" -f fieldId="PVTSSF_lADOCjbMFM4AjuUhzgcCn8s" -f value="f75ad846")
echo "Set status result: $result"
# Get the label of the issue
LABEL=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }} --jq '.labels[0].name')
echo "Issue label: $LABEL"
# Convert label to lowercase for comparison
LABEL_LOWER=$(echo "$LABEL" | tr '[:upper:]' '[:lower:]')
# Set issue type based on label
ISSUE_TYPE_ID=$(case $LABEL_LOWER in
"bug") echo "b760225f" ;;
"feature request") echo "1341bde2" ;;
"improvement") echo "cb34d96f" ;;
"documentation") echo "269885d0" ;;
"refactor") echo "4996f537" ;;
"infrastructure") echo "45a91bfe" ;;
*) echo "" ;;
esac)
if [ -z "$ISSUE_TYPE_ID" ]; then
echo "No matching issue type for label: $LABEL"
else
echo "Setting issue type to ID: $ISSUE_TYPE_ID"
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="${PROJECT_ITEM_ID}" -f fieldId="PVTSSF_lADOCjbMFM4AjuUhzgcCswQ" -f value="$ISSUE_TYPE_ID")
echo "Set issue type result: $result"
fi