-
Notifications
You must be signed in to change notification settings - Fork 7
/
dump_hld_data.sh
executable file
·76 lines (68 loc) · 2.21 KB
/
dump_hld_data.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
73
74
75
76
#!/bin/bash
repos="sonic-net/sonic sonic-net/dash opencomputeproject/sai"
clone="n"
help(){
echo "Use:"
echo " -r # repo list, default $repos"
echo " -c # force reclone repo."
}
while [[ $# > 0 ]]
do
case "$1" in
-r)
repos=$2
shift
;;
-c)
clone="y"
;;
*)
help
exit 1
;;
esac
shift
done
for repo in $repos;do
repo_base=$(echo $repo | awk -F/ '{print$2}')
list=${repo_base}_hld.list
csv=${repo_base}_hld.csv
folder="doc"
[[ "$repo_base" == "dash" ]] && folder="documentation"
rm -f $csv.tmp
echo repo: $repo_base
echo csv: $csv
echo list: $list
echo folder: $folder
[[ "$clone" == "y" ]] && rm -rf $repo_base
[ -d $repo_base ] || git clone https://github.com/$repo
cd $repo_base
find $folder/ -xtype f -size +10c | grep -E -e "\.md" -e "\.MD" | grep -iv README.md > ../$list
while IFS= read -r line;do
if grep "$line" ../$csv 2> /dev/null | grep -v ,, > /dev/null ;then
grep "$line" ../$csv | grep -v ,, >> ../$csv.tmp
continue
fi
sha=$(git log --oneline --follow "$line" | tail -n 1 | awk '{print$1}')
gh pr list -R $repo -L 1 -s merged --json author,mergedAt -S "$sha" > tmp && sleep 1
author=$(cat tmp | jq -r ".[].author.login")
mergedAt=$(cat tmp | jq -r ".[].mergedAt")
if [ -z "$author" ];then
pr=$(git show $sha | head -n 5 | grep -Eo "(#[0-9]*)" | grep -Eo [0-9]*)
if [ -z $pr ];then
author=$(git show $sha -s --format="%an<%ae>")
mergedAt=$(date -d @$(git show $sha -s --format="%ct") +%FT%TZ)
echo == $author,$mergedAt
else
gh pr list -R $repo -L 1 -s merged --json author,mergedAt -S "number $pr" > tmp && sleep 1
author=$(cat tmp | jq -r ".[].author.login")
mergedAt=$(cat tmp | jq -r ".[].mergedAt")
echo == $pr,$author,$mergedAt
fi
fi
echo $repo_base,$line,$author,$mergedAt >> ../$csv.tmp
done <../$list
cd ..
sort $csv.tmp > $csv
rm $csv.tmp $list
done