Search in sources :

Example 1 with RefFilter

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

the class ListTags method apply.

@Override
public Response<ImmutableList<TagInfo>> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, RestApiException, PermissionBackendException {
    resource.getProjectState().checkStatePermitsRead();
    List<TagInfo> tags = new ArrayList<>();
    PermissionBackend.ForProject perm = permissionBackend.currentUser().project(resource.getNameKey());
    try (Repository repo = getRepository(resource.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        Collection<Ref> all = visibleTags(resource.getNameKey(), repo, repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
        for (Ref ref : all) {
            tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw, resource.getProjectState(), links));
        }
    }
    tags.sort(comparing(t -> t.ref));
    return Response.ok(new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags));
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RefPermission(com.google.gerrit.server.permissions.RefPermission) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IdString(com.google.gerrit.extensions.restapi.IdString) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) RevObject(org.eclipse.jgit.revwalk.RevObject) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTag(org.eclipse.jgit.revwalk.RevTag) ImmutableList(com.google.common.collect.ImmutableList) Comparator.comparing(java.util.Comparator.comparing) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) RefFilter(com.google.gerrit.server.project.RefFilter) Collection(java.util.Collection) RefFilterOptions(com.google.gerrit.server.permissions.PermissionBackend.RefFilterOptions) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) Option(org.kohsuke.args4j.Option) CommonConverters(com.google.gerrit.server.CommonConverters) Instant(java.time.Instant) WebLinks(com.google.gerrit.server.WebLinks) PersonIdent(org.eclipse.jgit.lib.PersonIdent) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) List(java.util.List) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ListRefsRequest(com.google.gerrit.extensions.api.projects.ProjectApi.ListRefsRequest) Ref(org.eclipse.jgit.lib.Ref) Project(com.google.gerrit.entities.Project) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) Repository(org.eclipse.jgit.lib.Repository) RefFilter(com.google.gerrit.server.project.RefFilter) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Project (com.google.gerrit.entities.Project)1 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)1 ListRefsRequest (com.google.gerrit.extensions.api.projects.ProjectApi.ListRefsRequest)1 TagInfo (com.google.gerrit.extensions.api.projects.TagInfo)1 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Response (com.google.gerrit.extensions.restapi.Response)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 RestReadView (com.google.gerrit.extensions.restapi.RestReadView)1 CommonConverters (com.google.gerrit.server.CommonConverters)1 WebLinks (com.google.gerrit.server.WebLinks)1 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 RefFilterOptions (com.google.gerrit.server.permissions.PermissionBackend.RefFilterOptions)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 RefPermission (com.google.gerrit.server.permissions.RefPermission)1 ProjectResource (com.google.gerrit.server.project.ProjectResource)1 ProjectState (com.google.gerrit.server.project.ProjectState)1