Skip to content

Commit ed4430a

Browse files
author
BESS Solutions
committed
feat(community): weekly Discord update automatico cada lunes 09:00 ART
1 parent 072b615 commit ed4430a

1 file changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Weekly Community Update
2+
3+
on:
4+
schedule:
5+
# Todos los lunes a las 09:00 ART (UTC-3 → 12:00 UTC)
6+
- cron: "0 12 * * 1"
7+
workflow_dispatch: # Permite trigger manual para probar
8+
9+
jobs:
10+
weekly-update:
11+
name: Publicar resumen semanal en Discord
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
issues: read
16+
pull-requests: read
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # Para contar commits de la semana
22+
23+
- name: Recopilar estadísticas de la semana
24+
id: stats
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
REPO: ${{ github.repository }}
28+
run: |
29+
SINCE=$(date -d "7 days ago" --utc +"%Y-%m-%dT%H:%M:%SZ")
30+
TODAY=$(date --utc +"%d %b %Y")
31+
32+
# Commits esta semana (en rama main)
33+
COMMITS=$(git log main --since="7 days ago" --oneline | wc -l | tr -d ' ')
34+
35+
# PRs mergeados esta semana
36+
PRS=$(gh pr list --state merged --base main \
37+
--search "merged:>=$(date -d '7 days ago' +%Y-%m-%d)" \
38+
--json number --jq 'length' 2>/dev/null || echo "0")
39+
40+
# Issues cerradas esta semana
41+
ISSUES_CLOSED=$(gh issue list --state closed \
42+
--search "closed:>=$(date -d '7 days ago' +%Y-%m-%d)" \
43+
--json number --jq 'length' 2>/dev/null || echo "0")
44+
45+
# Issues abiertas esta semana
46+
ISSUES_NEW=$(gh issue list --state open \
47+
--search "created:>=$(date -d '7 days ago' +%Y-%m-%d)" \
48+
--json number --jq 'length' 2>/dev/null || echo "0")
49+
50+
# Stars totales del repo
51+
STARS=$(gh api repos/$REPO --jq '.stargazers_count' 2>/dev/null || echo "?")
52+
53+
# Total de commits
54+
TOTAL_COMMITS=$(git rev-list --count HEAD)
55+
56+
echo "commits=$COMMITS" >> $GITHUB_OUTPUT
57+
echo "prs=$PRS" >> $GITHUB_OUTPUT
58+
echo "issues_closed=$ISSUES_CLOSED" >> $GITHUB_OUTPUT
59+
echo "issues_new=$ISSUES_NEW" >> $GITHUB_OUTPUT
60+
echo "stars=$STARS" >> $GITHUB_OUTPUT
61+
echo "total_commits=$TOTAL_COMMITS" >> $GITHUB_OUTPUT
62+
echo "date=$TODAY" >> $GITHUB_OUTPUT
63+
64+
- name: Preparar mensaje Discord
65+
id: message
66+
env:
67+
COMMITS: ${{ steps.stats.outputs.commits }}
68+
PRS: ${{ steps.stats.outputs.prs }}
69+
ISSUES_CLOSED: ${{ steps.stats.outputs.issues_closed }}
70+
ISSUES_NEW: ${{ steps.stats.outputs.issues_new }}
71+
STARS: ${{ steps.stats.outputs.stars }}
72+
TOTAL_COMMITS: ${{ steps.stats.outputs.total_commits }}
73+
DATE: ${{ steps.stats.outputs.date }}
74+
run: |
75+
# Construir JSON del embed Discord
76+
cat > discord_payload.json << EOF
77+
{
78+
"username": "BESSAI Bot",
79+
"avatar_url": "https://raw.githubusercontent.com/bess-solutions/open-bess-edge/main/docs/media/bessai_logo.png",
80+
"embeds": [{
81+
"title": "📊 BESSAI Weekly Update — ${DATE}",
82+
"description": "Resumen semanal del proyecto **open-bess-edge**",
83+
"url": "https://github.com/${{ github.repository }}",
84+
"color": 5763719,
85+
"fields": [
86+
{
87+
"name": "🔀 Commits esta semana",
88+
"value": "${COMMITS}",
89+
"inline": true
90+
},
91+
{
92+
"name": "✅ PRs mergeados",
93+
"value": "${PRS}",
94+
"inline": true
95+
},
96+
{
97+
"name": "🐛 Issues cerradas",
98+
"value": "${ISSUES_CLOSED}",
99+
"inline": true
100+
},
101+
{
102+
"name": "🆕 Issues nuevas",
103+
"value": "${ISSUES_NEW}",
104+
"inline": true
105+
},
106+
{
107+
"name": "⭐ Estrellas totales",
108+
"value": "${STARS}",
109+
"inline": true
110+
},
111+
{
112+
"name": "📦 Total commits",
113+
"value": "${TOTAL_COMMITS}",
114+
"inline": true
115+
},
116+
{
117+
"name": "💰 Bounties activos",
118+
"value": "[Ver bounty_program.md](https://github.com/${{ github.repository }}/blob/main/docs/bounty_program.md)",
119+
"inline": false
120+
},
121+
{
122+
"name": "🔗 Links",
123+
"value": "[📚 Docs](https://bess-solutions.github.io/open-bess-edge) · [🐙 GitHub](https://github.com/${{ github.repository }}) · [💬 Discord](https://discord.gg/ZqpE8AZs)",
124+
"inline": false
125+
}
126+
],
127+
"footer": {
128+
"text": "BESSAI Edge Gateway — Industrial BESS Management OSS",
129+
"icon_url": "https://raw.githubusercontent.com/bess-solutions/open-bess-edge/main/docs/media/bessai_logo.png"
130+
},
131+
"timestamp": "$(date --utc +%Y-%m-%dT%H:%M:%SZ)"
132+
}]
133+
}
134+
EOF
135+
136+
- name: Publicar en Discord
137+
env:
138+
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEEKLY_WEBHOOK }}
139+
run: |
140+
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
141+
echo "⚠️ DISCORD_WEEKLY_WEBHOOK secret no configurado. Saltando publicación."
142+
echo "Contenido del mensaje que se hubiera enviado:"
143+
cat discord_payload.json
144+
exit 0
145+
fi
146+
147+
HTTP_STATUS=$(curl -s -o response.txt -w "%{http_code}" \
148+
-X POST "$DISCORD_WEBHOOK_URL" \
149+
-H "Content-Type: application/json" \
150+
-d @discord_payload.json)
151+
152+
if [ "$HTTP_STATUS" = "204" ] || [ "$HTTP_STATUS" = "200" ]; then
153+
echo "✅ Mensaje enviado a Discord correctamente (HTTP $HTTP_STATUS)"
154+
else
155+
echo "❌ Error enviando a Discord: HTTP $HTTP_STATUS"
156+
cat response.txt
157+
exit 1
158+
fi
159+
160+
- name: Resumen en GitHub Step Summary
161+
env:
162+
COMMITS: ${{ steps.stats.outputs.commits }}
163+
PRS: ${{ steps.stats.outputs.prs }}
164+
STARS: ${{ steps.stats.outputs.stars }}
165+
DATE: ${{ steps.stats.outputs.date }}
166+
run: |
167+
echo "## 📊 Weekly Update — ${DATE}" >> $GITHUB_STEP_SUMMARY
168+
echo "" >> $GITHUB_STEP_SUMMARY
169+
echo "| Métrica | Valor |" >> $GITHUB_STEP_SUMMARY
170+
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
171+
echo "| Commits esta semana | ${COMMITS} |" >> $GITHUB_STEP_SUMMARY
172+
echo "| PRs mergeados | ${PRS} |" >> $GITHUB_STEP_SUMMARY
173+
echo "| ⭐ Estrellas | ${STARS} |" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)