From 16a1336c5d54452a577b86b394cc37e032c8e5ad Mon Sep 17 00:00:00 2001 From: RahulABangar07 Date: Tue, 5 Aug 2025 22:21:50 +0530 Subject: [PATCH 1/3] Create list-folder-repo.sh --- list-folder-repo.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 list-folder-repo.sh diff --git a/list-folder-repo.sh b/list-folder-repo.sh new file mode 100644 index 0000000000000..337f05370beb3 --- /dev/null +++ b/list-folder-repo.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# === Configuration === +REPO_URL="https://gitlab.com/group/repo.git" +CLONE_DIR="temp_repo" + +# === Clone the repo (shallow clone) === +git clone --depth 1 "$REPO_URL" "$CLONE_DIR" +cd "$CLONE_DIR" || exit + +# === Get all subfolders === +mapfile -t folder_array < <(find . -type d ! -path './.git*' ! -path '.') + +# === Print the array === +echo "Folders:" +printf "%s\n" "${folder_array[@]}" + +# === Clean up === +cd .. +rm -rf "$CLONE_DIR" From a24d9f5c9e90daa6f5d0f19cd41c96aed6353531 Mon Sep 17 00:00:00 2001 From: RahulABangar07 Date: Tue, 5 Aug 2025 22:50:21 +0530 Subject: [PATCH 2/3] Update list-folder-repo.sh --- list-folder-repo.sh | 67 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/list-folder-repo.sh b/list-folder-repo.sh index 337f05370beb3..07e8fb18c03c5 100644 --- a/list-folder-repo.sh +++ b/list-folder-repo.sh @@ -1,20 +1,61 @@ #!/bin/bash # === Configuration === -REPO_URL="https://gitlab.com/group/repo.git" -CLONE_DIR="temp_repo" +GITLAB_URL="https://gitlab.com" +GITLAB_TOKEN="your_gitlab_token_here" +GROUP_NAME="your_group_or_username" +TMP_DIR="./repos_temp" +BRANCH_NAME="develop" -# === Clone the repo (shallow clone) === -git clone --depth 1 "$REPO_URL" "$CLONE_DIR" -cd "$CLONE_DIR" || exit +# === Create temp directory === +mkdir -p "$TMP_DIR" -# === Get all subfolders === -mapfile -t folder_array < <(find . -type d ! -path './.git*' ! -path '.') +# === Get all projects (handling pagination) === +page=1 +per_page=100 +project_urls=() -# === Print the array === -echo "Folders:" -printf "%s\n" "${folder_array[@]}" +echo "Fetching projects from GitLab..." -# === Clean up === -cd .. -rm -rf "$CLONE_DIR" +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." From fe8348ddb1ef5390eb9765a3380f6d8b320d51c3 Mon Sep 17 00:00:00 2001 From: RahulABangar07 Date: Tue, 5 Aug 2025 23:03:02 +0530 Subject: [PATCH 3/3] Create LineOfCodeInRepo --- LineOfCodeInRepo | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 LineOfCodeInRepo diff --git a/LineOfCodeInRepo b/LineOfCodeInRepo new file mode 100644 index 0000000000000..3a9468463f7bf --- /dev/null +++ b/LineOfCodeInRepo @@ -0,0 +1,40 @@ +#!/bin/bash + +# === Configuration === +REPO_LIST=( + "git@gitlab.com:yourgroup/repo1.git" + "git@gitlab.com:yourgroup/repo2.git" + "git@gitlab.com: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."