Skip to content

Commit 11aba27

Browse files
authored
Update stats.yml
1 parent 9eb0e38 commit 11aba27

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

.github/workflows/stats.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: Checkout repository
13+
- name: Checkout repository using PAT
1414
uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.GH_TRAFFIC_TOKEN }}
1517

1618
- name: Fetch & Aggregate All Repo Traffic
1719
env:
@@ -22,33 +24,19 @@ jobs:
2224
TRAFFIC_FILE=metrics/traffic.csv
2325
REFERRERS_FILE=metrics/referrers.csv
2426
25-
# Create traffic CSV if not exists
26-
if [ ! -f "$TRAFFIC_FILE" ]; then
27-
echo "repo,timestamp,clones,unique_cloners,views,unique_visitors" > $TRAFFIC_FILE
28-
fi
27+
# Initialize CSVs if not exist
28+
[ ! -f "$TRAFFIC_FILE" ] && echo "repo,timestamp,clones,unique_cloners,views,unique_visitors" > $TRAFFIC_FILE
29+
[ ! -f "$REFERRERS_FILE" ] && echo "repo,timestamp,referrer,views" > $REFERRERS_FILE
2930
30-
# Create referrers CSV if not exists
31-
if [ ! -f "$REFERRERS_FILE" ]; then
32-
echo "repo,timestamp,referrer,views" > $REFERRERS_FILE
33-
fi
34-
35-
# Hardcoded list of repos
36-
REPOS=(
37-
"SasanLabs/VulnerableApp"
38-
"SasanLabs/VulnerableApp-facade"
39-
"SasanLabs/LLMForge"
40-
"SasanLabs/SAFE"
41-
)
31+
REPOS=("SasanLabs/VulnerableApp" "SasanLabs/VulnerableApp-facade" "SasanLabs/LLMForge" "SasanLabs/SAFE")
4232
4333
for REPO in "${REPOS[@]}"; do
4434
echo "Fetching traffic for $REPO"
4535
46-
# Fetch clones and views
4736
CLONES_JSON=$(curl -s -H "Authorization: Bearer $TOKEN" \
4837
-H "Accept: application/vnd.github+json" \
4938
https://api.github.com/repos/$REPO/traffic/clones)
50-
echo "Raw clones JSON for $REPO:"
51-
echo "$CLONES_JSON"
39+
5240
VIEWS_JSON=$(curl -s -H "Authorization: Bearer $TOKEN" \
5341
-H "Accept: application/vnd.github+json" \
5442
https://api.github.com/repos/$REPO/traffic/views)
@@ -58,22 +46,16 @@ jobs:
5846
TOTAL_VIEWS=$(echo $VIEWS_JSON | jq '.count')
5947
UNIQUE_VISITORS=$(echo $VIEWS_JSON | jq '.uniques')
6048
61-
# Append traffic to CSV (avoid duplicates)
6249
LAST=$(grep "^$REPO," $TRAFFIC_FILE | tail -n1 | cut -d',' -f3-6)
6350
CURRENT="$TOTAL_CLONES,$UNIQUE_CLONERS,$TOTAL_VIEWS,$UNIQUE_VISITORS"
64-
if [ "$LAST" != "$CURRENT" ]; then
65-
echo "$REPO,$TIMESTAMP,$CURRENT" >> $TRAFFIC_FILE
66-
fi
51+
[ "$LAST" != "$CURRENT" ] && echo "$REPO,$TIMESTAMP,$CURRENT" >> $TRAFFIC_FILE
6752
68-
# Fetch referrers
6953
REFERRERS_JSON=$(curl -s -H "Authorization: Bearer $TOKEN" \
7054
-H "Accept: application/vnd.github+json" \
7155
https://api.github.com/repos/$REPO/traffic/popular/referrers)
7256
73-
# Append each referrer to separate CSV
7457
echo $REFERRERS_JSON | jq -r --arg REPO "$REPO" --arg TS "$TIMESTAMP" \
7558
'.[] | "\($REPO),\($TS),\(.referrer),\(.count)"' >> $REFERRERS_FILE
76-
7759
done
7860
7961
- name: Generate IMPACT.md
@@ -97,21 +79,20 @@ jobs:
9779
}
9880
END {
9981
for (r in count) {
100-
# Count unique referrers from referrers.csv
10182
cmd="grep ^"r" " ref_file " | cut -d, -f3 | sort | uniq | wc -l"
10283
cmd | getline ref_count
10384
close(cmd)
10485
printf "|%s|%d|%d|%d|%d|%s|\n", r, sum[r], unique, int(sum[r]/count[r]), count[r], ref_count
10586
}
10687
}' >> $IMPACT
10788
108-
- name: Commit & Push
89+
- name: Commit & Push changes
10990
env:
110-
TOKEN: ${{ secrets.GH_TRAFFIC_TOKEN }}
91+
TOKEN: ${{ secrets.GH_TRAFFIC_TOKEN }}
11192
run: |
11293
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
11394
git config user.name "preetkaran20"
11495
git config user.email "preetkaran20@gmail.com"
11596
git add metrics/traffic.csv metrics/referrers.csv IMPACT.md
11697
git commit -m "Update multi-repo traffic metrics ($TIMESTAMP)" || echo "No changes"
117-
git push origin master
98+
git push "https://preetkaran20:${TOKEN}@github.com/SasanLabs/SAFE.git" HEAD:master

0 commit comments

Comments
 (0)