Search in sources :

Example 1 with ChangeInfo

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;
}
Also used : GetChangeInput(com.google.copybara.git.gerritapi.GetChangeInput) ChangeInfo(com.google.copybara.git.gerritapi.ChangeInfo) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) GerritApi(com.google.copybara.git.gerritapi.GerritApi) AccountInfo(com.google.copybara.git.gerritapi.AccountInfo)

Example 2 with ChangeInfo

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);
    }
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) ChangeInfo(com.google.copybara.git.gerritapi.ChangeInfo) RepoException(com.google.copybara.exception.RepoException) EvalException(net.starlark.java.eval.EvalException) StarlarkMethod(net.starlark.java.annot.StarlarkMethod)

Aggregations

ChangeInfo (com.google.copybara.git.gerritapi.ChangeInfo)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 RepoException (com.google.copybara.exception.RepoException)1 ValidationException (com.google.copybara.exception.ValidationException)1 AccountInfo (com.google.copybara.git.gerritapi.AccountInfo)1 GerritApi (com.google.copybara.git.gerritapi.GerritApi)1 GetChangeInput (com.google.copybara.git.gerritapi.GetChangeInput)1 List (java.util.List)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1 EvalException (net.starlark.java.eval.EvalException)1