Skip to content

Create list-folder-repo.sh #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions LineOfCodeInRepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# === Configuration ===
REPO_LIST=(
"[email protected]:yourgroup/repo1.git"
"[email protected]:yourgroup/repo2.git"
"[email protected]:yourgroup/repo3.git"
)
BRANCH_NAME="develop"
TMP_DIR="./repos_temp"

# === Create temp directory ===
mkdir -p "$TMP_DIR"

echo "Processing ${#REPO_LIST[@]} repositories..."

for REPO_URL in "${REPO_LIST[@]}"; do
REPO_NAME=$(basename "$REPO_URL" .git)
CLONE_PATH="$TMP_DIR/$REPO_NAME"

echo "Cloning $REPO_NAME..."

# Clone only the develop branch
git clone --depth 1 --branch "$BRANCH_NAME" "$REPO_URL" "$CLONE_PATH" &>/dev/null

if [ $? -ne 0 ]; then
echo " ⚠️ Failed to clone $REPO_NAME or branch '$BRANCH_NAME' does not exist."
continue
fi

# Count non-empty lines
LINE_COUNT=$(find "$CLONE_PATH" -type f ! -path '*/.git/*' -exec cat {} + | grep -v '^\s*$' | wc -l)

echo " 📄 $REPO_NAME: $LINE_COUNT lines (non-empty)"
done

# === Cleanup ===
rm -rf "$TMP_DIR"

echo "✅ Done."
61 changes: 61 additions & 0 deletions list-folder-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# === Configuration ===
GITLAB_URL="https://gitlab.com"
GITLAB_TOKEN="your_gitlab_token_here"
GROUP_NAME="your_group_or_username"
TMP_DIR="./repos_temp"
BRANCH_NAME="develop"

# === Create temp directory ===
mkdir -p "$TMP_DIR"

# === Get all projects (handling pagination) ===
page=1
per_page=100
project_urls=()

echo "Fetching projects from GitLab..."

while :; do
response=$(curl -s --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
"$GITLAB_URL/api/v4/groups/$GROUP_NAME/projects?per_page=$per_page&page=$page")

urls=$(echo "$response" | jq -r '.[].ssh_url_to_repo')
[[ -z "$urls" || "$urls" == "null" ]] && break

while IFS= read -r url; do
project_urls+=("$url")
done <<< "$urls"

((page++))
done

echo "Total projects found: ${#project_urls[@]}"
echo "Cloning and counting lines in '$BRANCH_NAME' branches..."

# === For each project ===
for repo_url in "${project_urls[@]}"; do
repo_name=$(basename "$repo_url" .git)
repo_path="$TMP_DIR/$repo_name"

echo "Processing: $repo_name"

# Clone only the develop branch (shallow)
git clone --depth 1 --branch "$BRANCH_NAME" "$repo_url" "$repo_path" &>/dev/null

if [ $? -ne 0 ]; then
echo " ⚠️ Failed to clone $repo_name or branch '$BRANCH_NAME' does not exist."
continue
fi

# Count lines (non-empty lines only)
line_count=$(find "$repo_path" -type f ! -path '*/.git/*' -exec cat {} + | grep -v '^\s*$' | wc -l)

echo " 📄 $repo_name: $line_count lines (non-empty)"
done

# === Cleanup ===
rm -rf "$TMP_DIR"

echo "✅ Done."