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 | |
| 8 | gerrit_review_for_gerrit_topic() { |
| 9 | [ -z "$OUTPUT_DIR" ] && OUTPUT_DIR=$PWD/output |
| 10 | [ -z "$GERRIT_SERVER" ] && GERRIT_SERVER="scgit.amlogic.com" |
| 11 | [ -z "$GERRIT_PORT" ] && GERRIT_PORT="29418" |
| 12 | [ -z "$GERRIT_QUERY_RESULT" ] && GERRIT_QUERY_RESULT="$OUTPUT_DIR/topic_changes.txt" |
| 13 | |
| 14 | if [ -z "$MANUAL_GERRIT_TOPIC" ] || [ ! -f "$GERRIT_QUERY_RESULT" ]; then |
| 15 | return |
| 16 | fi |
| 17 | |
| 18 | if [ "$1" = "SUCCESS" ]; then |
| 19 | verify_score="+1" |
| 20 | elif [ "$1" = "FAIL" ]; then |
| 21 | verify_score="-1" |
| 22 | else |
| 23 | echo "gerrit_review_for_gerrit_topic: Invalid parameter $1" |
| 24 | return |
| 25 | fi |
| 26 | |
| 27 | review_msg="Build ${BUILD_URL}: $1" |
| 28 | |
| 29 | GERRIT_CHANGE_NUMBERS=$(jq -r '.number // empty' $GERRIT_QUERY_RESULT) |
| 30 | GERRIT_PATCHSET_NUMBERS=$(jq -r '.currentPatchSet.number // empty' $GERRIT_QUERY_RESULT) |
| 31 | |
| 32 | i=1 |
| 33 | for GERRIT_CHANGE_NUMBER in $GERRIT_CHANGE_NUMBERS; do |
| 34 | GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_PATCHSET_NUMBERS | awk "{print \$$i}") |
| 35 | echo -n "$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER $verify_score ... " |
| 36 | ssh -p $GERRIT_PORT $GERRIT_SERVER gerrit review --verified "${verify_score}" -m "'${review_msg}'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER |
| 37 | if [ "$?" -eq 0 ]; then |
| 38 | echo "OK" |
| 39 | else |
| 40 | echo "failed" |
| 41 | fi |
| 42 | i=$((i+1)) |
| 43 | done |
| 44 | |
| 45 | if [ "$1" = "FAIL" ]; then |
| 46 | exit 1 |
| 47 | fi |
| 48 | } |