-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror-github
executable file
·63 lines (59 loc) · 1.89 KB
/
mirror-github
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
#!/bin/sh
if [ "`hostname |cut -d. -f1`" != "abf" ]; then
echo "This script must be run on abf"
exit 1
fi
json() {
python -c "
import json,sys
try:
print(json.load(sys.stdin)$@)
except IndexError:
pass
"
}
MYDIR="$(realpath $(dirname $0))"
if [ -z "$OAUTH_TOKEN" ]; then
echo "Before running this script, set OAUTH_TOKEN to a token"
echo "generated using https://github.com/settings/token"
exit 1
fi
PERPAGE=100
COUNT=0
for org in OpenMandrivaAssociation OpenMandrivaSoftware; do
START=""
mkdir -p "$MYDIR/$org"
while true; do
QUERY="{\"query\": \"query {organization(login:\\\"$org\\\") { id name repositories(first:$PERPAGE $START) { edges { node { id name } cursor } pageInfo { endCursor hasNextPage } } } }\""
REPOS="$(curl -H "Authorization: token $OAUTH_TOKEN" -X POST -d "$QUERY" https://api.github.com/graphql 2>/dev/null)"
if [ -z "$REPOS" ]; then
echo "$QUERY failed" >&2
break
fi
for i in $(seq 0 $((PERPAGE-1))); do
R="$(echo $REPOS |json "['data']['organization']['repositories']['edges'][$i]['node']['name']").git"
if [ "$R" = ".git" ]; then
echo "No more repositories at $QUERY $i" >&2
break
fi
if [ "$R" = "abf-yml.git" -o "$R" = "secret-keys.git" -o "$R" = "OpenMandrivaAssociation.github.io.git" ]; then
# These repositories contain passwords and aren't public
# Since we aren't authenticated, can't mirror them
continue
fi
COUNT=$((COUNT+1))
echo "Mirroring $org/$R"
cd "$MYDIR/$org"
if [ -d "$R" ]; then
cd "$R"
git fetch --prune --all
else
git clone --mirror "https://github.com/$org/$R"
echo $R >>"$MYDIR"/NEW-REPOS.log
fi
done
[ "$(echo $REPOS |json "['data']['organization']['repositories']['pageInfo']['hasNextPage']")" != "True" ] && break
START="after:\\\"$(echo $REPOS |json "['data']['organization']['repositories']['pageInfo']['endCursor']")\\\""
done
done
echo "$COUNT repositories mirrored."