Created
July 13, 2021 22:27
-
-
Save lelandbatey/83aa9615ad1b33489606381775498d97 to your computer and use it in GitHub Desktop.
Record all contributors to each Git repository in a file tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# list_all_contributors.sh ROOT_SEARCH_PATH | |
# | |
# Usage: Finds all Git repositories in ROOT_SEARCH_PATH and records all | |
# contributors to each repo, each repo getting one file, with these | |
# contributor files saved to the current directory. | |
# Copyright (C) 2021 Leland Batey | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU Affero General Public License as | |
# published by the Free Software Foundation, either version 3 of the | |
# License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU Affero General Public License for more details. | |
# | |
# Find the GNU Affero General Public License at <https://www.gnu.org/licenses/>. | |
SCAN_DIR="$1" | |
# Find all the '.git' folders then strip the '/.git' suffix leaving only the | |
# repo paths | |
GIT_REPOS="$(find "${SCAN_DIR}" -name "*.git" -type d | sed 's/\/.git$//g')" | |
# Creates a filename to be used to store the list of git contributors for the | |
# repo. Requires a prefix and a path, returns the filename. Filename will be | |
# rougly equal to path.trimprefix(prefix).replace('/', '_'). | |
# :param $1: string prefix | |
# :param $2: string path | |
function create_sanitize_usrlist_filename() { | |
python3 -c "import sys | |
prefix = sys.argv[1] | |
paths = sys.argv[2].split('\n') | |
for x in paths: | |
noprx = x.replace(prefix, '', 1) | |
if noprx[0] == '/': | |
noprx = noprx[1:] | |
print(noprx.replace('/', '_')) | |
" $@ | |
} | |
#create_sanitize_usrlist_filename "/home/leland/projects/repos" "/home/leland/projects/repos/python/foo/bar" | |
function printgitcontributors() { | |
cd "$1" | |
git shortlog HEAD --summary --numbered --email | |
} | |
CWD="$PWD" | |
for fn in $GIT_REPOS; do | |
OUTPUT_FN="$(create_sanitize_usrlist_filename "${SCAN_DIR}" "${fn}" )" | |
echo "date ${CWD}/${OUTPUT_FN} " | |
printgitcontributors "$fn" > "${CWD}/${OUTPUT_FN}" | |
cd "$CWD" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment