-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (167 loc) · 7.64 KB
/
fvutils-weekly-report.yaml
File metadata and controls
189 lines (167 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: FVUtils Weekly Report
on:
schedule:
- cron: '0 9 * * 1'
workflow_dispatch:
permissions:
contents: read
pull-requests: read
discussions: write
models: read
env:
MODEL: gpt-4o
MODELS_ENDPOINT: https://models.inference.ai.azure.com/chat/completions
jobs:
generate-news:
runs-on: ubuntu-latest
steps:
# ── Step 1: Identify active repos ────────────────────────────────────────
# Find fvutils repos that have had pushes in the past 7 days.
- name: Identify active repos
env:
GH_TOKEN: ${{ github.token }}
run: |
END_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
START_DATE=$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ)
echo "START_DATE=$START_DATE" >> $GITHUB_ENV
echo "END_DATE=$END_DATE" >> $GITHUB_ENV
echo "Scanning fvutils org for repos pushed since $START_DATE ..."
gh repo list fvutils --limit 100 --json name,pushedAt \
| jq -r --arg start "$START_DATE" \
'.[] | select(.pushedAt >= $start) | .name' \
> /tmp/active_repos.txt
echo "Active repos:"
cat /tmp/active_repos.txt
# ── Step 2: Collect details from active repos ────────────────────────────
# For each active repo, gather commits, merged PRs, and updated issues.
- name: Collect details from active repos
env:
GH_TOKEN: ${{ github.token }}
run: |
: > /tmp/activity.md # start fresh
while IFS= read -r repo; do
echo "## fvutils/$repo" >> /tmp/activity.md
echo "" >> /tmp/activity.md
# Commits
COMMITS=$(gh api \
"repos/fvutils/$repo/commits?since=${START_DATE}&until=${END_DATE}&per_page=50" \
--jq '.[] | "- \(.commit.message | split("\n")[0]) [\(.sha[0:7])]"' \
2>/dev/null || true)
if [ -n "$COMMITS" ]; then
echo "### Commits" >> /tmp/activity.md
echo "$COMMITS" >> /tmp/activity.md
echo "" >> /tmp/activity.md
fi
# Pull requests (merged or opened this week)
PRS=$(gh pr list --repo "fvutils/$repo" --state all \
--search "updated:>=$(echo $START_DATE | cut -c1-10)" \
--json number,title,state,author \
--jq '.[] | "- #\(.number) \(.title) [\(.state)] (@\(.author.login))"' \
2>/dev/null || true)
if [ -n "$PRS" ]; then
echo "### Pull Requests" >> /tmp/activity.md
echo "$PRS" >> /tmp/activity.md
echo "" >> /tmp/activity.md
fi
# Issues opened or updated this week
ISSUES=$(gh issue list --repo "fvutils/$repo" --state all \
--search "updated:>=$(echo $START_DATE | cut -c1-10)" \
--json number,title,state,author \
--jq '.[] | "- #\(.number) \(.title) [\(.state)] (@\(.author.login))"' \
2>/dev/null || true)
if [ -n "$ISSUES" ]; then
echo "### Issues" >> /tmp/activity.md
echo "$ISSUES" >> /tmp/activity.md
echo "" >> /tmp/activity.md
fi
done < /tmp/active_repos.txt
echo "--- collected activity ---"
cat /tmp/activity.md
# ── Step 3: Generate news item via gh api /models/$MODEL ─────────────────
# Pass the raw activity to gpt-5-mini-high and ask for a polished news item.
- name: Generate news item
env:
GH_TOKEN: ${{ github.token }}
run: |
WEEK_END=$(date -u '+%d %b %Y')
# Build the JSON payload with Python to avoid shell quoting issues.
# All heredoc lines are indented 10 spaces so YAML includes them in the
# block scalar; YAML strips the 10-space prefix before passing to bash.
export WEEK_END MODEL
python3 - << 'PYEOF'
import json, os
activity = open('/tmp/activity.md').read()
week_end = os.environ['WEEK_END']
model = os.environ['MODEL']
prompt = (
"You are a technical writer for an open-source verification tools project.\n\n"
f"Below is raw weekly activity (commits, PRs, issues) from the fvutils GitHub org "
f"for the week ending {week_end}.\n\n"
+ activity
+ "\n\nWrite a concise weekly news item suitable for the project website. "
"Include: a short overall summary paragraph, then a per-repo highlights section "
"using bullet points, and a brief \"What's next\" closing line. "
"Be factual, avoid hype, use past tense for completed work."
)
payload = {"model": model, "messages": [{"role": "user", "content": prompt}],
"max_tokens": 600, "temperature": 0.4}
with open('/tmp/request.json', 'w') as f:
json.dump(payload, f)
print("Request JSON written.")
PYEOF
curl -s \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Content-Type: application/json" \
--data @/tmp/request.json \
"$MODELS_ENDPOINT" \
> /tmp/api_response.json 2>/tmp/api_error.txt
echo "--- API response ---"
cat /tmp/api_response.json
python3 << 'PYEOF'
import sys, json
data = json.load(open('/tmp/api_response.json'))
if 'choices' in data:
with open('/tmp/news_item.md', 'w') as f:
f.write(data['choices'][0]['message']['content'])
else:
print('ERROR:', data, file=sys.stderr)
sys.exit(1)
PYEOF
if [ $? -ne 0 ]; then
echo "WARNING: GitHub Models API call failed:"
cat /tmp/api_error.txt
echo "Generating fallback news item..."
printf "## fvutils Weekly Highlights — week ending %s\n\n" "$WEEK_END" > /tmp/news_item.md
cat /tmp/activity.md >> /tmp/news_item.md
echo "" >> /tmp/news_item.md
echo "*Auto-generated from commit/PR/issue metadata — AI summarization unavailable.*" >> /tmp/news_item.md
fi
echo "=== Generated news item ==="
cat /tmp/news_item.md
# ── Publish: post to fvutils/.github Discussions ─────────────────────────
- name: Post to Discussions
env:
GH_TOKEN: ${{ github.token }}
run: |
WEEK_NUM=$(date -u +%V)
YEAR=$(date -u +%Y)
TITLE="Weekly Highlights — Week $WEEK_NUM, $YEAR"
BODY=$(cat /tmp/news_item.md)
BODY="$BODY"$'\n\n---\n*Generated automatically by [fvutils-weekly-report](../actions/workflows/fvutils-weekly-report.yaml) using '"$MODEL"'.*'
gh api graphql -f query='
mutation($repositoryId: ID!, $categoryId: ID!, $title: String!, $body: String!) {
createDiscussion(input: {
repositoryId: $repositoryId
categoryId: $categoryId
title: $title
body: $body
}) {
discussion { id url title }
}
}
' \
-f repositoryId="R_kgDOHMTiUw" \
-f categoryId="DIC_kwDOHMTiU84C2BrA" \
-f title="$TITLE" \
-f body="$BODY" \
| jq -r '.data.createDiscussion.discussion | "Created: \(.title)\nURL: \(.url)"'