Kent Lu
Kent Lu

Reputation: 211

How to get commitMessage from gerrit REST API use JAVA

I want to use java connect Gerrit REST API, so i find the opensource gerrit-rest-java-client. But i don't know how to query the changes commitMessage.

My simple code is as follows

GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritAuthData.Basic authData = new GerritAuthData.Basic("Gerrit", "User", "password");

GerritApi gerritApi = gerritRestApiFactory.create(authData);

List<ChangeInfo> changes = gerritApi.changes().query("status:merged").withLimit(1).get();

for (ChangeInfo cc : changes) {
    System.out.println("subject:" + cc.subject);
    System.out.println("changeId:" + cc.changeId);
    System.out.println("commitMessage:");
}

Upvotes: 2

Views: 2513

Answers (1)

You need to query changes adding the "&o=CURRENT_REVISION" to get commit SHA-1 of the current revision (see more details here). Then you need to use the Get Commit endpoint to finally get the commit message.

Upvotes: 2

Related Questions