Search in sources :

Example 1 with BanResultInfo

use of com.google.gerrit.server.project.BanCommit.BanResultInfo in project gerrit by GerritCodeReview.

the class BanCommitIT method banCommit.

@Test
public void banCommit() throws Exception {
    RevCommit c = commitBuilder().add("a.txt", "some content").create();
    RestResponse r = adminRestSession.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits(c.name()));
    r.assertOK();
    BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
    assertThat(Iterables.getOnlyElement(info.newlyBanned)).isEqualTo(c.name());
    assertThat(info.alreadyBanned).isNull();
    assertThat(info.ignored).isNull();
    RemoteRefUpdate u = pushHead(testRepo, "refs/heads/master", false).getRemoteUpdate("refs/heads/master");
    assertThat(u).isNotNull();
    assertThat(u.getStatus()).isEqualTo(REJECTED_OTHER_REASON);
    assertThat(u.getMessage()).startsWith("contains banned commit");
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RestResponse(com.google.gerrit.acceptance.RestResponse) BanResultInfo(com.google.gerrit.server.project.BanCommit.BanResultInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with BanResultInfo

use of com.google.gerrit.server.project.BanCommit.BanResultInfo in project gerrit by GerritCodeReview.

the class BanCommitIT method banAlreadyBannedCommit.

@Test
public void banAlreadyBannedCommit() throws Exception {
    RestResponse r = adminRestSession.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
    r.consume();
    r = adminRestSession.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
    r.assertOK();
    BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
    assertThat(Iterables.getOnlyElement(info.alreadyBanned)).isEqualTo("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96");
    assertThat(info.newlyBanned).isNull();
    assertThat(info.ignored).isNull();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) BanResultInfo(com.google.gerrit.server.project.BanCommit.BanResultInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with BanResultInfo

use of com.google.gerrit.server.project.BanCommit.BanResultInfo in project gerrit by GerritCodeReview.

the class BanCommitCommand method run.

@Override
protected void run() throws Failure {
    try {
        BanCommit.Input input = BanCommit.Input.fromCommits(Lists.transform(commitsToBan, ObjectId::getName));
        input.reason = reason;
        BanResultInfo r = banCommit.apply(new ProjectResource(projectControl), input);
        printCommits(r.newlyBanned, "The following commits were banned");
        printCommits(r.alreadyBanned, "The following commits were already banned");
        printCommits(r.ignored, "The following ids do not represent commits and were ignored");
    } catch (RestApiException | IOException e) {
        throw die(e);
    }
}
Also used : BanResultInfo(com.google.gerrit.server.project.BanCommit.BanResultInfo) ProjectResource(com.google.gerrit.server.project.ProjectResource) IOException(java.io.IOException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) BanCommit(com.google.gerrit.server.project.BanCommit)

Aggregations

BanResultInfo (com.google.gerrit.server.project.BanCommit.BanResultInfo)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 RestResponse (com.google.gerrit.acceptance.RestResponse)2 Test (org.junit.Test)2 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 BanCommit (com.google.gerrit.server.project.BanCommit)1 ProjectResource (com.google.gerrit.server.project.ProjectResource)1 IOException (java.io.IOException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)1