|
| 1 | +name: Reopen issues moved out of a terminal column (reconciliation) |
| 2 | + |
| 3 | +# Board -> issue "reopen" is the one behavior GitHub gives no immediate path |
| 4 | +# for: projects_v2_item can't trigger a repo workflow, and there is no native |
| 5 | +# "auto-reopen" (native only ships Auto-close). So this reconciles on a timer. |
| 6 | +# See docs/decisions/0004 and docs/active-spikes/board-sync-redesign.md. |
| 7 | +on: |
| 8 | + # IMPORTANT: the schedule is intentionally left commented out until the |
| 9 | + # one-time baseline-terminal-cleanup has been run. Before that, this would |
| 10 | + # mass-reopen legacy issues closed before the automation existed. Run this |
| 11 | + # via "Run workflow" (dry_run) first, confirm it wouldn't touch legacy |
| 12 | + # issues, then uncomment the cron. See board-sync-redesign.todo.md. |
| 13 | + # schedule: |
| 14 | + # - cron: '*/5 * * * *' |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + dry_run: |
| 18 | + description: 'Dry run (log without reopening)' |
| 19 | + required: false |
| 20 | + default: 'true' |
| 21 | + type: boolean |
| 22 | + |
| 23 | +env: |
| 24 | + GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }} |
| 25 | + # Skip issues closed within this window — close-to-done / closed-to-filled |
| 26 | + # may still be moving a freshly-closed issue into its terminal column. |
| 27 | + FRESH_CLOSE_SECONDS: "600" |
| 28 | + |
| 29 | +jobs: |
| 30 | + reconcile: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Reopen closed issues whose card sits in a non-terminal column |
| 35 | + run: | |
| 36 | + DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}" |
| 37 | + NOW=$(date +%s) |
| 38 | + echo "Dry run: $DRY_RUN" |
| 39 | + echo "---" |
| 40 | +
|
| 41 | + reconcile_board() { |
| 42 | + PROJECT_ID="$1" |
| 43 | + TERMINAL_OPTION="$2" |
| 44 | + BOARD_NAME="$3" |
| 45 | + CURSOR="" |
| 46 | +
|
| 47 | + while true; do |
| 48 | + if [ -n "$CURSOR" ]; then |
| 49 | + RESULT=$(gh api graphql -f query=' |
| 50 | + query($project: ID!, $cursor: String!) { |
| 51 | + node(id: $project) { |
| 52 | + ... on ProjectV2 { |
| 53 | + items(first: 100, after: $cursor) { |
| 54 | + nodes { |
| 55 | + fieldValueByName(name: "Status") { |
| 56 | + ... on ProjectV2ItemFieldSingleSelectValue { optionId } |
| 57 | + } |
| 58 | + content { |
| 59 | + ... on Issue { |
| 60 | + number |
| 61 | + state |
| 62 | + closedAt |
| 63 | + repository { nameWithOwner } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + pageInfo { hasNextPage endCursor } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + }' -f project="$PROJECT_ID" -f cursor="$CURSOR") |
| 72 | + else |
| 73 | + RESULT=$(gh api graphql -f query=' |
| 74 | + query($project: ID!) { |
| 75 | + node(id: $project) { |
| 76 | + ... on ProjectV2 { |
| 77 | + items(first: 100) { |
| 78 | + nodes { |
| 79 | + fieldValueByName(name: "Status") { |
| 80 | + ... on ProjectV2ItemFieldSingleSelectValue { optionId } |
| 81 | + } |
| 82 | + content { |
| 83 | + ... on Issue { |
| 84 | + number |
| 85 | + state |
| 86 | + closedAt |
| 87 | + repository { nameWithOwner } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + pageInfo { hasNextPage endCursor } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + }' -f project="$PROJECT_ID") |
| 96 | + fi |
| 97 | +
|
| 98 | + HAS_NEXT=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.hasNextPage') |
| 99 | + CURSOR=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.endCursor') |
| 100 | +
|
| 101 | + while IFS= read -r item; do |
| 102 | + OPTION_ID=$(echo "$item" | jq -r '.fieldValueByName.optionId // ""') |
| 103 | + NUMBER=$(echo "$item" | jq -r '.content.number // ""') |
| 104 | + STATE=$(echo "$item" | jq -r '.content.state // ""') |
| 105 | + CLOSED_AT=$(echo "$item" | jq -r '.content.closedAt // ""') |
| 106 | + REPO=$(echo "$item" | jq -r '.content.repository.nameWithOwner // ""') |
| 107 | +
|
| 108 | + # Only closed issues, with a status set, not already terminal |
| 109 | + [ "$STATE" != "CLOSED" ] && continue |
| 110 | + [ -z "$OPTION_ID" ] && continue |
| 111 | + [ "$OPTION_ID" == "$TERMINAL_OPTION" ] && continue |
| 112 | + [ -z "$NUMBER" ] || [ -z "$REPO" ] && continue |
| 113 | +
|
| 114 | + # Fresh-close guard |
| 115 | + if [ -n "$CLOSED_AT" ]; then |
| 116 | + CLOSED_TS=$(date -d "$CLOSED_AT" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$CLOSED_AT" +%s) |
| 117 | + if [ $(( NOW - CLOSED_TS )) -lt "$FRESH_CLOSE_SECONDS" ]; then |
| 118 | + echo "Skip #$NUMBER ($BOARD_NAME) — closed less than ${FRESH_CLOSE_SECONDS}s ago." |
| 119 | + continue |
| 120 | + fi |
| 121 | + fi |
| 122 | +
|
| 123 | + echo "Would reopen: #$NUMBER in $REPO ($BOARD_NAME — non-terminal column, issue closed)" |
| 124 | + if [ "$DRY_RUN" != "true" ]; then |
| 125 | + gh issue reopen "$NUMBER" --repo "$REPO" |
| 126 | + echo " → Reopened." |
| 127 | + fi |
| 128 | + done < <(echo "$RESULT" | jq -c '.data.node.items.nodes[]') |
| 129 | +
|
| 130 | + [ "$HAS_NEXT" != "true" ] && break |
| 131 | + done |
| 132 | + } |
| 133 | +
|
| 134 | + # Org Kanban: terminal column is Done. Open Roles: terminal is Filled. |
| 135 | + reconcile_board "PVT_kwDOAA7NZM4AqQF8" "98236657" "Org Kanban" |
| 136 | + reconcile_board "PVT_kwDOAA7NZM4AmdbW" "47fc9ee4" "Open Roles" |
| 137 | +
|
| 138 | + echo "---" |
| 139 | + if [ "$DRY_RUN" == "true" ]; then |
| 140 | + echo "Dry run complete. Run with dry_run=false to apply." |
| 141 | + fi |
0 commit comments