-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·67 lines (62 loc) · 2.13 KB
/
export.sh
File metadata and controls
executable file
·67 lines (62 loc) · 2.13 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
#!/bin/bash
set -x
ACCEPT_HEADER="-H 'Accept: application/vnd.github+json'"
TYPE=${SOURCE_TYPE:=organization}
LOCK=${SOURCE_LOCK:=false}
# list all repos
if [ "$TYPE" == "organization" ]; then
rREPOS=$(curl -s $ACCEPT_HEADER -H "Authorization: Bearer $SOURCE_TOKEN" https://api.github.com/orgs/$ORGANIZATION/repos?per_page=100)
else
rREPOS=$(curl -s $ACCEPT_HEADER -H "Authorization: Bearer $SOURCE_TOKEN" https://api.github.com/user/repos?per_page=100\&affiliation=owner)
fi
REPOS=$(echo $rREPOS | jq -r '[.[].full_name'])
# start a migration from target
if [ "$TYPE" == "organization" ]; then
rID=$(curl -s -X POST \
$ACCEPT_HEADER \
-H "Authorization: Bearer $SOURCE_TOKEN" \
-d'{"lock_repositories":'$LOCK', "repositories":'"$REPOS"'}' \
https://api.github.com/orgs/$ORGANIZATION/migrations)
else
rID=$(curl -s -X POST \
$ACCEPT_HEADER \
-H "Authorization: Bearer $SOURCE_TOKEN" \
-d'{"lock_repositories":'$LOCK', "repositories":'"$REPOS"'}' \
https://api.github.com/user/migrations)
fi
ID=$(echo $rID | jq -r '.id')
# check migration status until exported
check_migration () {
if [ "$TYPE" == "organization" ]; then
r=$(curl -s \
$ACCEPT_HEADER \
-H "Authorization: Bearer $SOURCE_TOKEN" \
https://api.github.com/orgs/$ORGANIZATION/migrations/$ID)
else
r=$(curl -s \
$ACCEPT_HEADER \
-H "Authorization: Bearer $SOURCE_TOKEN" \
https://api.github.com/user/migrations/$ID)
fi
echo $r | jq -r '. | select(.state=="exported") | .guid'
}
GUID=
while [[ "$GUID" == "" ]]; do
GUID=$(check_migration);
sleep 5;
echo 'Waiting on migration...'
done
if [ "$TYPE" == "organization" ]; then
DOWNLOAD=$(curl -s \
-H 'Accept: application/vnd.github+json' \
-H "Authorization: Bearer $SOURCE_TOKEN" \
-L -o $ORGANIZATION.tar.gz --write-out '%{http_code}' \
https://api.github.com/orgs/$ORGANIZATION/migrations/$ID/archive)
else
DOWNLOAD=$(curl -s \
-H 'Accept: application/vnd.github+json' \
-H "Authorization: Bearer $SOURCE_TOKEN" \
-L -o $ORGANIZATION.tar.gz --write-out '%{http_code}' \
https://api.github.com/user/migrations/$ID/archive)
fi
echo $DOWNLOAD