Search in sources :

Example 1 with AccountInfo

use of com.google.copybara.git.gerritapi.AccountInfo 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 AccountInfo (com.google.copybara.git.gerritapi.AccountInfo)1 ChangeInfo (com.google.copybara.git.gerritapi.ChangeInfo)1 GerritApi (com.google.copybara.git.gerritapi.GerritApi)1 GetChangeInput (com.google.copybara.git.gerritapi.GetChangeInput)1 List (java.util.List)1