2

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:");
}
2
  • I survey Gerrit REST API find Revision Endpoints API can get commit message, but i use RevisionApi not find any method or variable can get message. ChangeApi ccapi = gerritApi.changes() .id("PROJECTBASE~BCX10A51~I031e50eb06c10638b914abb7a5d4‌​31e49b19abb8"); RevisionApi rr = ccapi.revision("031e50eb06c10638b914abb7a5d431e49b19abb8"); Commented Jun 16, 2017 at 10:10
  • You have to use GerritApi as ~gerritApi.changes().query("query").get();~ passing the query, for commitMessage, form the query as documented here - gerrit-review.googlesource.com/Documentation/… Commented May 25, 2022 at 14:18

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response, I know use Get Commit can get the commit message, so i use the RevisionApi class try to get the commit message, But RevisionApi sourcecode i don't see any about commit message method or variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.