-
Notifications
You must be signed in to change notification settings - Fork 6
/
activity.sh
128 lines (104 loc) · 3.22 KB
/
activity.sh
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
#!/bin/bash
set -e
#
## Use for demo purposes only!
## To execute just run the following commaind inside a demo repository:
#
# wget https://raw.githubusercontent.com/bobbyiliev/github-activity-bash-script/main/activity.sh
# bash activity.sh
#
## Finllly push your changes to GitHub:
#
# git push origin -f your_branch_name"
#
if [[ ! -d ".git" ]] ; then
cwd=$(pwd)
dir=$(mktemp -d -p $cwd test-git-repo-XXXXXXXXX)
mkdir -p $dir
cd $dir
git init
>&2 echo NO. NOT git repo...
exit 1
fi
# thomas-nyman CC BY-SA 3.0 https://unix.stackexchange.com/a/155077
if [[ -z "$(git status --porcelain)" ]] ; then
echo OK. Working directory clean...
else
>&2 echo NO. Working directory NOT clean. Uncommitted changes...
exit 2
fi
if [[ -z "ACTIVITY_BR" ]] ; then
ACTIVITY_BR="main"
fi
git checkout --orphan $ACTIVITY_BR >/dev/null 2>&1 || git checkout $ACTIVITY_BR > /dev/null 2>&1
# Create temp commits direcotry
if [[ ! -d .commits ]] ; then
mkdir -p .commits
fi
# Add changes file log
if [[ ! -f .commits/changes ]] ; then
touch .commits/changes
fi
if [[ -z "$MAX_PAST_DAYS" ]] ; then
MAX_PAST_DAYS=365
fi
# Create commits for the past 365 days
for (( day=$MAX_PAST_DAYS; day>=1; day-- )) ; do
# Get the past date of the commit
day2=$(date --date="-${day} day" "+%a, %d %b %Y %X %z")
echo "Creating commits for ${day}"
# Generate random number of commits for that date
if [[ -z "$COMMIT_NB" ]] ; then
if [[ -z "$COMMIT_MAX" ]] ; then
commits=$(( ( RANDOM % 6 ) + 2 ))
else
commits=$(( ( RANDOM % $COMMIT_MAX ) + 1 ))
fi
else
commits=$COMMIT_NB
fi
# Create the comits
echo "Creating ${commits} commits"
for ((i=1;i<=${commits};i++)); do
content=$(date -d "${day2}" +"%s")
echo ${content}-${i} >> .commits/changes
git add .commits/changes
git commit -m "Commit number ${content}-${i}"
git commit --amend --no-edit --date "${day2}"
done
done
function yes_or_no {
# author : tiago-lopo john-kugelman CC BY-SA 3.0 https://stackoverflow.com/a/29436423
# usage : yes_or_no "$message" && do_something
# modified
while true; do
read -p "$* [y/n]: " yn
case $yn in
[YyOo]*) return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
done
}
if command -v gh ; then
echo
echo OK. github cli found.
yes_or_no "Did you want to create repo on github ? " && \
gh repo create $(basename $(pwd)) \
-y \
--private \
--description 'generated by https://github.com/ccdd12/github-activity-bash-script' \
--homepage 'https://github.com/ccdd12/github-activity-bash-script' \
>/dev/null 2>&1 || \
echo NO. repo already exist.
fi
echo
yes_or_no "Did you want to push to remote 'origin' ? " && \
git push --force --set-upstream origin $ACTIVITY_BR || \
echo OK. push to your own remote remote/branch.
cat << EOF
Generating commits completed...
To push your changes later :
git remote add origin https://github.com/username/$(basename $(pwd))
gh repo create
git push --force --set-upstream origin $ACTIVITY_BR
EOF