-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.sh
executable file
·58 lines (46 loc) · 1.42 KB
/
migrate.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
#!/bin/sh
# Be careful with this set to true
LOCKREPOS=false
ARCHIVE=githubdotcom-archive.tar.gz
failquit() {
echo "FATAL: $*"
exit 1
}
usagequit() {
echo 'Usage:'
echo 'GITHUBTOKEN=token'
echo 'ORGNAME=yourorg'
echo 'GITHUBUSER=your github.com username'
echo "$0: <repository name>"
exit 1
}
[ -z "$@" ] && usagequit
[ -z "$GITHUBTOKEN" ] && failquit "GITHUBTOKEN must be set."
[ -z "$ORGNAME" ] && failquit "ORGNAME must be set."
[ -z "$GITHUBUSER" ] && failquit "GITHUBUSER must be set."
# Only support one repo for now. Multiple should be simple.
REPO=$1
REPOS=\"$ORGNAME/$REPO\"
[ -z "$(which curl 2> /dev/null)" ] && failquit 'You need to install curl.'
migrationurl=$( \
curl -s -H "Authorization: token $GITHUBTOKEN" -X POST \
-H "Accept: application/vnd.github.wyandotte-preview+json" \
-d'{"lock_repositories":'"$LOCKREPOS"',"repositories":['"$REPOS"']}' \
"https://api.github.com/orgs/$ORGNAME/migrations" | \
grep '"url"' | grep migrations | cut -d \" -f 4
)
while sleep 10; do
state=$(
curl -s -H "Authorization: token $GITHUBTOKEN" \
-H "Accept: application/vnd.github.wyandotte-preview+json" \
"$migrationurl" | grep '"state"'
)
echo "$migrationurl: $state"
echo $state | grep -q exported && break
echo "Polling again in ten seconds."
done
curl -u $GITHUBUSER:$GITHUBTOKEN \
-H "Accept: application/vnd.github.wyandotte-preview+json" \
-L -o $ARCHIVE \
"$migrationurl/archive"
ls -l $ARCHIVE