-
Notifications
You must be signed in to change notification settings - Fork 5
/
devstats
executable file
·150 lines (137 loc) · 5.38 KB
/
devstats
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
set -euo pipefail
SKIP_FETCH="${SKIP_FETCH:-}"
DEBUG="${DEBUG:-}"
NOSSH="${NOSSH:-}"
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"
FROM="2018-01-01"
TO=$(date "+%Y-%m-%d")
if [ "${1-}" = "-h" ] || [ "${1-}" = "--help" ]; then
echo "Usage $0 [YEAR-MONTH-DAY] [YEAR-MONTH-DAY]"
echo "This script will fetch all Flatcar-related repos to ${SCRIPTFOLDER/..} and"
echo "and show some dev stats."
echo "The dates consist of year, month, and day (e.g., 2021-01-01)."
echo "With only the start date given the time spans up to today."
echo "Without the start date the time starts from ${FROM}."
echo "Set NOSSH=1 as env var to clone the repos via https."
echo "Set SKIP_FETCH=1 as env var to skip the repo update."
echo "Set DEBUG=1 as env var to work on test data."
exit 1
fi
if [ "${1-}" != "" ]; then
FROM="${1}"
fi
if [ "${2-}" != "" ]; then
TO="${2}"
fi
# Excluded: flatcar/ignition flatcar/afterburn flatcar/ign-converter flatcar/grub
# (because they are upstream projects)
REPOS=(flatcar/scripts flatcar/coreos-overlay flatcar/portage-stable flatcar/flatcar-website
flatcar/init flatcar/flatcar-linux-update-operator flatcar/flatcar-build-scripts
flatcar/mantle flatcar/update-ssh-keys flatcar/container-linux-config-transpiler
flatcar/locksmith flatcar/bootengine flatcar/baselayout
flatcar/flatcar-packer-qemu flatcar/sysext-bakery
flatcar/flatcar-dev-util flatcar/torcx flatcar/update_engine flatcar/flatcar-terraform
flatcar/coreos-cloudinit flatcar/fleetlock flatcar/toolbox flatcar/seismograph
flatcar/updateservicectl flatcar/mayday
flatcar/nss-altfiles flatcar/sysroot-wrappers flatcar/shim
flatcar/fero flatcar/efunctions flatcar/chromite
flatcar/flatcar-release-mirror flatcar/sdnotify-proxy
flatcar/flog flatcar/ue-rs kinvolk/nebraska)
OUTPUT=""
if [ "${DEBUG}" = "1" ]; then
OUTPUT="4 Some Body <somebody@microsoft.com>
3 Other Person <op@external.com>
7 Some Body <sb@users.noreply.github.com>
2 Another One <ao@kinvolk.io>"
fi
declare -A COUNTER
declare -A EMAILS
declare -A TO_REPOS
for REPO in "${REPOS[@]}"; do
NAME=$(echo "${REPO}" | cut -d / -f 2)
if [ "${DEBUG}" != "1" ]; then
FOLDER="${SCRIPTFOLDER}/../${NAME}"
if [ ! -d "${FOLDER}" ]; then
echo "Cloning ${REPO} in ${FOLDER}"
cd "${SCRIPTFOLDER}/.."
URL="git@github.com:${REPO}.git"
if [ "${NOSSH}" = "1" ]; then
URL="https://github.com/${REPO}.git"
fi
git clone --recurse-submodules "${URL}" > /dev/null 2> /dev/null || { echo "Cloning failed, try again with NOSSH=1" >&2 ; exit 1 ;}
cd -
else
if [ "${SKIP_FETCH}" != "1" ]; then
echo "Fetching ${REPO} in ${FOLDER}"
git -C "${FOLDER}" fetch origin > /dev/null 2> /dev/null
fi
fi
REF="origin/main"
if ! git -C "${FOLDER}" show "${REF}" > /dev/null 2> /dev/null; then
REF="origin/flatcar-master"
fi
if ! git -C "${FOLDER}" show "${REF}" > /dev/null 2> /dev/null; then
REF="origin/master"
fi
if ! git -C "${FOLDER}" show "${REF}" > /dev/null 2> /dev/null; then
REF="origin/trunk"
fi
# Trim left space, use space not tabs, and ignore bots
OUTPUT=$(git -C "${FOLDER}" shortlog -sne --since="${FROM}" --until="${TO}" "${REF}" | sed 's/^[ ]*//g' | tr '\t' ' ' | { grep -v -P '(flatcar-ci|Buildbot|dependabot|jenkins@localhost)' || true ; })
fi
while IFS= read -r line; do
if [ "${line}" != "" ]; then
# Format is "COUNT NAME SURNAME <EMAIL>"
COUNT=$(echo "${line}" | cut -d " " -f 1)
AUTHOR=$(echo "${line}" | cut -d " " -f 2- | cut -d "<" -f 1)
# Trim left and right space
AUTHOR=$(echo "${AUTHOR}" | sed 's/^[ ]*//g' | sed 's/[ ]*$//g')
EMAIL=$(echo "${line}" | cut -d " " -f 2- | cut -d "<" -f 2 | cut -d ">" -f 1)
# Workarounds for a few names
if [ "${AUTHOR}" = "yolossn" ] || [ "${AUTHOR}" = "Santhosh Nagaraj S" ]; then
AUTHOR="S Santhosh Nagaraj"
fi
if [ "${AUTHOR}" = "Kai Lüke" ]; then
AUTHOR="Kai Lueke"
fi
if [ "${AUTHOR}" = "william light" ]; then
AUTHOR="William Light"
fi
if [ "${AUTHOR}" = "ashu8912" ]; then
AUTHOR="Ashu Ghildiyal"
fi
if [ "${AUTHOR}" = "Iago López Galeiras" ]; then
AUTHOR="Iago Lopez Galeiras"
fi
if [ "${AUTHOR}" = "krnowak" ]; then
AUTHOR="Krzesimir Nowak"
fi
PREV_COUNT="${COUNTER["${AUTHOR}"]-0}"
COUNTER["${AUTHOR}"]=$((COUNT + PREV_COUNT))
PREV_EMAILS="${EMAILS["${AUTHOR}"]-}"
if ! echo "${PREV_EMAILS}" | grep -q "${EMAIL}"; then
EMAILS["${AUTHOR}"]=$(echo "${PREV_EMAILS} ${EMAIL}" | sed 's/^[ ]*//g')
fi
PREV_TO_REPOS="${TO_REPOS["${AUTHOR}"]-}"
if ! echo "${PREV_TO_REPOS}" | grep -q "${NAME}"; then
TO_REPOS["${AUTHOR}"]=$(echo "${PREV_TO_REPOS} ${NAME}" | sed 's/^[ ]*//g')
fi
fi
done <<< "${OUTPUT}"
done
STATS=$(for AUTHOR in "${!COUNTER[@]}"; do
echo "${COUNTER["${AUTHOR}"]} ${AUTHOR} <${EMAILS["${AUTHOR}"]-}> (${TO_REPOS["${AUTHOR}"]})"
done | sort -n -r)
PATTERN="(microsoft|kinvolk)"
echo
echo "Commits from ${FROM} to ${TO} in"
echo " ${REPOS[*]}" | sed 's#flatcar/##g' | fmt
echo
echo "Kinvolk/Microsoft:"
echo "${STATS}" | grep -P "${PATTERN}"
echo
echo "Non-Kinvolk/Microsoft:"
echo "${STATS}" | grep -v -P "${PATTERN}"
echo
echo "Total commits: $(($(echo "${COUNTER[@]}" | tr -s '[:blank:]' '+')))"