|
| 1 | +name: "triage-issue" |
| 2 | +description: "Composite action to create monthly triage issue and optionally close previous month" |
| 3 | +inputs: |
| 4 | + close-previous: |
| 5 | + description: "Whether to close last month’s triage issue (true/false)" |
| 6 | + required: false |
| 7 | + default: "true" |
| 8 | + label: |
| 9 | + description: "Label to apply to triage issue" |
| 10 | + required: false |
| 11 | + default: "triage" |
| 12 | + body-template: |
| 13 | + description: "Custom body template (supports {{MONTH}} placeholder)" |
| 14 | + required: false |
| 15 | + default: | |
| 16 | + ### Monthly GitHub Triage – {{MONTH}} |
| 17 | +
|
| 18 | + This automatically generated issue tracks triage activities for {{MONTH}}. |
| 19 | +
|
| 20 | + **Purpose** |
| 21 | + - Collect new issues for classification. |
| 22 | + - Track placeholders. |
| 23 | + - Consolidate duplicates. |
| 24 | +
|
| 25 | + **Automation** |
| 26 | + - Weekly summary comments (companion workflow). |
| 27 | + - Future enhancements: stale detection, cross-links. |
| 28 | +
|
| 29 | + :octocat: :copilot: Created automatically. |
| 30 | +runs: |
| 31 | + using: "composite" |
| 32 | + steps: |
| 33 | + - name: Compute dates |
| 34 | + id: dates |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + CURR=$(date -u +'%Y-%m') |
| 38 | + PREV=$(date -u -d "$(date -u +%Y-%m-01) -1 month" +'%Y-%m') |
| 39 | + echo "curr=$CURR" >> $GITHUB_OUTPUT |
| 40 | + echo "prev=$PREV" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Ensure triage issue |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const closePrev = (process.env.INPUT_CLOSE_PREVIOUS || 'true').toLowerCase() === 'true'; |
| 47 | + const label = process.env.INPUT_LABEL || 'triage'; |
| 48 | + const bodyTemplate = process.env.INPUT_BODY_TEMPLATE; |
| 49 | + const curr = '${{ steps.dates.outputs.curr }}'; |
| 50 | + const prev = '${{ steps.dates.outputs.prev }}'; |
| 51 | + const currTitle = `GitHub Triage: ${curr}`; |
| 52 | + const prevTitle = `GitHub Triage: ${prev}`; |
| 53 | +
|
| 54 | + async function findIssue(title) { |
| 55 | + const perPage = 100; |
| 56 | + for (let page = 1; page < 50; page++) { |
| 57 | + const { data } = await github.rest.issues.listForRepo({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + state: 'all', |
| 61 | + per_page: perPage, |
| 62 | + page |
| 63 | + }); |
| 64 | + if (!data.length) break; |
| 65 | + const hit = data.find(i => i.title === title); |
| 66 | + if (hit) return hit; |
| 67 | + if (data.length < perPage) break; |
| 68 | + } |
| 69 | + return null; |
| 70 | + } |
| 71 | +
|
| 72 | + if (closePrev) { |
| 73 | + const prevIssue = await findIssue(prevTitle); |
| 74 | + if (prevIssue && prevIssue.state === 'open') { |
| 75 | + await github.rest.issues.update({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + issue_number: prevIssue.number, |
| 79 | + state: 'closed' |
| 80 | + }); |
| 81 | + core.info(`Closed previous triage issue #${prevIssue.number} (${prevTitle})`); |
| 82 | + } else { |
| 83 | + core.info(`Previous triage issue not open or not found (${prevTitle}).`); |
| 84 | + } |
| 85 | + } |
| 86 | +
|
| 87 | + const currIssue = await findIssue(currTitle); |
| 88 | + if (currIssue) { |
| 89 | + core.info(`Current triage issue already exists: #${currIssue.number}`); |
| 90 | + return; |
| 91 | + } |
| 92 | +
|
| 93 | + const body = bodyTemplate.replace(/{{MONTH}}/g, curr); |
| 94 | + const created = await github.rest.issues.create({ |
| 95 | + owner: context.repo.owner, |
| 96 | + repo: context.repo.repo, |
| 97 | + title: currTitle, |
| 98 | + body, |
| 99 | + labels: [label] |
| 100 | + }); |
| 101 | + core.notice(`Created triage issue #${created.data.number} (${currTitle}).`); |
0 commit comments