#!/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 [--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 --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"