REST API to get Patch Set Approvals

93 views
Skip to first unread message

Rafael Lima

unread,
Apr 1, 2021, 4:03:33 PM4/1/21
to Repo and Gerrit Discussion
Hi all, 

I've been looking for a REST API to get patch set approvals for a given change. 

An API that could return something like this for a given change: 
patch_set_id, value, account_id, category_id 
(very similar to what Gerrit has on patch_set_approvals table).

Already read the REST API documentation for different Gerrit versions and couldn't find any. 

Am I missing anything?

I'm currently using Gerrit 2.14 but looking for a REST that could still be used after upgrading Gerrit to newer versions.

Thanks!

Rafael Lima



Han-Wen Nienhuys

unread,
Apr 6, 2021, 4:19:42 AM4/6/21
to Rafael Lima, Repo and Gerrit Discussion
have you tried the o=LABELS option,

)]}'
{
..
  "labels": {
    "Verified": {
      "approved": {
        "_account_id": 1022687
      }
    },
    "Code-Review": {},
    "Code-Style": {
      "approved": {
        "_account_id": 1022687
      }
    }
  },

--
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Rafael Lima

unread,
Apr 6, 2021, 4:06:13 PM4/6/21
to Repo and Gerrit Discussion
Hi Han-Wen, thanks for answering.

For my understanding labels holds only the latest vote for each reviewer.
I'm looking for a way to get the history of votes for all patch sets of a given change.

One solution I've found was: 
1. Call changes/{{GERRIT_CHANGE_ID}}?o=ALL_REVISIONS
2. Call changes/{{GERRIT_CHANGE_ID}}/revisions/{{GERRIT_REVISION_ID}}/reviewers/{{GERRIT_ACCOUNT_ID}}/votes/

But looks like it will take a long time to process all changes into the full Gerrit history because every change has N revisions and M accounts. 

Second option would be to parse the messages returned by the changes API: 
"messages": [
{
"id": "1461eab7_691aa2b9",
"date": "2021-04-06 17:14:34.000000000",
"message": "Patch Set 2: Code-Review-1",
"_revision_number": 2
},
...

But sounds like running in circles since we have all this information on the patch_set_approvals table.

Thanks,

Rafael

Han-Wen Nienhuys

unread,
Apr 7, 2021, 4:33:36 AM4/7/21
to Rafael Lima, Repo and Gerrit Discussion
On Tue, Apr 6, 2021 at 10:06 PM Rafael Lima <rac...@gmail.com> wrote:
Hi Han-Wen, thanks for answering.

For my understanding labels holds only the latest vote for each reviewer.
I'm looking for a way to get the history of votes for all patch sets of a given change.

One solution I've found was: 
1. Call changes/{{GERRIT_CHANGE_ID}}?o=ALL_REVISIONS
2. Call changes/{{GERRIT_CHANGE_ID}}/revisions/{{GERRIT_REVISION_ID}}/reviewers/{{GERRIT_ACCOUNT_ID}}/votes/

But looks like it will take a long time to process all changes into the full Gerrit history because every change has N revisions and M accounts. 

Second option would be to parse the messages returned by the changes API: 
"messages": [
{
"id": "1461eab7_691aa2b9",
"date": "2021-04-06 17:14:34.000000000",
"message": "Patch Set 2: Code-Review-1",
"_revision_number": 2
},
...

But sounds like running in circles since we have all this information on the patch_set_approvals table.

Newer Gerrit versions don't have this table (or any table), so that's not going to help you.  

The 3.4 release has a feature that will let you walk the history of a change (/meta_diff), which would let you reconstruct this information. Alternately, with NoteDb, you could inspect the git history.

 
--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/2615dd1f-6af5-4b67-868f-012b90bc1893n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages