use of com.google.copybara.git.gerritapi.GerritApi 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.GerritApi in project copybara by google.
the class GerritEndpoint method deleteVote.
@StarlarkMethod(name = "delete_vote", doc = "Delete a label vote from an account owner on a Gerrit change.\n", parameters = { @Param(name = "change_id", named = true, doc = "The Gerrit change id."), @Param(name = "account_id", named = true, doc = "The account owner who votes on label_id. Use 'me' or 'self' " + "if the account owner makes this api call"), @Param(name = "label_id", named = true, doc = "The name of the label.") })
public void deleteVote(String changeId, String accountId, String labelId) throws EvalException {
try {
GerritApi gerritApi = apiSupplier.load(console);
gerritApi.deleteVote(changeId, accountId, labelId, new DeleteVoteInput(NotifyType.NONE));
} catch (RepoException | ValidationException | RuntimeException e) {
throw new EvalException("Error calling delete_vote: " + e.getMessage(), e);
}
}
Aggregations