-
Notifications
You must be signed in to change notification settings - Fork 0
/
githarvesting.sh
executable file
·72 lines (72 loc) · 1.54 KB
/
githarvesting.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# 1 - realizar o clone do repositório localmente. Ex: git clone https://github.com/reddit/reddit.git
# Clone your repository.
# 2 - Executar este script contra o repositório: ./githarvesting.sh /caminho/para/repositório
# Execute githarvesting.sh against repository path
# 3 - Opicional - redirecionar a saída padrão do script para um arquivo .csv
#
#
#
_repo="$1"
_list="/tmp/githarvesting.log"
#
#
#
if [ -z "$_repo" ]
then
echo "./script /path/to/repo"
exit 1
fi
#
#
#
if [ ! -z "$_repo" ] && [ ! -d "$_repo" ]
then
echo "$_repo is not a directory"
exit 1
fi
#
#
#
if [ ! -d "$_repo"/.git ]
then
echo "$_repo Not a git repository"
exit
else
cd "$_repo"
git log > "$_list"
fi
#
#
#
echo "First Name,Last Name,Position,Email"
#
#
#
while read _line;
do
echo "$_line" | grep -q ^"Author:"
_key="$?"
if [ "$_key" == "0" ]
then
_name=$(echo "$_line" | cut -d':' -f 2 | cut -d'<' -f 1 | tr -d '"' | sed 's/^ *//')
_firstname="$(echo "$_name" | awk '{print $1}' | tr -d ',')"
if [ -z "$_firstname" ]
then
_firstname="First Name"
fi
_lastname="$(echo $_name | awk '{print $NF}' | tr -d ',')"
_position="$(echo "$_line"|awk '{print $1}'| tr -d ':')"
if [ -z "$_position" ]
then
_position="Author"
fi
_email="$(echo "$_line" | grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b")"
_fmail="$(echo "$_email" | head -n 1)"
if [ ! -z "$_firstname" ] && [ ! -z "$_lastname" ] && [ ! -z "$_position" ] && [ ! -z "$_fmail" ]
then
echo "$_firstname,$_lastname,$_position,$_fmail"
fi
fi
done < "$_list"