|
| 1 | +name: Art board project reminder (reusable) |
| 2 | + |
| 3 | +# Reusable workflow: paginates a Projects V2 board, finds issues stuck in a |
| 4 | +# given column for too long, and posts a one-time reminder comment. |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + column: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + stale_days: |
| 16 | + required: true |
| 17 | + type: number |
| 18 | + match_missing_status: |
| 19 | + description: Also match items with no Status field set (for "No Status" columns) |
| 20 | + required: false |
| 21 | + type: boolean |
| 22 | + default: false |
| 23 | + reminder_tag: |
| 24 | + description: HTML comment used to deduplicate reminders |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + message: |
| 28 | + description: 'Comment body — use {days} as a placeholder' |
| 29 | + required: true |
| 30 | + type: string |
| 31 | + secrets: |
| 32 | + GH_APP_POSTHOG_ART_BOARD_BOT_APP_ID: |
| 33 | + required: true |
| 34 | + GH_APP_POSTHOG_ART_BOARD_BOT_PRIVATE_KEY: |
| 35 | + required: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + remind: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - name: Get app token |
| 42 | + id: app-token |
| 43 | + uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 |
| 44 | + with: |
| 45 | + app-id: ${{ secrets.GH_APP_POSTHOG_ART_BOARD_BOT_APP_ID }} |
| 46 | + private-key: ${{ secrets.GH_APP_POSTHOG_ART_BOARD_BOT_PRIVATE_KEY }} |
| 47 | + - name: Find stale issues and post reminders |
| 48 | + uses: actions/github-script@v7 |
| 49 | + env: |
| 50 | + INPUT_COLUMN: ${{ inputs.column }} |
| 51 | + INPUT_STALE_DAYS: ${{ inputs.stale_days }} |
| 52 | + INPUT_MATCH_MISSING: ${{ inputs.match_missing_status }} |
| 53 | + INPUT_TAG: ${{ inputs.reminder_tag }} |
| 54 | + INPUT_MESSAGE: ${{ inputs.message }} |
| 55 | + with: |
| 56 | + github-token: ${{ steps.app-token.outputs.token }} |
| 57 | + script: | |
| 58 | + const column = process.env.INPUT_COLUMN; |
| 59 | + const staleDays = parseInt(process.env.INPUT_STALE_DAYS); |
| 60 | + const matchMissing = process.env.INPUT_MATCH_MISSING === 'true'; |
| 61 | + const reminderTag = process.env.INPUT_TAG; |
| 62 | + const msgTemplate = process.env.INPUT_MESSAGE; |
| 63 | + const snoozed = 'All projects (snoozed projects)'; |
| 64 | + const staleMs = staleDays * 86_400_000; |
| 65 | + const now = Date.now(); |
| 66 | +
|
| 67 | + // ── Paginate all project items ──────────────────────────────── |
| 68 | + const QUERY = ` |
| 69 | + query($org: String!, $num: Int!, $cursor: String) { |
| 70 | + organization(login: $org) { |
| 71 | + projectV2(number: $num) { |
| 72 | + items(first: 100, after: $cursor) { |
| 73 | + pageInfo { hasNextPage endCursor } |
| 74 | + nodes { |
| 75 | + updatedAt |
| 76 | + fieldValues(first: 20) { |
| 77 | + nodes { |
| 78 | + ... on ProjectV2ItemFieldSingleSelectValue { |
| 79 | + name |
| 80 | + field { ... on ProjectV2FieldCommon { name } } |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + content { |
| 85 | + ... on Issue { number state repository { nameWithOwner } } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + }`; |
| 92 | +
|
| 93 | + let items = [], cursor = null; |
| 94 | + do { |
| 95 | + const res = await github.graphql(QUERY, { org: 'PostHog', num: 65, cursor }); |
| 96 | + const page = res.organization.projectV2.items; |
| 97 | + items = items.concat(page.nodes); |
| 98 | + cursor = page.pageInfo.hasNextPage ? page.pageInfo.endCursor : null; |
| 99 | + } while (cursor); |
| 100 | +
|
| 101 | + // ── Filter stale items ──────────────────────────────────────── |
| 102 | + const stale = items.filter(item => { |
| 103 | + const issue = item.content; |
| 104 | + if (!issue?.number || issue.state === 'CLOSED') return false; |
| 105 | +
|
| 106 | + const status = item.fieldValues.nodes.find(f => f.field?.name === 'Status'); |
| 107 | + if (status?.name === snoozed) return false; |
| 108 | +
|
| 109 | + const matches = matchMissing |
| 110 | + ? (!status || status.name === column) |
| 111 | + : (status?.name === column); |
| 112 | + if (!matches) return false; |
| 113 | +
|
| 114 | + return (now - new Date(item.updatedAt).getTime()) >= staleMs; |
| 115 | + }); |
| 116 | +
|
| 117 | + console.log(`${stale.length} stale item(s) in "${column}".`); |
| 118 | +
|
| 119 | + // ── Post one-time reminders ─────────────────────────────────── |
| 120 | + for (const item of stale) { |
| 121 | + const issue = item.content; |
| 122 | + const [owner, repo] = issue.repository.nameWithOwner.split('/'); |
| 123 | +
|
| 124 | + const { data: comments } = await github.rest.issues.listComments({ |
| 125 | + owner, repo, issue_number: issue.number, per_page: 100, |
| 126 | + }); |
| 127 | + if (comments.some(c => c.body.includes(reminderTag))) continue; |
| 128 | +
|
| 129 | + const days = Math.floor((now - new Date(item.updatedAt).getTime()) / 86_400_000); |
| 130 | + await github.rest.issues.createComment({ |
| 131 | + owner, repo, issue_number: issue.number, |
| 132 | + body: `${reminderTag}\n${msgTemplate.replace('{days}', days)}`, |
| 133 | + }); |
| 134 | + console.log(`Reminded #${issue.number} (${days} days).`); |
| 135 | + } |
0 commit comments