Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: MIT |
| 6 | # |
| 7 | |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 8 | # $1: Review result |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 9 | gerrit_review_for_gerrit_topic() { |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 10 | [ -z "$MANUAL_GERRIT_TOPIC" ] && return |
| 11 | |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 12 | [ -z "$OUTPUT_DIR" ] && OUTPUT_DIR=$PWD/output |
| 13 | [ -z "$GERRIT_SERVER" ] && GERRIT_SERVER="scgit.amlogic.com" |
| 14 | [ -z "$GERRIT_PORT" ] && GERRIT_PORT="29418" |
| 15 | [ -z "$GERRIT_QUERY_RESULT" ] && GERRIT_QUERY_RESULT="$OUTPUT_DIR/topic_changes.txt" |
| 16 | |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 17 | [ ! -f "$GERRIT_QUERY_RESULT" ] && echo "${FUNCNAME[0]}: No such file! $GERRIT_QUERY_RESULT" && exit 1 |
| 18 | [ $# -ne 1 ] && echo "${FUNCNAME[0]}: Invalid parameters! $*" && exit 1 |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 19 | |
Kelvin Zhang | 341ad7e | 2022-11-22 16:48:05 +0800 | [diff] [blame] | 20 | if [ "$1" = "Start" ]; then |
| 21 | verify_param="" |
Kelvin Zhang | 0d40565 | 2022-11-22 17:04:52 +0800 | [diff] [blame] | 22 | elif [ "$1" = "SUCCESS" ] || [ "$1" = "FAIL" ]; then |
| 23 | [ "$1" = "SUCCESS" ] && verify_score="+1" |
| 24 | [ "$1" = "FAIL" ] && verify_score="-1" |
Kelvin Zhang | 341ad7e | 2022-11-22 16:48:05 +0800 | [diff] [blame] | 25 | verify_param="--verified $verify_score" |
| 26 | echo -e "======== Verifying Gerrit Topic: $MANUAL_GERRIT_TOPIC ========" |
Kelvin Zhang | 0d40565 | 2022-11-22 17:04:52 +0800 | [diff] [blame] | 27 | else |
| 28 | echo "${FUNCNAME[0]}: Invalid parameter $1" && exit 1 |
Kelvin Zhang | 341ad7e | 2022-11-22 16:48:05 +0800 | [diff] [blame] | 29 | fi |
| 30 | |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 31 | review_msg="Build ${BUILD_URL}: $1" |
| 32 | |
| 33 | GERRIT_CHANGE_NUMBERS=$(jq -r '.number // empty' $GERRIT_QUERY_RESULT) |
| 34 | GERRIT_PATCHSET_NUMBERS=$(jq -r '.currentPatchSet.number // empty' $GERRIT_QUERY_RESULT) |
| 35 | |
| 36 | i=1 |
| 37 | for GERRIT_CHANGE_NUMBER in $GERRIT_CHANGE_NUMBERS; do |
| 38 | GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_PATCHSET_NUMBERS | awk "{print \$$i}") |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 39 | [ "$1" != "Start" ] && echo -n -e "$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER $verify_score ...\t" |
| 40 | ssh -p $GERRIT_PORT $GERRIT_SERVER gerrit review "${verify_param}" -m "'${review_msg}'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER |
| 41 | if [ "$1" != "Start" ]; then |
| 42 | if [ "$?" -eq 0 ]; then |
Kelvin Zhang | 341ad7e | 2022-11-22 16:48:05 +0800 | [diff] [blame] | 43 | echo "done" |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 44 | else |
| 45 | echo "failed" |
| 46 | fi |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 47 | fi |
| 48 | i=$((i+1)) |
| 49 | done |
| 50 | |
Kelvin Zhang | 341ad7e | 2022-11-22 16:48:05 +0800 | [diff] [blame] | 51 | if [ "$1" != "Start" ]; then |
| 52 | i=$((i-1)) |
| 53 | [ "$i" -eq 1 ] && echo -e "======== Verified $i Gerrit change for $MANUAL_GERRIT_TOPIC ========\n" |
| 54 | [ "$i" -gt 1 ] && echo -e "======== Verified $i Gerrit changes for $MANUAL_GERRIT_TOPIC ========\n" |
| 55 | fi |
Kelvin Zhang | cf64342 | 2022-11-22 15:28:31 +0800 | [diff] [blame] | 56 | |
Kelvin Zhang | d931bc3 | 2022-11-23 10:21:55 +0800 | [diff] [blame] | 57 | [ "$1" = "FAIL" ] && exit 1 |
| 58 | |
Kelvin Zhang | 5dfdeb3 | 2022-11-23 09:49:45 +0800 | [diff] [blame] | 59 | return 0 |
Kelvin Zhang | 461d2e1 | 2022-11-21 20:51:42 +0800 | [diff] [blame] | 60 | } |