Skip to content

Instantly share code, notes, and snippets.

@barata0
Created October 27, 2023 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barata0/6d5636a32d32cfe3515a36571a941a9a to your computer and use it in GitHub Desktop.
Save barata0/6d5636a32d32cfe3515a36571a941a9a to your computer and use it in GitHub Desktop.
get commit logs and tags from git repos
#!/bin/bash
# arquivo repos.txt com listagem dos repos a serem processados
mapfile -t repos < repos.txt
since=${1:-'01 Jan 2022'}
echo "--------- repos since ${since}"
echo $repos
echo "--------------------------"
# tem q apagar os arquivos se nao vai ficar incrementando
echo "apagando arquivos de resultado"
rm -f banking-commits.csv
rm -f banking-deploys.csv
process_repo() {
repo=$1
root_dir=$2
echo "processing $repo"
# clona o repositorio e vai para o diretorio
echo "cloning (or updating) ${repo}"
git clone git@github.com:dlpco/${repo}.git
cd ${repo}
# vai para a branch principal seja ela master ou main
git checkout $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
git pull
# lista os commit no arquivo csv
echo "getting commits: ${repo}"
git log --since="$since" --date=format:'%Y-%m' --pretty=format:'%ad|%s' | sort | sed -e "s/^/$repo|/" >> $root_dir/banking-commits.csv
git fetch --tags
# lista as tags no arquivo csv
echo "getting tags: ${repo}"
git for-each-ref --format="%(creatordate:format:%Y-%m)|%(refname)" --sort=-creatordate refs/tags | grep -v 'rc' | sed -e "s/^/$repo|/" >> $root_dir/banking-deploys.csv
cd ..
echo "done ${repo}"
}
echo "processando em paralelo os repos"
for repo in "${repos[@]}"; do
process_repo $repo $PWD &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment