This script works:
!#/bin/bash
gerrit_query_output=$(ssh -p 29418 my_review-server.com gerrit query --format=JSON --commit-message change:66664 | head -n 1)
commit_message=$(echo $gerrit_query_output | python -c "import sys, json; print json.load(sys.stdin)['commitMessage']" | grep -v ^Change-Id:)
echo "commit msg= $commit_message"
Is there an option in gerrit query command to print only first line so I can avoid | head -n 1
in line 2? json parsing in python fails if gerrit_query_output gets {"type":"stats","rowCount":1,"runTimeMilliseconds":9,"moreChanges":false}
as second line.
Is there a better way to get commitMessage without Change-Id:
line, so I can avoid | grep -v ^Change-Id:
1) Use "jq" instead of phthon to get the commit message:
ssh -p 29418 GERRIT-SERVER gerrit query --format=JSON --commit-message change:CHANGE-NUMBER | jq -r --raw-output '.commitMessage // empty'
2) There's no way to do that.