initial
This commit is contained in:
commit
f7dbd579af
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/runme.sh
|
||||||
58
migrate.sh
Executable file
58
migrate.sh
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euf -o pipefail
|
||||||
|
|
||||||
|
curp="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
create_org() {
|
||||||
|
orgid=$(curl --silent -X POST "${apiurl}/orgs" \
|
||||||
|
-H "Authorization: token ${token}" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{ \"username\": \"$1\", \"visibility\": \"limited\"}" | jq -r '.id')
|
||||||
|
[[ "$orgid" != "null" ]] && sleep 1 || true
|
||||||
|
}
|
||||||
|
|
||||||
|
create_repo() {
|
||||||
|
repoid=$(curl --silent -X POST "${apiurl}$2" \
|
||||||
|
-H "Authorization: token ${token}" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"auto_init\": false, \"private\": true, \"name\": \"$1\"}" | jq -r '.id')
|
||||||
|
[[ "$repoid" != "null" ]] && sleep 5 || true
|
||||||
|
}
|
||||||
|
|
||||||
|
serverurl="$1"
|
||||||
|
token="$2"
|
||||||
|
admin="$3"
|
||||||
|
password="$4"
|
||||||
|
repos="${@:5}"
|
||||||
|
pushuri="$(echo "$serverurl" | perl -pe "s#(https?://)#\${1}${admin}:${password}@#")"
|
||||||
|
apiurl="$serverurl/api/v1"
|
||||||
|
|
||||||
|
# repo examples
|
||||||
|
# /path/to/repo:orgname ( orgname only )
|
||||||
|
# /path/to/repo::reponame ( repo name only )
|
||||||
|
# /path/to/repo:orgname:reponame ( all options passed )
|
||||||
|
# /path/to/repo ( use name from path, no org )
|
||||||
|
|
||||||
|
# init repos
|
||||||
|
for repo in ${repos}; do
|
||||||
|
repoPath="$(echo "$repo" | cut -d ':' -f1 | tr -d '[:space:]')"
|
||||||
|
repoOrg="$(echo "$repo" | cut -d ':' -f2 | tr -d '[:space:]')"
|
||||||
|
repoName="$(echo "$repo" | cut -d ':' -f3 | tr -d '[:space:]')"
|
||||||
|
[ -z "$repoName" ] && repoName="$(basename "$repoPath")"
|
||||||
|
if [ -z "$repoOrg" ]; then
|
||||||
|
repoAPIEP="/user/repos"
|
||||||
|
repoOwner="${ADMIN_USER}"
|
||||||
|
else
|
||||||
|
create_org "$repoOrg"
|
||||||
|
repoAPIEP="/org/$repoOrg/repos"
|
||||||
|
repoOwner="$repoOrg"
|
||||||
|
fi
|
||||||
|
create_repo "${repoName}" "${repoAPIEP}" 1>&2
|
||||||
|
(
|
||||||
|
cd "$repoPath"
|
||||||
|
git push "$pushuri/${repoOwner}/${repoName}.git" master
|
||||||
|
)
|
||||||
|
done
|
||||||
2
repos/.gitignore
vendored
Normal file
2
repos/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
Loading…
x
Reference in New Issue
Block a user