use of com.google.copybara.git.gerritapi.ChangeInfo 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;
}
use of com.google.copybara.git.gerritapi.ChangeInfo in project copybara by google.
the class GerritEndpoint method getChange.
@StarlarkMethod(name = "get_change", doc = "Retrieve a Gerrit change.", parameters = { @Param(name = "id", named = true, doc = "The change id or change number."), @Param(name = "include_results", named = true, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, doc = "" + "What to include in the response. See " + "https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html" + "#query-options", positional = false, defaultValue = "['LABELS']") })
public ChangeInfo getChange(String id, Sequence<?> includeResults) throws EvalException {
try {
ChangeInfo changeInfo = doGetChange(id, getIncludeResults(includeResults));
ValidationException.checkCondition(!changeInfo.isMoreChanges(), "Pagination is not supported yet.");
return changeInfo;
} catch (RepoException | ValidationException | RuntimeException e) {
throw new EvalException("Error getting change: " + e.getMessage(), e);
}
}
Aggregations