Skip to content

Add new issue to Org Kanban #56

Add new issue to Org Kanban

Add new issue to Org Kanban #56

name: Add new issue to Org Kanban
on:
issues:
types:
- opened
# Deliberately NOT triggered on `labeled`. Re-running on every label
# change re-set the item's status to "To Do", which clobbered manual
# board moves (e.g. an item moved to Done would bounce back to To Do
# the next time any label was added, breaking the native Auto-close).
# The "blank issue later labeled `open role`" case is handled by
# open-role-add.yaml, which removes the item from this board itself.
env:
GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
ORG_KANBAN_PROJECT_ID: PVT_kwDOAA7NZM4AqQF8
STATUS_FIELD_ID: PVTSSF_lADOAA7NZM4AqQF8zghh1hc
TODO_OPTION_ID: f75ad846
jobs:
add-to-kanban:
# Skip pull requests, skip open role issues (they go to Open Roles board instead)
if: |
github.event.issue != null &&
!contains(github.event.issue.labels.*.name, 'open role')
runs-on: ubuntu-latest
steps:
- name: Add issue to Org Kanban under "To Do"
run: |
ISSUE_NODE_ID="${{ github.event.issue.node_id }}"
# Add the issue to the project (returns item ID)
ITEM_ID=$(gh api graphql -f query='
mutation($project: ID!, $content: ID!) {
addProjectV2ItemById(input: { projectId: $project, contentId: $content }) {
item { id }
}
}' \
-f project="$ORG_KANBAN_PROJECT_ID" \
-f content="$ISSUE_NODE_ID" \
--jq '.data.addProjectV2ItemById.item.id')
# addProjectV2ItemById is idempotent: it returns the existing item
# ID if the issue is already on the board, so a non-empty ID here is
# normal. An empty ID means the add genuinely failed.
if [ -z "$ITEM_ID" ]; then
echo "Could not add issue to board — skipping status set."
exit 0
fi
echo "Added item $ITEM_ID — setting status to 'To Do'..."
# Set status to "To Do"
gh api graphql -f query='
mutation($project: ID!, $item: ID!, $field: ID!, $option: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $project,
itemId: $item,
fieldId: $field,
value: { singleSelectOptionId: $option }
}) {
projectV2Item { id }
}
}' \
-f project="$ORG_KANBAN_PROJECT_ID" \
-f item="$ITEM_ID" \
-f field="$STATUS_FIELD_ID" \
-f option="$TODO_OPTION_ID"
echo "Done — issue is now on Org Kanban in 'To Do'."