Skip to content

Route open role issues #108

Route open role issues

Route open role issues #108

name: Route open role issues
on:
issues:
types:
- labeled
env:
GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
OPEN_ROLES_PROJECT_ID: PVT_kwDOAA7NZM4AmdbW
OPEN_ROLES_STATUS_FIELD_ID: PVTSSF_lADOAA7NZM4AmdbWzgeWrcw
OPEN_OPTION_ID: f75ad846
ORG_KANBAN_PROJECT_ID: PVT_kwDOAA7NZM4AqQF8
jobs:
route-open-role:
if: github.event.label.name == 'open role'
runs-on: ubuntu-latest
steps:
- name: Add to Open Roles as "Open" and remove from Org Kanban
run: |
ISSUE_NODE_ID="${{ github.event.issue.node_id }}"
# Add to the Open Roles board. addProjectV2ItemById is idempotent —
# it returns the existing item ID if the issue is already on the board.
# We set status in code because the native "Item added to project"
# workflow is intentionally turned off (see board-sync-redesign).
ITEM_ID=$(gh api graphql -f query='
mutation($project: ID!, $content: ID!) {
addProjectV2ItemById(input: { projectId: $project, contentId: $content }) {
item { id }
}
}' -f project="$OPEN_ROLES_PROJECT_ID" -f content="$ISSUE_NODE_ID" \
--jq '.data.addProjectV2ItemById.item.id')
if [ -n "$ITEM_ID" ]; then
echo "On Open Roles as item $ITEM_ID — setting status to 'Open'..."
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="$OPEN_ROLES_PROJECT_ID" -f item="$ITEM_ID" \
-f field="$OPEN_ROLES_STATUS_FIELD_ID" -f option="$OPEN_OPTION_ID"
else
echo "Could not add to Open Roles — skipping status set."
fi
# Remove from Org Kanban if present. This only matters for the
# late-label case (blank issue landed on the Kanban, then got the
# open-role label). Paginate so we find it regardless of board size.
KANBAN_ITEM_ID=""
CURSOR=""
while true; do
if [ -n "$CURSOR" ]; then
RESULT=$(gh api graphql -f query='
query($project: ID!, $cursor: String!) {
node(id: $project) {
... on ProjectV2 {
items(first: 100, after: $cursor) {
nodes { id content { ... on Issue { id } } }
pageInfo { hasNextPage endCursor }
}
}
}
}' -f project="$ORG_KANBAN_PROJECT_ID" -f cursor="$CURSOR")
else
RESULT=$(gh api graphql -f query='
query($project: ID!) {
node(id: $project) {
... on ProjectV2 {
items(first: 100) {
nodes { id content { ... on Issue { id } } }
pageInfo { hasNextPage endCursor }
}
}
}
}' -f project="$ORG_KANBAN_PROJECT_ID")
fi
KANBAN_ITEM_ID=$(echo "$RESULT" | jq -r ".data.node.items.nodes[] | select(.content.id == \"$ISSUE_NODE_ID\") | .id")
[ -n "$KANBAN_ITEM_ID" ] && break
HAS_NEXT=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.hasNextPage')
CURSOR=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.endCursor')
[ "$HAS_NEXT" != "true" ] && break
done
if [ -n "$KANBAN_ITEM_ID" ]; then
echo "Removing from Org Kanban (item $KANBAN_ITEM_ID)..."
gh api graphql -f query='
mutation($project: ID!, $item: ID!) {
deleteProjectV2Item(input: { projectId: $project, itemId: $item }) {
deletedItemId
}
}' -f project="$ORG_KANBAN_PROJECT_ID" -f item="$KANBAN_ITEM_ID"
echo "Removed."
else
echo "Not on Org Kanban — nothing to remove."
fi