Search in sources :

Example 11 with TagInfo

use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.

the class ListTags method apply.

@Override
public List<TagInfo> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, BadRequestException {
    List<TagInfo> tags = new ArrayList<>();
    PermissionBackend.ForProject perm = permissionBackend.user(user).project(resource.getNameKey());
    try (Repository repo = getRepository(resource.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        ProjectControl pctl = resource.getControl();
        Map<String, Ref> all = visibleTags(pctl, repo, repo.getRefDatabase().getRefs(Constants.R_TAGS));
        for (Ref ref : all.values()) {
            tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw));
        }
    }
    Collections.sort(tags, new Comparator<TagInfo>() {

        @Override
        public int compare(TagInfo a, TagInfo b) {
            return a.ref.compareTo(b.ref);
        }
    });
    return new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags);
}
Also used : PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) ArrayList(java.util.ArrayList) IdString(com.google.gerrit.extensions.restapi.IdString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo)

Example 12 with TagInfo

use of com.google.gerrit.extensions.api.projects.TagInfo 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)

Example 13 with TagInfo

use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.

the class ListTags method createTagInfo.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
public static TagInfo createTagInfo(PermissionBackend.ForRef perm, Ref ref, RevWalk rw, ProjectState projectState, WebLinks links) throws IOException {
    RevObject object = rw.parseAny(ref.getObjectId());
    Boolean canDelete = null;
    if (!isConfigRef(ref.getName())) {
        // Never allow to delete the meta config branch.
        canDelete = perm.testOrFalse(RefPermission.DELETE) && projectState.statePermitsWrite() ? true : null;
    }
    ImmutableList<WebLinkInfo> webLinks = links.getTagLinks(projectState.getName(), ref.getName());
    if (object instanceof RevTag) {
        // Annotated or signed tag
        RevTag tag = (RevTag) object;
        PersonIdent tagger = tag.getTaggerIdent();
        return new TagInfo(ref.getName(), tag.getName(), tag.getObject().getName(), tag.getFullMessage().trim(), tagger != null ? CommonConverters.toGitPerson(tagger) : null, canDelete, webLinks.isEmpty() ? null : webLinks, tagger != null ? tagger.getWhen().toInstant() : null);
    }
    Instant timestamp = object instanceof RevCommit ? ((RevCommit) object).getCommitterIdent().getWhen().toInstant() : null;
    // Lightweight tag
    return new TagInfo(ref.getName(), ref.getObjectId().getName(), canDelete, webLinks.isEmpty() ? null : webLinks, timestamp);
}
Also used : WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) RevTag(org.eclipse.jgit.revwalk.RevTag) RevObject(org.eclipse.jgit.revwalk.RevObject) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) Instant(java.time.Instant) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 14 with TagInfo

use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.

the class TagsIT method annotatedTag.

@Test
public void annotatedTag() throws Exception {
    grantTagPermissions();
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
    PushOneCommit.Result r = push.to("refs/heads/master");
    r.assertOkStatus();
    TagInput input = new TagInput();
    input.ref = "v1.0";
    input.revision = r.getCommit().getName();
    input.message = "annotation message";
    TagInfo result = tag(input.ref).create(input).get();
    assertThat(result.ref).isEqualTo(R_TAGS + input.ref);
    assertThat(result.object).isEqualTo(input.revision);
    assertThat(result.message).isEqualTo(input.message);
    assertThat(result.tagger.name).isEqualTo(admin.fullName());
    assertThat(result.tagger.email).isEqualTo(admin.email());
    assertThat(result.created).isEqualTo(result.tagger.date);
    eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision);
    // A second tag pushed on the same ref should have the same ref
    TagInput input2 = new TagInput();
    input2.ref = "refs/tags/v2.0";
    input2.revision = input.revision;
    input2.message = "second annotation message";
    TagInfo result2 = tag(input2.ref).create(input2).get();
    assertThat(result2.ref).isEqualTo(input2.ref);
    assertThat(result2.object).isEqualTo(input2.revision);
    assertThat(result2.message).isEqualTo(input2.message);
    assertThat(result2.tagger.name).isEqualTo(admin.fullName());
    assertThat(result2.tagger.email).isEqualTo(admin.email());
    assertThat(result2.created).isEqualTo(result2.tagger.date);
    eventRecorder.assertRefUpdatedEvents(project.get(), result2.ref, null, result2.revision);
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with TagInfo

use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.

the class TagsIT method createTags.

private void createTags() throws Exception {
    grantTagPermissions();
    String revision = pushTo("refs/heads/master").getCommit().name();
    TagInput input = new TagInput();
    input.revision = revision;
    for (String tagname : testTags) {
        TagInfo result = tag(tagname).create(input).get();
        assertThat(result.revision).isEqualTo(input.revision);
        assertThat(result.ref).isEqualTo(R_TAGS + tagname);
    }
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput)

Aggregations

TagInfo (com.google.gerrit.extensions.api.projects.TagInfo)16 TagInput (com.google.gerrit.extensions.api.projects.TagInput)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 Test (org.junit.Test)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 RevObject (org.eclipse.jgit.revwalk.RevObject)3 RevTag (org.eclipse.jgit.revwalk.RevTag)3 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 ImmutableList (com.google.common.collect.ImmutableList)1 Project (com.google.gerrit.entities.Project)1 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)1