Enhance repository discovery in README and setup script. Implement API access for fetching all accessible repositories, including owned, shared, and public repos. Add fallback method for pattern scanning and improve user feedback during repository selection.

This commit is contained in:
2025-07-14 11:03:27 +01:00
parent b37592e99d
commit a7d4e6ec0e
2 changed files with 124 additions and 32 deletions

105
setup.sh
View File

@@ -46,27 +46,106 @@ show_ssh_key() {
### === LIST AVAILABLE GIT PROJECTS === ###
list_git_projects() {
echo "[+] Fetching available git projects for user: $USERNAME..."
# Get list of repositories using git ls-remote
echo "[*] Available repositories:"
echo "[+] Fetching all accessible git projects..."
local repo_count=1
local found_repos=()
# Check for common repository patterns
for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do
local full_repo="$USERNAME/$repo"
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
echo "$repo_count. $full_repo"
found_repos+=("$full_repo")
((repo_count++))
# Try to use git server API if available (GitLab/Gitea style)
if command -v curl &> /dev/null; then
echo "[*] Attempting to fetch repositories via API..."
# Try GitLab API format
local gitlab_repos=$(curl -s -H "Authorization: Bearer $(ssh-add -L 2>/dev/null || echo '')" \
"https://$GIT_SERVER/api/v4/projects?membership=true&per_page=100" 2>/dev/null | \
grep -o '"path_with_namespace":"[^"]*' | cut -d'"' -f4 2>/dev/null || echo "")
# Try Gitea API format
if [ -z "$gitlab_repos" ]; then
local gitea_repos=$(curl -s "https://$GIT_SERVER/api/v1/user/repos" 2>/dev/null | \
grep -o '"full_name":"[^"]*' | cut -d'"' -f4 2>/dev/null || echo "")
gitlab_repos="$gitea_repos"
fi
done
if [ -n "$gitlab_repos" ]; then
echo "[*] Found repositories via API:"
while IFS= read -r repo; do
if [ -n "$repo" ]; then
echo "$repo_count. $repo"
found_repos+=("$repo")
((repo_count++))
fi
done <<< "$gitlab_repos"
fi
fi
# Fallback: Check common patterns for multiple users and the current user
if [ ${#found_repos[@]} -eq 0 ]; then
echo "[*] API not available, scanning common repository patterns..."
# Check user's own repositories first
for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do
local full_repo="$USERNAME/$repo"
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
echo "$repo_count. $full_repo (owner)"
found_repos+=("$full_repo")
((repo_count++))
fi
done
# Check common shared repositories and other users' public repos
local common_users=("admin" "shared" "public" "team" "common" "devops" "infrastructure")
local common_repos=("dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace" "templates" "shared-configs" "common-tools")
for user in "${common_users[@]}"; do
for repo in "${common_repos[@]}"; do
local full_repo="$user/$repo"
if [ "$user" != "$USERNAME" ] && git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
echo "$repo_count. $full_repo (shared)"
found_repos+=("$full_repo")
((repo_count++))
fi
done
done
# Try to discover repositories by checking SSH access to common paths
echo "[*] Checking for additional accessible repositories..."
# This is a more aggressive approach - try common project names
local project_names=("website" "api" "frontend" "backend" "database" "monitoring" "deployment" "ci-cd" "documentation")
for user in "${common_users[@]}" "$USERNAME"; do
for project in "${project_names[@]}"; do
local full_repo="$user/$project"
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null 2>&1; then
# Check if we haven't already added this repo
local already_added=false
for existing_repo in "${found_repos[@]}"; do
if [ "$existing_repo" = "$full_repo" ]; then
already_added=true
break
fi
done
if [ "$already_added" = false ]; then
local access_type="shared"
if [ "$user" = "$USERNAME" ]; then
access_type="owner"
fi
echo "$repo_count. $full_repo ($access_type)"
found_repos+=("$full_repo")
((repo_count++))
fi
fi
done
done
fi
if [ ${#found_repos[@]} -eq 0 ]; then
echo "[!] No repositories found for user: $USERNAME"
echo "[!] No accessible repositories found"
echo "[*] You can still enter a custom repository path."
else
echo
echo "[*] Found ${#found_repos[@]} accessible repositories"
fi
echo