97 lines
1.8 KiB
Bash
Executable File
97 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
GITEA_URL="http://git.konsthol.eu:3333"
|
|
|
|
USERNAME="konsthol"
|
|
|
|
NAME="${0##*/}"
|
|
|
|
function usage() {
|
|
|
|
cat <<EOF
|
|
|
|
USAGE: $NAME [OPTIONS]
|
|
|
|
OPTIONS:
|
|
|
|
-h,--help Display this message
|
|
|
|
-c,--create Create a reposiroty
|
|
|
|
-d,--delete Delete a reposority
|
|
|
|
-l,--list List repositories
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
function createRepo() {
|
|
|
|
curl -X POST \
|
|
"$GITEA_URL/api/v1/user/repos?access_token=$(pass SelfHosted/giteaTokenForKonsthol)" \
|
|
-H "accept:application/json" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"auto_init\": false,
|
|
\"description\": \"$2\",
|
|
\"gitignores\": \"\",
|
|
\"issue_labels\": \"\",
|
|
\"license\": \"\",
|
|
\"name\": \"$1\",
|
|
\"private\": false,
|
|
\"readme\": \"\"
|
|
}"
|
|
|
|
}
|
|
|
|
function deleteRepo() {
|
|
|
|
curl -X DELETE \
|
|
"$GITEA_URL/api/v1/repos/$USERNAME/$1?access_token=$(pass SelfHosted/giteaTokenForKonsthol)" \
|
|
-H "accept:application/json"
|
|
|
|
}
|
|
|
|
function listRepos {
|
|
|
|
RESPONSE=$(curl -s -X GET \
|
|
"$GITEA_URL/api/v1/users/$USERNAME/repos?access_token=$(pass SelfHosted/giteaTokenForKonsthol)" \
|
|
-H "accept:application/json" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"page\": \"5\",
|
|
\"limit\": \"5\"
|
|
}")
|
|
|
|
echo "$RESPONSE" | jq | grep "full_name\": \"$USERNAME" | awk -F/ '{print $2}' | sed 's/"//g' | sed 's/,//g'
|
|
|
|
}
|
|
|
|
if (( $# == 0 )); then
|
|
usage
|
|
else
|
|
for arg in "$@"; do
|
|
case $arg in
|
|
-h|--help)
|
|
usage
|
|
;;
|
|
-c|--create)
|
|
read -p "Enter new repo's name: " name
|
|
read -p "Enter new repo's description: " description
|
|
createRepo "$name" "$description"
|
|
;;
|
|
-d|--delete)
|
|
read -p "Enter to be deleted repo's name: " name
|
|
deleteRepo "$name"
|
|
;;
|
|
-l|--list)
|
|
listRepos
|
|
echo -e ""
|
|
;;
|
|
*)
|
|
printf "\nOption does not exist: %s\n\n" "$arg"
|
|
esac
|
|
done
|
|
fi
|