Skip to content

Weekly clone stats #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Mar 25, 2025
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
70390b8
adds workflow
Dopeamin Mar 24, 2025
0bb3193
adds pullrequest as trigger
Dopeamin Mar 24, 2025
0658fee
fixes flow
Dopeamin Mar 24, 2025
422a081
use upload-artifact v4
Dopeamin Mar 24, 2025
8c42332
uses download-artifact v4
Dopeamin Mar 24, 2025
327a8cc
fixes email sending
Dopeamin Mar 24, 2025
c1d61e8
prints result
Dopeamin Mar 24, 2025
71e3f54
prints result
Dopeamin Mar 24, 2025
8800347
removes PR triggering
Dopeamin Mar 24, 2025
da29073
fixes clone number issue
Dopeamin Mar 24, 2025
399f541
adds trigger
Dopeamin Mar 24, 2025
78baacf
fixes link
Dopeamin Mar 24, 2025
06b17ee
fixes credentials
Dopeamin Mar 24, 2025
e52436d
fixes credentials
Dopeamin Mar 24, 2025
a26b455
fixes credentials
Dopeamin Mar 24, 2025
f230edc
adds back email sending
Dopeamin Mar 24, 2025
4a6bbe6
removes not needed step
Dopeamin Mar 24, 2025
5c7d1f2
add email sending
Dopeamin Mar 24, 2025
235261b
add email sending
Dopeamin Mar 24, 2025
ae9f976
add email sending
Dopeamin Mar 25, 2025
05a49a3
add email sending
Dopeamin Mar 25, 2025
40f9f98
add email sending
Dopeamin Mar 25, 2025
510b991
add email sending
Dopeamin Mar 25, 2025
2e81c78
add email sending
Dopeamin Mar 25, 2025
2baf3d4
add email sending
Dopeamin Mar 25, 2025
3d9c778
add email sending
Dopeamin Mar 25, 2025
b4655d4
add email sending
Dopeamin Mar 25, 2025
6aa6ca0
add email sending
Dopeamin Mar 25, 2025
f78dc62
add email sending
Dopeamin Mar 25, 2025
261a778
add email sending
Dopeamin Mar 25, 2025
75738a2
add email sending
Dopeamin Mar 25, 2025
e832012
removes on pr
Dopeamin Mar 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/weekly_clone_stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Weekly Clone Stats Email

on:
schedule:
- cron: '0 8 * * 1' # Every Monday at 08:00 UTC

permissions:
contents: read

jobs:
fetch-clone-stats:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Fetch Clone Stats
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
REPO="${{ github.repository }}"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPO/traffic/clones > clone_stats.json

- name: Upload Clone Stats
uses: actions/upload-artifact@v4
with:
name: clone-stats
path: clone_stats.json

downloading-and-sending-stats:
needs: fetch-clone-stats
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Download Clone Stats
uses: actions/download-artifact@v4
with:
name: clone-stats
path: .

- name: Parse clone stats
id: parse
run: |
COUNT=$(jq '.count' clone_stats.json)
UNIQUES=$(jq '.uniques' clone_stats.json)
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
echo "uniques=$UNIQUES" >> "$GITHUB_OUTPUT"

- name: Send custom email
run: |
ENCODED_AUTH=${{ secrets.SENDGRID_KEY }}
FROM=${{ vars.EMAIL_FROM }}
TO=${{ vars.EMAIL_TO }}
COUNT=${{ steps.parse.outputs.count }}
REPOSITORY=${{ github.repository }}
UNIQUES=${{ steps.parse.outputs.uniques }}

curl -X POST https://api.sendgrid.com/v3/mail/send \
-H "Authorization: Bearer $ENCODED_AUTH" \
-H "Content-Type: application/json" \
-d "{
\"personalizations\": [{
\"to\": [{\"email\": \"${TO}\"}],
\"subject\": \"Weekly GitHub Clone Stats for ${REPOSITORY}\"
}],
\"from\": {\"email\": \"${FROM}\"},
\"content\": [{
\"type\": \"text/plain\",
\"value\": \"Hi there! Here are the clone stats for ${REPOSITORY} this week:\n\n🔁 Total Clones: ${COUNT}\n👤 Unique Cloners: ${UNIQUES}\"
}]
}"