Search in sources :

Example 1 with TagInfo

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

the class ListTags method createTagInfo.

public static TagInfo createTagInfo(PermissionBackend.ForRef perm, Ref ref, RevWalk rw) throws MissingObjectException, IOException {
    RevObject object = rw.parseAny(ref.getObjectId());
    boolean canDelete = perm.testOrFalse(RefPermission.DELETE);
    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(tag.getTaggerIdent()) : null, canDelete);
    }
    // Lightweight tag
    return new TagInfo(ref.getName(), ref.getObjectId().getName(), canDelete);
}
Also used : 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)

Example 2 with TagInfo

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

the class DeleteTagIT method assertDeleteSucceeds.

private void assertDeleteSucceeds() throws Exception {
    TagInfo tagInfo = tag().get();
    assertThat(tagInfo.canDelete).isTrue();
    String tagRev = tagInfo.revision;
    tag().delete();
    eventRecorder.assertRefUpdatedEvents(project.get(), TAG, null, tagRev, tagRev, null);
    assertThrows(ResourceNotFoundException.class, () -> tag().get());
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo)

Example 3 with TagInfo

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

the class GetBranchIT method getTagRef.

@Test
public void getTagRef() throws Exception {
    // create a tag
    TagInput input = new TagInput();
    input.message = "My Tag";
    input.revision = projectOperations.project(project).getHead("master").name();
    TagInfo tagInfo = gApi.projects().name(project.get()).tag("my-tag").create(input).get();
    // any user who can see the project, can see the tag
    requestScopeOperations.setApiUser(user.id());
    assertBranchFound(project, tagInfo.ref);
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with TagInfo

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

the class GetBranchIT method cannotGetTagRefThatPointsToNonVisibleBranch.

@Test
public void cannotGetTagRefThatPointsToNonVisibleBranch() throws Exception {
    // create a tag
    TagInput input = new TagInput();
    input.message = "My Tag";
    input.revision = projectOperations.project(project).getHead("master").name();
    TagInfo tagInfo = gApi.projects().name(project.get()).tag("my-tag").create(input).get();
    // block read access to the branch
    projectOperations.project(project).forUpdate().add(block(Permission.READ).ref(RefNames.fullName("master")).group(ANONYMOUS_USERS)).update();
    // if the user cannot see the project, the tag is not visible
    requestScopeOperations.setApiUser(user.id());
    assertBranchNotFound(project, tagInfo.ref);
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with TagInfo

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

the class TagsIT method createExistingTag.

@Test
public void createExistingTag() throws Exception {
    grantTagPermissions();
    TagInput input = new TagInput();
    input.ref = "test";
    TagInfo result = tag(input.ref).create(input).get();
    assertThat(result.ref).isEqualTo(R_TAGS + "test");
    input.ref = "refs/tags/test";
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> tag(input.ref).create(input));
    assertThat(thrown).hasMessageThat().contains("tag \"" + R_TAGS + "test\" already exists");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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