Skip to content

Instantly share code, notes, and snippets.

@bogdando
Created November 30, 2020 13:52
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 bogdando/ed345b1f974c8e97edd33b61e7bf8158 to your computer and use it in GitHub Desktop.
Save bogdando/ed345b1f974c8e97edd33b61e7bf8158 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Fetch Zuul comments on failed builds for a patchset $1 and colorize it
#
set -eu
FROM=${FROM:-johndoe@review.opendev.org} # Insert HERE your gerrit ssh login
echo "Fetching CI results from $FROM for: $1"
out=$(mktemp /tmp/tmp.XXXXXXXXXX)
trap 'rm -f ${out}*' EXIT INT HUP
ssh -p 29418 $FROM gerrit query --comments --format=JSON \
--current-patch-set change:$1 > $out.all
jq -rc "\"\(.comments[]? |\
select((.reviewer.name == \"Zuul\") and \
(.message|test(\"Build failed\"))))\"" \
$out.all > $out.filtered
jq -rc '.timestamp' $out.filtered > $out.timestamps
jq -rc '.message' $out.filtered > $out.messages
i=0
while read -r l; do
if echo $l | grep -q "Build failed"; then
(( i = i + 1 ))
t=$(sed -n "${i}p" $out.timestamps)
echo $(date +"%Y-%m-%d %H:%M" -d@$t)
fi
echo $l | grep -q -e TIME -e FAIL -e SUCC -e SKIP -e ERR -e "Build failed" || continue
echo -e $l | grep -o 'Build failed.*\.' && continue
echo -e $l | awk '/TIME/ { print "\033[34m"$0"\033[0m";}'
echo -e $l | awk '/FAIL/ { print "\033[31m"$0"\033[0m";}'
echo -e $l | awk '/SUCC/ { print "\033[32m"$0"\033[0m";}'
echo -e $l | awk '/SKIP/ { print "\033[35m"$0"\033[0m";}'
echo -e $l | awk '/ERR/ { print "\033[33m"$0"\033[0m";}'
done < <(cat -- $out.messages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment