use of com.google.copybara.git.gerritapi.GetChangeInput in project copybara by google.
the class GerritOrigin method resolve.
@Override
public GitRevision resolve(@Nullable String reference) throws RepoException, ValidationException {
generalOptions.console().progress("Git Origin: Initializing local repo");
checkCondition(!Strings.isNullOrEmpty(reference), "Expecting a change number as reference");
GerritChange change = GerritChange.resolve(getRepository(), repoUrl, reference, this.generalOptions);
if (change == null) {
GitRevision gitRevision = GitRepoType.GIT.resolveRef(getRepository(), repoUrl, reference, this.generalOptions, describeVersion, partialFetch);
return describeVersion ? getRepository().addDescribeVersion(gitRevision) : gitRevision;
}
GerritApi api = gerritOptions.newGerritApi(repoUrl);
ChangeInfo response = api.getChange(Integer.toString(change.getChange()), new GetChangeInput(ImmutableSet.of(DETAILED_ACCOUNTS, DETAILED_LABELS)));
if (branch != null && !branch.equals(response.getBranch())) {
throw new EmptyChangeException(String.format("Skipping import of change %s for branch %s. Only tracking changes for branch %s", change.getChange(), response.getBranch(), branch));
}
ImmutableMultimap.Builder<String, String> labels = ImmutableMultimap.builder();
labels.put(GerritChange.GERRIT_CHANGE_BRANCH, response.getBranch());
if (response.getTopic() != null) {
labels.put(GerritChange.GERRIT_CHANGE_TOPIC, response.getTopic());
}
labels.put(GerritChange.GERRIT_COMPLETE_CHANGE_ID_LABEL, response.getId());
for (Entry<String, List<AccountInfo>> e : response.getReviewers().entrySet()) {
for (AccountInfo info : e.getValue()) {
if (info.getEmail() != null) {
labels.put("GERRIT_" + e.getKey() + "_EMAIL", info.getEmail());
}
}
}
if (response.getOwner().getEmail() != null) {
labels.put(GerritChange.GERRIT_OWNER_EMAIL_LABEL, response.getOwner().getEmail());
}
GitRevision gitRevision = change.fetch(labels.build());
return describeVersion ? getRepository().addDescribeVersion(gitRevision) : gitRevision;
}
Aggregations