Initial commit: git-hangman-lab and keycloak-hangman-lab skills
This commit is contained in:
65
git-hangman-lab/scripts/git/repo-add-collaborators
Executable file
65
git-hangman-lab/scripts/git/repo-add-collaborators
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
roster=false
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--repo)
|
||||
repo="$2"
|
||||
shift 2
|
||||
;;
|
||||
--user)
|
||||
user="$2"
|
||||
shift 2
|
||||
;;
|
||||
--roster)
|
||||
roster=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if user is provided
|
||||
if [[ -z "$user" ]]; then
|
||||
echo "Usage: $0 --user <user> [--repo <repo>] [--roster]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Handle roster mode
|
||||
if [[ "$roster" == "true" ]]; then
|
||||
owner="hzhang"
|
||||
repo=".roster"
|
||||
|
||||
# Check if git-adm key exists
|
||||
if ! pass_mgr list | grep -q "git-adm"; then
|
||||
echo "you dont have permission to run this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
token=$(pass_mgr get-secret --key git-adm)
|
||||
else
|
||||
# Check if repo and git-access-token are provided
|
||||
if [[ -z "$repo" ]]; then
|
||||
echo "Usage: $0 --user <user> --repo <repo>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! pass_mgr list | grep -q "git-access-token"; then
|
||||
echo "generate your access token first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
owner=$(pass_mgr get-username --key git)
|
||||
token=$(pass_mgr get-secret --key git-access-token)
|
||||
fi
|
||||
|
||||
# Execute
|
||||
curl -X PUT -H "Authorization: token $token" -H "Content-Type: application/json" -d '{"permission":"write"}' "https://git.hangman-lab.top/api/v1/repos/$owner/$repo/collaborators/$user"
|
||||
Reference in New Issue
Block a user