diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh --- a/tools/tools/git/git-arc.sh +++ b/tools/tools/git/git-arc.sh @@ -155,6 +155,31 @@ exit 1 } +printf_color() +{ + local sgr + + color=$1 + shift + + case $color in + black) sgr="\033[30m" ;; + red) sgr="\033[31m" ;; + green) sgr="\033[32m" ;; + yellow) sgr="\033[33m" ;; + blue) sgr="\033[34m" ;; + magenta) sgr="\033[35m" ;; + cyan) sgr="\033[36m" ;; + white) sgr="\033[37m" ;; + *) sgr="\033[0m" ;; + esac + + printf "%b" "$sgr" + # shellcheck disable=SC2059 + printf "$@" + printf "\033[0m" +} + # Use xmktemp instead of mktemp when creating temporary files. xmktemp() { @@ -207,7 +232,7 @@ diff2status() { - local diff tmp status summary + local diff tmp phid status status_color status_name summary diff=$1 if ! expr "$diff" : 'D[1-9][0-9]*$' >/dev/null; then @@ -217,10 +242,20 @@ tmp=$(xmktemp) echo '{"names":["'"$diff"'"]}' | arc_call_conduit -- phid.lookup > "$tmp" - status=$(jq -r "select(.response != []) | .response.${diff}.status" < "$tmp") + phid=$(jq -r ".response[].phid" "$tmp") + if [ -z "$phid" ] || [ "$phid" = "null" ]; then + err "invalid Phabricator ID for ${diff}" + fi + + status=$(printf "%s" '{"constraints": {"phids": ["'"$phid"'"]}}' | \ + arc_call_conduit -- differential.revision.search | \ + jq -r '.response.data[0].fields.status') + status_name=$(echo "$status" | jq -r '.name') + status_color=$(echo "$status" | jq -r '."color.ansi"') summary=$(jq -r "select(.response != []) | .response.${diff}.fullName" < "$tmp") - printf "%-14s %s\n" "${status}" "${summary}" + printf_color "$status_color" "%-15s" "$status_name" + printf " %s\n" "$summary" } log2diff() @@ -472,7 +507,7 @@ awk -F'D[1-9][0-9]*: ' \ '{if ($2 == "'"$(echo $title | sed 's/"/\\"/g')"'") print $0}') if [ -z "$diff" ]; then - echo "No Review : $title" + echo "No Review : $title" elif [ "$(echo "$diff" | wc -l)" -ne 1 ]; then printf "%s" "Ambiguous Reviews: " echo "$diff" | grep -E -o 'D[1-9][0-9]*:' | tr -d ':' \