Search in sources :

Example 21 with TagInput

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

the class TagsIT method invalidBaseRevision.

@Test
public void invalidBaseRevision() throws Exception {
    grantTagPermissions();
    TagInput input = new TagInput();
    input.ref = "test";
    input.revision = "abcdefg";
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> tag(input.ref).create(input));
    assertThat(thrown).hasMessageThat().contains("Invalid base revision");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TagInput(com.google.gerrit.extensions.api.projects.TagInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 22 with TagInput

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

the class TagsIT method listTagsOfNonVisibleBranch.

@Test
public void listTagsOfNonVisibleBranch() throws Exception {
    grantTagPermissions();
    // Allow creating a new hidden branch
    projectOperations.project(project).forUpdate().add(allow(Permission.CREATE).group(REGISTERED_USERS).ref("refs/heads/hidden")).update();
    PushOneCommit push1 = pushFactory.create(admin.newIdent(), testRepo);
    PushOneCommit.Result r1 = push1.to("refs/heads/master");
    r1.assertOkStatus();
    TagInput tag1 = new TagInput();
    tag1.ref = "v1.0";
    tag1.revision = r1.getCommit().getName();
    TagInfo result = tag(tag1.ref).create(tag1).get();
    assertThat(result.ref).isEqualTo(R_TAGS + tag1.ref);
    assertThat(result.revision).isEqualTo(tag1.revision);
    pushTo("refs/heads/hidden").assertOkStatus();
    PushOneCommit push2 = pushFactory.create(admin.newIdent(), testRepo);
    PushOneCommit.Result r2 = push2.to("refs/heads/hidden");
    r2.assertOkStatus();
    TagInput tag2 = new TagInput();
    tag2.ref = "v2.0";
    tag2.revision = r2.getCommit().getName();
    result = tag(tag2.ref).create(tag2).get();
    assertThat(result.ref).isEqualTo(R_TAGS + tag2.ref);
    assertThat(result.revision).isEqualTo(tag2.revision);
    List<TagInfo> tags = getTags().get();
    assertThat(tags).hasSize(2);
    assertThat(tags.get(0).ref).isEqualTo(R_TAGS + tag1.ref);
    assertThat(tags.get(0).revision).isEqualTo(tag1.revision);
    assertThat(tags.get(1).ref).isEqualTo(R_TAGS + tag2.ref);
    assertThat(tags.get(1).revision).isEqualTo(tag2.revision);
    projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/hidden").group(REGISTERED_USERS)).update();
    tags = getTags().get();
    assertThat(tags).hasSize(1);
    assertThat(tags.get(0).ref).isEqualTo(R_TAGS + tag1.ref);
    assertThat(tags.get(0).revision).isEqualTo(tag1.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 23 with TagInput

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

the class TagsIT method createTagNotAllowed.

@Test
public void createTagNotAllowed() throws Exception {
    projectOperations.project(project).forUpdate().add(block(Permission.CREATE).ref(R_TAGS + "*").group(REGISTERED_USERS)).update();
    TagInput input = new TagInput();
    input.ref = "test";
    AuthException thrown = assertThrows(AuthException.class, () -> tag(input.ref).create(input));
    assertThat(thrown).hasMessageThat().contains("not permitted: create");
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) TagInput(com.google.gerrit.extensions.api.projects.TagInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

TagInput (com.google.gerrit.extensions.api.projects.TagInput)23 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20 Test (org.junit.Test)20 TagInfo (com.google.gerrit.extensions.api.projects.TagInfo)10 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 Result (com.google.gerrit.acceptance.PushOneCommit.Result)3 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 InvalidRevisionException (com.google.gerrit.server.project.RefUtil.InvalidRevisionException)2 IOException (java.io.IOException)2 Git (org.eclipse.jgit.api.Git)2 TagCommand (org.eclipse.jgit.api.TagCommand)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2