-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontribute.sh
More file actions
executable file
·70 lines (59 loc) · 1.97 KB
/
contribute.sh
File metadata and controls
executable file
·70 lines (59 loc) · 1.97 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
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
DATA_FILE="$REPO_DIR/contributions.json"
DAYS_BACK="${1:-365}"
MIN_COMMITS="${2:-1}"
MAX_COMMITS="${3:-5}"
echo "🟩 GitHub Contribution Graph Filler"
echo "===================================="
echo "Filling $DAYS_BACK days with $MIN_COMMITS-$MAX_COMMITS commits per day"
echo ""
if [[ "$(uname)" == "Darwin" ]]; then
date_cmd() { date -v-"${1}"d +%Y-%m-%d; }
else
date_cmd() { date -d "$1 days ago" +%Y-%m-%d; }
fi
total_commits=0
for ((i = DAYS_BACK; i >= 0; i--)); do
commit_date=$(date_cmd "$i")
num_commits=$(( RANDOM % (MAX_COMMITS - MIN_COMMITS + 1) + MIN_COMMITS ))
for ((j = 1; j <= num_commits; j++)); do
hour=$(( RANDOM % 14 + 8 ))
minute=$(( RANDOM % 60 ))
second=$(( RANDOM % 60 ))
timestamp="${commit_date}T$(printf '%02d:%02d:%02d' $hour $minute $second)"
python3 -c "
import json, os, random, string
path = '$DATA_FILE'
data = {}
if os.path.exists(path):
with open(path) as f:
data = json.load(f)
entry = {
'date': '$commit_date',
'seq': $j,
'id': ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
}
data.setdefault('contributions', []).append(entry)
data['last_updated'] = '$timestamp'
data['total'] = len(data['contributions'])
with open(path, 'w') as f:
json.dump(data, f, indent=2)
"
export GIT_AUTHOR_DATE="$timestamp"
export GIT_COMMITTER_DATE="$timestamp"
git -C "$REPO_DIR" add -A
git -C "$REPO_DIR" commit -m "contrib: $commit_date #$j" --quiet
unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE
total_commits=$((total_commits + 1))
done
printf "\r Progress: day %d/%d (%s) — %d commits so far" \
$((DAYS_BACK - i + 1)) $((DAYS_BACK + 1)) "$commit_date" "$total_commits"
done
echo ""
echo ""
echo "Done! Created $total_commits commits over $((DAYS_BACK + 1)) days."
echo ""
echo "Now push to GitHub:"
echo " git push -u origin main"