-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl-graph.sh
executable file
·87 lines (68 loc) · 2.69 KB
/
cl-graph.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
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
if [ "$#" != "1" ]; then
echo "usage: $(basename $0) <gerrit hashtag>" > /dev/stderr
exit 1
fi;
hashtag=${1}
tempdir=$(mktemp -dt "cl-graph-${hashtag}-XXXXXXXX")
changes_json_file="$tempdir/changes.json"
# download list of CLs for the hashtag
curl -s "https://android-review.googlesource.com/changes/?q=hashtag:%22${hashtag}%22&o=SUBMIT_REQUIREMENTS" | tail -n -1 > "${changes_json_file}"
# extract CL numbers
numbers=$(<"${changes_json_file}" jq -r .[]._number)
bubble_width=30
declare -A topic_commits;
echo "digraph \"$hashtag\" {"
# download info on each CL
for number in $numbers; do
commit_json_file="$tempdir/commit-${number}.json"
curl -s "https://android-review.googlesource.com/changes/${number}/revisions/current/commit" | tail -n -1 > ${commit_json_file}
done
# process CL parents and topics
for number in $numbers; do
commit_json_file="$tempdir/commit-${number}.json"
topic=$(<"${changes_json_file}" jq -r ".[] | select(._number == $number).topic")
subject=$(<${commit_json_file} jq -r .subject | fold -s -w $bubble_width | sed -z -r 's/\n/\\n/g')
commit=$(<${commit_json_file} jq -r .commit)
# label CL
echo "\"$commit\" [label=\"$subject\"];"
# find status
status=$(<"${changes_json_file}" jq -r ".[] | select(._number == $number).status")
if [ "$status" == "MERGED" ]; then
# mark merged blue
echo "\"$commit\" [fillcolor=\"lightblue\" style=\"filled\"];"
else
# count failing checks
failing_checks=$(<"${changes_json_file}" jq -r ".[] | select(._number == $number).submit_requirements | map(.submittability_expression_result.status | select(. == \"FAIL\")) | length")
# mark ready-to-submit green
if [ "$failing_checks" == "0" ]; then
echo "\"$commit\" [fillcolor=\"lightgreen\" style=\"filled\"];"
elif [ "$failing_checks" == "1" ]; then
echo "\"$commit\" [fillcolor=\"lightyellow\" style=\"filled\"];"
fi
fi
# assign CL to topic
if [ "$topic" != "null" ]; then
topic_commits["$topic"]+="\"$commit\";"
fi
# link CL to parent commits
parents=$(<${commit_json_file} tail -n -1 | jq -r .parents[].commit)
for parent in $parents; do
# if parent is one of topic's commits, name it, else say project@HEAD
if cat "$tempdir"/commit-*.json | jq -e -r "select(.commit == \"$parent\")" >/dev/null; then
echo "\"$commit\" -> \"$parent\";"
else
project=$(<${changes_json_file} jq -r ".[] | select(._number == $number).project")
echo "\"$commit\" -> \"${project}@HEAD\";"
echo "\"${project}@HEAD\" [fillcolor=\"lightblue\" style=\"filled\"];"
fi
done
done
# emit topic clusters
for topic in ${!topic_commits[@]}; do
echo "subgraph \"cluster_topic:$topic\" {"
echo "label=\"topic:$topic\";"
echo "${topic_commits[$topic]}"
echo "}"
done
echo "}"