-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_importer.sh
More file actions
executable file
·53 lines (43 loc) · 980 Bytes
/
git_importer.sh
File metadata and controls
executable file
·53 lines (43 loc) · 980 Bytes
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
#! /bin/bash
if [ -z "$GITHUB_TOKEN" ]
then
echo "GitHub token not set"
exit 1
fi
if [ -z "$REPO_URL" ]
then
echo "Repo URL not set"
exit 1
fi
REPO_PATH=/usr/app/repo
git config --global url."https://$GITHUB_TOKEN:@github.com/".insteadOf "https://github.com/"
if [ -z "$(ls -A $REPO_PATH)" ]
then
echo "Repo not cloned to $REPO_PATH"
# add random sleep
# if there are many importers started it could generate spike in load
# there is no rush
sleep $((1 + $RANDOM + 300))
git clone $REPO_URL $REPO_PATH
if [ $? -ne 0 ]; then
echo "ERROR: failed to clone repo"
exit 1
fi
fi
while :
do
# loop infinitely
pushd $REPO_PATH
git pull
if [ $? -ne 0 ]; then
echo "ERROR: failed to pull repo"
break
fi
popd
python collect_stats.py $REPO_PATH
if [ $? -ne 0 ]; then
echo "ERROR: failed to collect stats"
break
fi
sleep $((3600 + $RANDOM + 300))
done