Gerrit Remote API

795 views
Skip to first unread message

Sascha Scholz

unread,
Jun 30, 2010, 9:44:52 AM6/30/10
to repo-d...@googlegroups.com
Hi,

is there a remote API available for Gerrit? I'm working on a Mylyn
connector that in the first iteration should simply list all open
Gerrit changes. Unfortunately, I couldn't find anything in the
documentation how to do that...

Sascha

Shawn Pearce

unread,
Jun 30, 2010, 10:23:25 AM6/30/10
to Sascha Scholz, repo-d...@googlegroups.com

Not exactly. However there is a JSON-RPC 2.0 interface over HTTP,
which is what the browser is actually using to render all content. If
you watch the browser showing All > Open with Firebug, you can see the
AJAX request it makes to list the changes, and then the response it
gets back from the server.

Since its Mylyn, you might be able to grab the gerrit source code and
look at the gerrit-reviewdb and gerrit-common projects. The first one
forms up most of the data entities that are serialized over the wire
as JSON-RPC (via the Gson library), and the second one has most of the
RPC service definitions. The endpoint name in the URL is the name of
the service class, the method name is uh, the method name.

The complex part is when you want to do authenticated operations for a
user. You'll need to get the user to authenticate (which is done in
at least 3 different ways), and then send their cookie and the
xsrfToken in the JSON-RPC payload. Getting that to work may be a bit
tricky. Right now IIRC the xsrfToken is just a copy of the cookie
value, but in a future version it will probably become a different
string.

Sascha Scholz

unread,
Jun 30, 2010, 12:41:48 PM6/30/10
to Shawn Pearce, repo-d...@googlegroups.com
Hi Shawn,

thanks for the fast reply, I'll try that out.

Sascha

Sascha Scholz

unread,
Nov 8, 2010, 4:17:26 PM11/8/10
to Shawn Pearce, repo-d...@googlegroups.com
Hi Shawn et al.,

> On Wed, Jun 30, 2010 at 4:23 PM, Shawn Pearce <s...@google.com> wrote:
>> Not exactly.  However there is a JSON-RPC 2.0 interface over HTTP,
>> which is what the browser is actually using to render all content.  If
>> you watch the browser showing All > Open with Firebug, you can see the
>> AJAX request it makes to list the changes, and then the response it
>> gets back from the server.
>>
>> Since its Mylyn, you might be able to grab the gerrit source code and
>> look at the gerrit-reviewdb and gerrit-common projects.  The first one
>> forms up most of the data entities that are serialized over the wire
>> as JSON-RPC (via the Gson library), and the second one has most of the
>> RPC service definitions.  The endpoint name in the URL is the name of
>> the service class, the method name is uh, the method name.

In the meantime we implemented a first prototype of the Mylyn Gerrit
connector [1]. Ok, actually we have two different prototypes provided
by different parties using slightly different approaches for the
JSON-RPC stuff... ;-)

1) using gwtjsonrpc and dependencies to gerrit-common and -reviewdb
implementation classes. This of course pulls some GWT dependencies in.
2) using a tailor-made JSON-RPC client and copying some model classes
from Gerrit (all o/r mapping annotations stripped out)

Either way, I'm not yet convinced of the solution because during
development we noticed that at least one RPC method had been changed
in an incompatible way (listOpenChanges if I remember correctly). The
open questions for me are:

- Are there already parts of the Gerrit JSON-RPC interface that are
declared stable/official API?
- I've heard that there are plans to move the Gerrit DB to a git based
format in future. Would that then be the preferred way to talk with a
Gerrit system from remote?
- Are there plans to create a Java library to talk to a remote Gerrit?
We'd love to use such a library if that would make life easier...
Maybe we could also work together on it? We need to build it anyway if
nothing's available and it probably makes sense to have it near to the
server code.

Regards,
Sascha

[1] http://git.eclipse.org/c/mylyn/org.eclipse.mylyn.reviews.git/

Shawn Pearce

