feat(kugetsu): add git server configuration management

Add 'kugetsu server' command for managing git server configurations:
- kugetsu server list              List all configured git servers
- kugetsu server add <name> <url>  Add a new git server
- kugetsu server remove <name>     Remove a git server
- kugetsu server default [<name>]   Get or set default server
- kugetsu server get [<name>]       Get URL for a server

Update get_repo_url() to use GIT_SERVERS config:
- First checks repos.json for direct mapping
- Then checks GIT_SERVERS for matching hostname
- Falls back to DEFAULT_GIT_SERVER
- Falls back to github.com as last resort

Update cmd_init to create config with default git servers:
- github.com -> https://github.com
- git.fbrns.co -> https://git.fbrns.co

Fixes #78
This commit is contained in:
shokollm
2026-04-01 23:07:30 +00:00
parent 19a02ffc34
commit 3d3cb56491

View File

@@ -139,6 +139,7 @@ issue_ref_to_branch_name() {
get_repo_url() { get_repo_url() {
local issue_ref="$1" local issue_ref="$1"
if [ -f "$REPOS_CONFIG" ]; then if [ -f "$REPOS_CONFIG" ]; then
local url=$(python3 -c "import json, sys; d=json.load(open('$REPOS_CONFIG')); print(d.get('$issue_ref', ''))" 2>/dev/null || echo "") local url=$(python3 -c "import json, sys; d=json.load(open('$REPOS_CONFIG')); print(d.get('$issue_ref', ''))" 2>/dev/null || echo "")
if [ -n "$url" ]; then if [ -n "$url" ]; then
@@ -146,8 +147,20 @@ get_repo_url() {
return return
fi fi
fi fi
local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1) local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1)
local rest=$(echo "$issue_ref" | sed 's/.*\///' | sed 's/#.*//') local rest=$(echo "$issue_ref" | sed 's/.*\///' | sed 's/#.*//')
if [ -n "${GIT_SERVERS[$instance]:-}" ]; then
echo "${GIT_SERVERS[$instance]}/${rest}.git"
return
fi
if [ -n "${GIT_SERVERS[$DEFAULT_GIT_SERVER]:-}" ]; then
echo "${GIT_SERVERS[$DEFAULT_GIT_SERVER]}/${rest}.git"
return
fi
echo "https://${instance}/${rest}.git" echo "https://${instance}/${rest}.git"
} }
@@ -670,6 +683,100 @@ set_debug_mode() {
echo "${filtered_args[@]}" echo "${filtered_args[@]}"
} }
cmd_server() {
local action="${1:-}"
case "$action" in
""|"list")
if [ -z "${GIT_SERVERS+x}" ]; then
echo "No git servers configured"
return
fi
echo "Git servers:"
for key in "${!GIT_SERVERS[@]}"; do
local marker=""
if [ "$key" = "$DEFAULT_GIT_SERVER" ]; then
marker=" (default)"
fi
echo " $key -> ${GIT_SERVERS[$key]}$marker"
done
;;
"add")
local name="${2:-}"
local url="${3:-}"
if [ -z "$name" ] || [ -z "$url" ]; then
echo "Usage: kugetsu server add <name> <url>" >&2
exit 1
fi
if grep -q "^GIT_SERVERS\[" "$KUGETSU_DIR/config" 2>/dev/null; then
sed -i "s|^GIT_SERVERS\[\"$name\"\]=.*|GIT_SERVERS[\"$name\"]=\"$url\"|" "$KUGETSU_DIR/config"
if ! grep -q "GIT_SERVERS\[\"$name\"\]" "$KUGETSU_DIR/config" 2>/dev/null; then
sed -i "/^declare -A GIT_SERVERS/a GIT_SERVERS[\"$name\"]=\"$url\"" "$KUGETSU_DIR/config"
fi
else
echo "declare -A GIT_SERVERS" >> "$KUGETSU_DIR/config"
echo "GIT_SERVERS[\"$name\"]=\"$url\"" >> "$KUGETSU_DIR/config"
fi
source "$KUGETSU_DIR/config"
echo "Added git server: $name -> $url"
;;
"remove"|"rm"|"delete")
local name="${2:-}"
if [ -z "$name" ]; then
echo "Usage: kugetsu server remove <name>" >&2
exit 1
fi
if [ -n "${GIT_SERVERS[$name]:-}" ]; then
if [ "$name" = "$DEFAULT_GIT_SERVER" ]; then
echo "Error: Cannot remove default server. Set a new default first." >&2
exit 1
fi
sed -i "/GIT_SERVERS\[\"$name\"\]/d" "$KUGETSU_DIR/config" 2>/dev/null
source "$KUGETSU_DIR/config"
echo "Removed git server: $name"
else
echo "Error: Server '$name' not found" >&2
exit 1
fi
;;
"default")
local name="${2:-}"
if [ -z "$name" ]; then
echo "Current default: $DEFAULT_GIT_SERVER"
return
fi
if [ -n "${GIT_SERVERS[$name]:-}" ]; then
sed -i "s/^DEFAULT_GIT_SERVER=.*/DEFAULT_GIT_SERVER=\"$name\"/" "$KUGETSU_DIR/config"
source "$KUGETSU_DIR/config"
echo "Set default git server to: $name"
else
echo "Error: Server '$name' not found" >&2
exit 1
fi
;;
"get")
local name="${2:-$DEFAULT_GIT_SERVER}"
if [ -n "${GIT_SERVERS[$name]:-}" ]; then
echo "${GIT_SERVERS[$name]}"
else
echo "Error: Server '$name' not found" >&2
exit 1
fi
;;
*)
echo "Usage: kugetsu server <list|add|remove|default|get>" >&2
echo "" >&2
echo "Commands:" >&2
echo " list List all configured git servers" >&2
echo " add <name> <url> Add a new git server" >&2
echo " remove <name> Remove a git server" >&2
echo " default [<name>] Get or set default server" >&2
echo " get [<name>] Get URL for a server (default: current default)" >&2
exit 1
;;
esac
}
cmd_init() { cmd_init() {
local force=false local force=false
@@ -694,6 +801,13 @@ cmd_init() {
# Max concurrent dev agents (default: 3) # Max concurrent dev agents (default: 3)
# MAX_CONCURRENT_AGENTS=5 # MAX_CONCURRENT_AGENTS=5
# Git server configurations
# Format: GIT_SERVERS["hostname"]="https://hostname"
declare -A GIT_SERVERS
GIT_SERVERS["github.com"]="https://github.com"
GIT_SERVERS["git.fbrns.co"]="https://git.fbrns.co"
DEFAULT_GIT_SERVER="github.com"
EOF EOF
echo "Created config file: $KUGETSU_DIR/config" echo "Created config file: $KUGETSU_DIR/config"
fi fi
@@ -1174,6 +1288,9 @@ main() {
status) status)
cmd_status cmd_status
;; ;;
server)
cmd_server "$@"
;;
doctor) doctor)
cmd_doctor "$@" cmd_doctor "$@"
;; ;;