Paul Sokolovsky | 3c98fe0 | 2023-07-02 12:42:59 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | set -ex |
| 8 | |
| 9 | # Set to 0 to temporarily disable posting comments to Gerrit. |
| 10 | should_post_comment=1 |
| 11 | |
| 12 | # Directory where this script resides. |
| 13 | SCRIPT_DIR="$(cd "$(dirname "$0")" ; echo "${PWD}")" |
| 14 | |
| 15 | # Don't post comments if run on the staging server. |
Saheer Babu | 7ff113c | 2024-12-19 00:42:45 +0000 | [diff] [blame] | 16 | if echo "$JENKINS_PUBLIC_URL" | grep -q "ci\.staging"; then |
Paul Sokolovsky | 3c98fe0 | 2023-07-02 12:42:59 +0300 | [diff] [blame] | 17 | should_post_comment=0 |
| 18 | fi |
| 19 | |
| 20 | # Always enable posting comments to sandbox (test) projects, even if they're |
| 21 | # disabled above. |
| 22 | if echo "${GERRIT_PROJECT}" | grep -q sandbox; then |
| 23 | should_post_comment=1 |
| 24 | fi |
| 25 | |
| 26 | # If run without a patch (e.g. for debugging, don't try to post comment. |
| 27 | if [ -z "$GERRIT_CHANGE_NUMBER" ]; then |
| 28 | should_post_comment=0 |
| 29 | fi |
| 30 | |
| 31 | if [ $should_post_comment -eq 1 ]; then |
| 32 | mkdir -p ~/.ssh/ |
| 33 | ssh-keyscan -H -p 29418 $GERRIT_HOST >> ~/.ssh/known_hosts |
| 34 | |
| 35 | quoted="$(python3 $SCRIPT_DIR/prepare_gerrit_comment.py misra_delta.txt)" |
| 36 | |
| 37 | ssh -o "PubkeyAcceptedKeyTypes +ssh-rsa" -p 29418 -i "$CI_BOT_KEY" "$CI_BOT_USERNAME@$GERRIT_HOST" gerrit \ |
| 38 | review "$GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER" \ |
| 39 | --message "$quoted" |
| 40 | fi |