Skip to content

Commit a0d014e

Browse files
committed
ci: automate daily PR triage, gated dependency merging and AI improvement review
1 parent 3d0d88e commit a0d014e

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Daily AI maintenance
2+
on:
3+
schedule:
4+
- cron: '11 10 * * *'
5+
workflow_dispatch:
6+
permissions:
7+
contents: read
8+
issues: write
9+
pull-requests: write
10+
concurrency:
11+
group: daily-ai-maintenance
12+
cancel-in-progress: false
13+
jobs:
14+
triage:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 20
17+
env:
18+
GH_TOKEN: ${{ github.token }}
19+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
persist-credentials: false
24+
- name: Audit PRs and safely merge eligible dependency fixes
25+
shell: bash
26+
run: |
27+
set -euo pipefail
28+
echo "## Daily maintenance — $GITHUB_REPOSITORY" >> "$GITHUB_STEP_SUMMARY"
29+
gh pr list --state open --limit 100 --json number,title,author,isDraft,mergeable,statusCheckRollup,labels > /tmp/prs.json
30+
jq -c '.[]' /tmp/prs.json | while IFS= read -r pr; do
31+
number=$(jq -r '.number' <<< "$pr")
32+
title=$(jq -r '.title' <<< "$pr")
33+
author=$(jq -r '.author.login // ""' <<< "$pr")
34+
failed=$(jq '[.statusCheckRollup[]? | select(.conclusion == "FAILURE" or .conclusion == "TIMED_OUT")] | length' <<< "$pr")
35+
if [ "$failed" -gt 0 ]; then
36+
echo "- PR #$number: failing checks" >> "$GITHUB_STEP_SUMMARY"
37+
existing=$(gh issue list --state open --search "AI repair PR #$number in:title" --json number | jq 'length')
38+
if [ "$existing" -eq 0 ]; then
39+
gh issue create --title "AI repair PR #$number" --body "CI failure on PR #$number ($title). Review workflow logs, fix the failing check, and rerun tests. Do not merge without successful checks."
40+
fi
41+
continue
42+
fi
43+
# Never merge arbitrary contributions, major upgrades, or unchecked PRs.
44+
if [[ "$author" != "renovate[bot]" && "$author" != "dependabot[bot]" ]]; then continue; fi
45+
if jq -e '.isDraft or .mergeable != "MERGEABLE" or (.statusCheckRollup | length == 0) or any(.statusCheckRollup[]; .status != "COMPLETED" or .conclusion != "SUCCESS")' <<< "$pr" >/dev/null; then continue; fi
46+
if grep -Eiq 'major|breaking|monorepo to v[0-9]+($|[^0-9])' <<< "$title"; then
47+
echo "- PR #$number: manual review required for potentially breaking upgrade" >> "$GITHUB_STEP_SUMMARY"
48+
continue
49+
fi
50+
# Respect branch protection and existing review requirements; do not force.
51+
if gh pr merge "$number" --squash --auto 2>/tmp/merge-error; then
52+
echo "- PR #$number: auto-merge requested (GitHub gates still apply)" >> "$GITHUB_STEP_SUMMARY"
53+
else
54+
echo "- PR #$number: merge deferred — $(head -c 150 /tmp/merge-error)" >> "$GITHUB_STEP_SUMMARY"
55+
fi
56+
done
57+
- name: AI repository improvement review
58+
if: env.OPENAI_API_KEY != ''
59+
shell: bash
60+
run: |
61+
python - <<'PY'
62+
import json, os, pathlib, subprocess, urllib.request
63+
files = []
64+
for name in ('package.json', 'README.md', 'tsconfig.json', 'renovate.json'):
65+
p = pathlib.Path(name)
66+
if p.is_file():
67+
files.append((name, p.read_text(errors='replace')[:4500]))
68+
if not files:
69+
print('No root package metadata to review')
70+
raise SystemExit(0)
71+
prompt = ('Review repository metadata and identify ONE concrete, non-duplicative '
72+
'quality, security-hardening, accessibility, or testing improvement. '
73+
'Do not claim a vulnerability without evidence. Output a concise issue '
74+
'with a title line and implementation/acceptance criteria. '
75+
'Never include secrets or request workflow permission changes.\n\n' +
76+
'\n\n'.join(n + ':\n' + v for n, v in files))
77+
data = json.dumps({'model':'gpt-4.1-mini','input':prompt,'max_output_tokens':350}).encode()
78+
request = urllib.request.Request('https://api.openai.com/v1/responses',data=data,
79+
headers={'Authorization':'Bearer '+os.environ['OPENAI_API_KEY'],
80+
'Content-Type':'application/json'})
81+
try:
82+
with urllib.request.urlopen(request, timeout=40) as response:
83+
result = json.load(response)
84+
suggestion = '\n'.join(c.get('text','') for item in result.get('output',[])
85+
for c in item.get('content',[]) if c.get('type')=='output_text').strip()
86+
if not suggestion: raise ValueError('Empty model response')
87+
existing = subprocess.check_output(['gh','issue','list','--state','open',
88+
'--search','Daily AI improvement in:title','--json','number'],text=True)
89+
if json.loads(existing): raise SystemExit(0)
90+
subprocess.run(['gh','issue','create','--title','Daily AI improvement review',
91+
'--body',suggestion[:3500]+'\n\nAI suggestion; validate before implementing.'],check=True)
92+
except Exception as exc:
93+
print('Improvement review skipped:',str(exc)[:180])
94+
PY

0 commit comments

Comments
 (0)