-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutil.sh
83 lines (73 loc) · 1.9 KB
/
util.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
#!/bin/bash
set -x -u -e -a
export SHELLOPTS
MAX_PROCS=6
SUBGIT=./subgit-3.2.6/bin/subgit
SVN_ROOT='file:///home/apertium/svn-mirror/apertium-sf-net'
GITHUB_API='https://api.github.com'
USER='sushain97'
ORG='apertium'
GITHUB_ROOT="https://github.com/${ORG}"
LANG_RE='\w{2,3}(_\w+)?'
delete_repo () {
curl -X DELETE "$GITHUB_API/repos/$ORG/$1" -u "$USER:$GITHUB_OAUTH_TOKEN"
}
create_repo () {
curl -s -S -X POST $GITHUB_API/orgs/$ORG/repos \
-u "$USER:$GITHUB_OAUTH_TOKEN" \
-d "{\"name\":\"$1\"}"
}
init_repo () {
git clone "[email protected]:$ORG/$1.git"
(
cd "$1"
echo "# $1" > README.md
git add README.md
git diff-index --quiet HEAD || git commit -m "Initial commit"
git push
)
rm -rf "$1"
}
set_repo_topics () {
curl -s -S -X PUT "$GITHUB_API/repos/$ORG/$1/topics" \
-u "$USER:$GITHUB_OAUTH_TOKEN" \
-d "{\"names\":$2}" \
-H "Accept:application/vnd.github.mercy-preview+json"
}
import_repo () {
$SUBGIT configure \
--layout auto \
--svn-url $SVN_ROOT \
--trunk "$1" \
"$2.git"
cp ./svn-authors.txt "$2.git/subgit/authors.txt"
$SUBGIT import "$2.git"
}
push_bare_repo () {
(
cd "$1.git/"
git remote add origin "[email protected]:$ORG/$1.git"
git push origin --force --all
git push origin --force --tags
git push origin --force refs/notes/*
git push origin --force refs/svn/map
)
}
exists_repo () {
curl -s -S "$GITHUB_API/repos/$ORG/$1" \
-u "$USER:$GITHUB_OAUTH_TOKEN" \
-w "%{http_code}" \
-o /dev/null
}
import_create_and_push_repo () {
if [[ $( exists_repo "$2" ) == '200' ]]
then
echo "$2 already exists in $ORG";
else
import_repo "$1" "$2"
create_repo "$2"
push_bare_repo "$2"
set_repo_topics "$2" "$3"
rm -rf "$2.git/"
fi
}