unread,
Nov 8, 2010, 9:39:44 PM11/8/10
to Sascha Scholz, repo-d...@googlegroups.com
On Mon, Nov 8, 2010 at 13:17, Sascha Scholz <sascha...@gmail.com> wrote:
>
> - Are there already parts of the Gerrit JSON-RPC interface that are
> declared stable/official API?

No. :-(

We do try to avoid changing it in a breaking way, but sometimes its
unavoidable, like the listOpenChanges breakage when we moved to the
query syntax and a generic query API. Right now I'm not sure we can
promise a stable RPC API. Though we can try harder (see below)
because I know a number of people who use Eclipse would appreciate
having a task connector for Gerrit.

> - I've heard that there are plans to move the Gerrit DB to a git based
> format in future. Would that then be the preferred way to talk with a
> Gerrit system from remote?

Perhaps, yes. We're still kicking around the design but are going to
work on it more before the end of the year. It might be production
ready early 2011 Q1. Speaking native Git from a browser is freaking
hard, so we'll still have a JSON-RPC interface for the current web UI.
But external third party applications might be better off accessing
the Git data directly, and communicating by pushing/fetching the
relevant Git data.

If I think about it right, we should build this part of Gerrit as its
own stand-alone JAR, built on top of JGit only. Then Mylyn could
embed this part to read/write the Git metadata, and avoid the rest of
our dependency chain.

But we are talking about some major re-engineering of Gerrit to do
this (which is why it hasn't been done yet!). IMHO, its going to be
Gerrit 3.0 when it ships.

> - Are there plans to create a Java library to talk to a remote Gerrit?

No plans, no.

> We'd love to use such a library if that would make life easier...
> Maybe we could also work together on it? We need to build it anyway if
> nothing's available and it probably makes sense to have it near to the
> server code.

I'd be willing to host it in the gerrit repository if you provide
sensible changes to our Maven build. But I think long-term we should
be looking at the metadata in Git, and a common codereview metadata
library built on top of JGit. IMHO, the codereview metadata format
should be "the" way to define codereview data for Git projects, and
should be commonly implemented by any Git tools that want to support
peer-review.

But we're still pie-in-the-sky stage. Code works, email is just
bulls**t. I keep talking about this, but never show actual working
code. :-(

Ernst Sjöstrand

unread,
Nov 9, 2010, 4:29:34 PM11/9/10
to Shawn Pearce, Sascha Scholz, repo-d...@googlegroups.com
Hi,

I would say that the query command over ssh is a remote interface that's very usable for integration with Gerrit!


Regards
//Ernst Sjöstrand

Matthias Sohn

unread,
Nov 9, 2010, 5:20:01 PM11/9/10
to Ernst Sjöstrand, Shawn Pearce, Sascha Scholz, repo-d...@googlegroups.com
Am 9. November 2010 22:29 schrieb Ernst Sjöstrand <ern...@gmail.com>:
Hi,

I would say that the query command over ssh is a remote interface that's very usable for integration with Gerrit!


Looks like this way we can access all (or most) review meta-data, but is it possible
to also transfer the review comments (both those inlined in the sources and those in 
the review summary) in that way ? 

Another problem with that approach is that many corporate firewalls 
let http(s) pass but block ssh (that's also the case for us).

--
Matthias

Pat Notz

unread,
Nov 9, 2010, 5:41:36 PM11/9/10
to Matthias Sohn, Ernst Sjöstrand, Shawn Pearce, Sascha Scholz, repo-d...@googlegroups.com
2010/11/9 Matthias Sohn <matthi...@googlemail.com>:

> Am 9. November 2010 22:29 schrieb Ernst Sjöstrand <ern...@gmail.com>:
>>
>> Hi,
>> I would say that the query command over ssh is a remote interface that's
>> very usable for integration with Gerrit!
>> http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html
>
> Looks like this way we can access all (or most) review meta-data, but is it
> possible
> to also transfer the review comments (both those inlined in the sources and
> those in
> the review summary) in that way ?

Yes. You get the full database.

> Another problem with that approach is that many corporate firewalls
> let http(s) pass but block ssh (that's also the case for us).

You're using the same SSH server that is used to push commits into
Gerrit. So, if you can push to Gerrit you can use these query tools.

> --
> Matthias

Matthias Sohn

unread,
Nov 9, 2010, 6:00:26 PM11/9/10
to Pat Notz, Ernst Sjöstrand, Shawn Pearce, Sascha Scholz, repo-d...@googlegroups.com
2010/11/9 Pat Notz <pat...@gmail.com>

2010/11/9 Matthias Sohn <matthi...@googlemail.com>:
> Am 9. November 2010 22:29 schrieb Ernst Sjöstrand <ern...@gmail.com>:
>>
>> Hi,
>> I would say that the query command over ssh is a remote interface that's
>> very usable for integration with Gerrit!
>> http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html
>
> Looks like this way we can access all (or most) review meta-data, but is it
> possible
> to also transfer the review comments (both those inlined in the sources and
> those in
> the review summary) in that way ?

Yes.  You get the full database.

> Another problem with that approach is that many corporate firewalls
> let http(s) pass but block ssh (that's also the case for us).

You're using the same SSH server that is used to push commits into
Gerrit. So, if you can push to Gerrit you can use these query tools.

I understood that, but currently - due to our firewall policies - I have to physically 
switch to a different network to access Gerrit servers outside our intranet via ssh
and that's not really fun.

Instead I would like to be able push to Gerrit via http(s) over http proxy. Also JGit/EGit 
don't really support this yet, that's why we are working on that. Along that line I would
also like to access Gerrit using Gerrit Mylyn connector over http(s). 

--
Matthias

Shawn Pearce

unread,
Nov 9, 2010, 6:53:56 PM11/9/10
to Pat Notz, Matthias Sohn, Ernst Sjöstrand, Sascha Scholz, repo-d...@googlegroups.com
On Tue, Nov 9, 2010 at 14:41, Pat Notz <pat...@gmail.com> wrote:
> 2010/11/9 Matthias Sohn <matthi...@googlemail.com>:
>> Am 9. November 2010 22:29 schrieb Ernst Sjöstrand <ern...@gmail.com>:
>>>
>>> Hi,
>>> I would say that the query command over ssh is a remote interface that's
>>> very usable for integration with Gerrit!
>>> http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html
>>
>> Looks like this way we can access all (or most) review meta-data, but is it
>> possible
>> to also transfer the review comments (both those inlined in the sources and
>> those in
>> the review summary) in that way ?
>
> Yes.  You get the full database.

No, you don't. The gerrit query command doesn't supply the full
database. And it doesn't supply the comments either. I think you can
only get the approval scores.

Pat Notz

unread,
Nov 9, 2010, 7:20:26 PM11/9/10
to Shawn Pearce, Matthias Sohn, Ernst Sjöstrand, Sascha Scholz, repo-d...@googlegroups.com
2010/11/9 Shawn Pearce <s...@google.com>:

Ah, right. I was thinking of gsql

http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-gsql.html

I have some Python tools that analyze reviews and I forgot that I had
switched to raw gsql early on for this reason.

~ Pat

Mihai Rusu

unread,
Nov 10, 2010, 6:55:45 PM11/10/10
to Pat Notz, Matthias Sohn, Ernst Sjöstrand, Shawn Pearce, Sascha Scholz, repo-d...@googlegroups.com
On Tue, Nov 9, 2010 at 2:41 PM, Pat Notz <pat...@gmail.com> wrote:
> 2010/11/9 Matthias Sohn <matthi...@googlemail.com>:
>> Am 9. November 2010 22:29 schrieb Ernst Sjöstrand <ern...@gmail.com>:
>>>
>>> Hi,
>>> I would say that the query command over ssh is a remote interface that's
>>> very usable for integration with Gerrit!
>>> http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html
>>
>> Looks like this way we can access all (or most) review meta-data, but is it
>> possible
>> to also transfer the review comments (both those inlined in the sources and
>> those in
>> the review summary) in that way ?
>
> Yes.  You get the full database.

Not really, I love the SSH "gerrit query" command but I noticed
recently that it does not return the created time (for the change, the
time the first patch was uploaded) even tho there is such a field in
the db.

--
Mihai Rusu

Reply all
Reply to author
Forward
0 new messages