How do I list all comments posted on my changes in gerrit?
Asked Answered
M

3

7

Here and there, colleague leaves a comment on my code changes which I post in gerrit. However to see them I have to:

  • click on the gerrit change in the list of changes. This link does not even indicate whether anything was commented
    image description
  • Then see a list of files and click on any that has something in the Comments column
    image description
  • Then I can read the comment

It would be much better to see a list of code fragments which have comments, sorted by time. That way, I wouldn't have to click all over my edit history.

How do I list all comments posted on my changes in gerrit?

Metamorphic answered 17/1, 2017 at 13:55 Comment(0)
F
5

You could try to use REST to retrive this kind of info.

1) To list all open changes created by you:

curl -s --request GET --netrc https://GERRIT-SERVER/a/changes/?q=owner:self+AND+status:open | sed 1d | jq --raw-output ".[] | ._number"

2) To list all comments (and their dates) on a change:

curl -s --request GET --netrc https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/comments | sed 1d | jq --raw-output ".[] | .[] | {Updated: .updated, Message: .message}"

Doing 1 + 2:

for c in $(curl -s --request GET --netrc https://GERRIT-SERVER/a/changes/?q=owner:self+AND+status:open | sed 1d | jq --raw-output ".[] | ._number")
do
    curl -s --request GET --netrc https://GERRIT-SERVER/a/changes/$c/comments | sed 1d | jq --raw-output ".[] | .[] | {Updated: .updated, Message: .message}"
done
Foolscap answered 17/1, 2017 at 17:44 Comment(3)
How is authentication handled in this case?Fortitude
In the examples I'm using the "--netrc" curl parameter to use the .netrc file for login name and password (see: man curl and man netrc for more details), but you can also use the "--user USER" and curl will prompt for your password or "--user USER:PASS" (unsecure).Grandstand
I ended up instead fetching these urls via javascript from an userscript. But they did work.Fortitude
T
3

It looks as if someone versions of gerrit, at least, will show you all the comments on the main review page. For example, take a look at this review. Look at the comments no patchset 20. In this gerrit instance, at least, all file comments will be listed here, along with links to he files and direct links to the individual comments. I don't know if this is stock Gerrit or if it has local modifications, but in the latter case they would be available publically somewhere.

You can get at the same information using the gerrit command line api. If your Gerrit host were review.openstack.org:29418, you could run:

ssh -p 29418 [email protected] gerrit query --comments --current-patch-set <changeid>

Where <changeid> is the Gerrit change-id or change number. This will show you all the comments, including inline comments from files, associated with the current patch set. You can replace --current-patch-set with --patch-sets to see this for all patch sets.

You can add --json to the query to get JSON output, which is useful if you would like to wrap this with some sort of script for pretty-fying the display.

Tressa answered 17/1, 2017 at 17:5 Comment(0)
D
1

If you want to retrieve only the contents of the comments you can use ssh with jq.

ssh -p 29418 [email protected] gerrit query --comments --current-patch-set <change_ID> --format=JSON | jq '.comments []? | .message'

or use jq -r to get the raw output without colors.

Disrobe answered 26/3, 2019 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.