Search in sources :

Example 11 with ProjectControl

use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.

the class ListGroups method getAllGroups.

private List<GroupInfo> getAllGroups() throws OrmException {
    List<GroupInfo> groupInfos;
    List<AccountGroup> groupList;
    if (!projects.isEmpty()) {
        Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
        for (final ProjectControl projectControl : projects) {
            final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
            for (final GroupReference groupRef : groupsRefs) {
                final AccountGroup group = groupCache.get(groupRef.getUUID());
                if (group != null) {
                    groups.put(group.getGroupUUID(), group);
                }
            }
        }
        groupList = filterGroups(groups.values());
    } else {
        groupList = filterGroups(groupCache.all());
    }
    groupInfos = Lists.newArrayListWithCapacity(groupList.size());
    int found = 0;
    int foundIndex = 0;
    for (AccountGroup group : groupList) {
        if (foundIndex++ < start) {
            continue;
        }
        if (limit > 0 && ++found > limit) {
            break;
        }
        groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
    }
    return groupInfos;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.common.data.GroupReference) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 12 with ProjectControl

use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.

the class ReviewCommand method parseCommandLine.

@Override
protected void parseCommandLine() throws UnloggedFailure {
    optionList = new ArrayList<>();
    customLabels = new HashMap<>();
    ProjectControl allProjectsControl;
    try {
        allProjectsControl = projectControlFactory.controlFor(allProjects);
    } catch (NoSuchProjectException e) {
        throw die("missing " + allProjects.get());
    }
    for (LabelType type : allProjectsControl.getLabelTypes().getLabelTypes()) {
        StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
        for (LabelValue v : type.getValues()) {
            usage.append(v.format()).append("\n");
        }
        final String name = "--" + type.getName().toLowerCase();
        optionList.add(new ApproveOption(name, usage.toString(), type));
    }
    super.parseCommandLine();
}
Also used : LabelValue(com.google.gerrit.common.data.LabelValue) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) LabelType(com.google.gerrit.common.data.LabelType) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 13 with ProjectControl

use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.

the class LsUserRefs method run.

@Override
protected void run() throws Failure {
    Account userAccount;
    try {
        userAccount = accountResolver.find(db, userName);
    } catch (OrmException e) {
        throw die(e);
    }
    if (userAccount == null) {
        stdout.print("No single user could be found when searching for: " + userName + '\n');
        stdout.flush();
        return;
    }
    IdentifiedUser user = userFactory.create(userAccount.getId());
    ProjectControl userProjectControl = projectControl.forUser(user);
    try (Repository repo = repoManager.openRepository(userProjectControl.getProject().getNameKey())) {
        try {
            Map<String, Ref> refsMap = new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo, userProjectControl, db, true).filter(repo.getRefDatabase().getRefs(ALL), false);
            for (final String ref : refsMap.keySet()) {
                if (!onlyRefsHeads || ref.startsWith(RefNames.REFS_HEADS)) {
                    stdout.println(ref);
                }
            }
        } catch (IOException e) {
            throw new Failure(1, "fatal: Error reading refs: '" + projectControl.getProject().getNameKey(), e);
        }
    } catch (RepositoryNotFoundException e) {
        throw die("'" + projectControl.getProject().getNameKey() + "': not a git archive");
    } catch (IOException e) {
        throw die("Error opening: '" + projectControl.getProject().getNameKey());
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) OrmException(com.google.gwtorm.server.OrmException) VisibleRefFilter(com.google.gerrit.server.git.VisibleRefFilter) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 14 with ProjectControl

use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.

the class RelatedChangesSorter method sort.

public List<PatchSetData> sort(List<ChangeData> in, PatchSet startPs) throws OrmException, IOException {
    checkArgument(!in.isEmpty(), "Input may not be empty");
    // Map of all patch sets, keyed by commit SHA-1.
    Map<String, PatchSetData> byId = collectById(in);
    PatchSetData start = byId.get(startPs.getRevision().get());
    checkArgument(start != null, "%s not found in %s", startPs, in);
    ProjectControl ctl = start.data().changeControl().getProjectControl();
    // Map of patch set -> immediate parent.
    ListMultimap<PatchSetData, PatchSetData> parents = MultimapBuilder.hashKeys(in.size()).arrayListValues(3).build();
    // Map of patch set -> immediate children.
    ListMultimap<PatchSetData, PatchSetData> children = MultimapBuilder.hashKeys(in.size()).arrayListValues(3).build();
    // All other patch sets of the same change as startPs.
    List<PatchSetData> otherPatchSetsOfStart = new ArrayList<>();
    for (ChangeData cd : in) {
        for (PatchSet ps : cd.patchSets()) {
            PatchSetData thisPsd = checkNotNull(byId.get(ps.getRevision().get()));
            if (cd.getId().equals(start.id()) && !ps.getId().equals(start.psId())) {
                otherPatchSetsOfStart.add(thisPsd);
            }
            for (RevCommit p : thisPsd.commit().getParents()) {
                PatchSetData parentPsd = byId.get(p.name());
                if (parentPsd != null) {
                    parents.put(thisPsd, parentPsd);
                    children.put(parentPsd, thisPsd);
                }
            }
        }
    }
    Collection<PatchSetData> ancestors = walkAncestors(ctl, parents, start);
    List<PatchSetData> descendants = walkDescendants(ctl, children, start, otherPatchSetsOfStart, ancestors);
    List<PatchSetData> result = new ArrayList<>(ancestors.size() + descendants.size() - 1);
    result.addAll(Lists.reverse(descendants));
    result.addAll(ancestors);
    return result;
}
Also used : ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ProjectControl(com.google.gerrit.server.project.ProjectControl) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 15 with ProjectControl

use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.

the class Revert method applyImpl.

@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, ChangeResource req, RevertInput input) throws IOException, OrmException, RestApiException, UpdateException, NoSuchChangeException {
    RefControl refControl = req.getControl().getRefControl();
    ProjectControl projectControl = req.getControl().getProjectControl();
    Capable capable = projectControl.canPushToAtLeastOneRef();
    if (capable != Capable.OK) {
        throw new AuthException(capable.getMessage());
    }
    Change change = req.getChange();
    if (!refControl.canUpload()) {
        throw new AuthException("revert not permitted");
    } else if (change.getStatus() != Status.MERGED) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    }
    Change.Id revertedChangeId = revert(updateFactory, req.getControl(), Strings.emptyToNull(input.message));
    return json.noOptions().format(req.getProject(), revertedChangeId);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Capable(com.google.gerrit.common.data.Capable) RefControl(com.google.gerrit.server.project.RefControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.reviewdb.client.Change) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Aggregations

ProjectControl (com.google.gerrit.server.project.ProjectControl)16 AuthException (com.google.gerrit.extensions.restapi.AuthException)5 Project (com.google.gerrit.reviewdb.client.Project)5 Capable (com.google.gerrit.common.data.Capable)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Change (com.google.gerrit.reviewdb.client.Change)4 RefControl (com.google.gerrit.server.project.RefControl)4 ArrayList (java.util.ArrayList)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)3 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)3 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)3 ProjectState (com.google.gerrit.server.project.ProjectState)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 AccessSection (com.google.gerrit.common.data.AccessSection)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 IntegrationException (com.google.gerrit.server.git.IntegrationException)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 ChangeControl (com.google.gerrit.server.project.ChangeControl)2