I've been trying to retrieve the generated commit ID from a reverted Gerrit change using https://github.com/uwolfer/gerrit-rest-java-client but haven't been able to find a way to do so.
One of the ways I've been trying to get this ID is trying to get access to the related changes list.
The REST API documentation shows that you can use a query to retrieve this list.
How can I retrieve this list using API calls?
Is there another way to retrieve this commit ID?
I want to use this to track reverts and be able to analyze possible impacts this revert has on the project.
Found a way to solve this issue. What I did was adding a "&o=MESSAGES" tag to the query to retrieve the full change history list where the revert message gives you the target commit ID.
I then transfer the Collection<> that is returned into a list so I can easily access all the messages.
Collection<ChangeMessageInfo> messageColl = gerritClient.changes().query("commit:<commitID>&o=MESSAGES").get().get(0).messages;
final List<ChangeMessageInfo> messageList = new ArrayList<>(messageColl);
The revert message is usually the last entry of the change history log.
List of tags that can be used in a similar manner can be found here. You need to scroll down a bit to find the tags.
UPDATE:
Found an even more effecient way of finding the reverted commits.
With the code below you are able to retrieve the body message below the subject on Gerrit which in turn enables the possibility to query the commit ID that is presented in that field.
List<String> revertedCommits = new ArrayList<>();
revertedCommits.add(<commitID>);
String revertedCommit = "unknown";
Map<String, RevisionInfo> revisionInfo = gerritClient.changes().query("commit:" + revertedCommits.get(revertedCommits.size() - 1) + "&o=CURRENT_REVISION&o=COMMIT_FOOTERS").get().get(0).revisions;
Pattern p = Pattern.compile(Pattern.quote("This reverts commit ") + "(.*?)" + Pattern.quote("."));
Matcher m = p.matcher(revisionInfo.values().iterator().next().commitWithFooters);
while (m.find()) {
revertedCommit = m.group(1);
}
This can then be iterated through to find all the reverts connected to the first commit.
Note that I use the "&o=CURRENT_REVISION" and "&o=COMMIT_FOOTERS" tags in the query to access this information. Without these tags, you only get an empty array.