Search in sources :

Example 1 with BanResultInfo

use of com.google.gerrit.server.restapi.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/", BanCommitInput.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()).contains("contains banned commit");
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RestResponse(com.google.gerrit.acceptance.RestResponse) BanResultInfo(com.google.gerrit.server.restapi.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.restapi.project.BanCommit.BanResultInfo in project gerrit by GerritCodeReview.

the class BanCommitCommand method run.

@Override
protected void run() throws Failure {
    enableGracefulStop();
    try {
        BanCommitInput input = BanCommitInput.fromCommits(Lists.transform(commitsToBan, ObjectId::getName));
        input.reason = reason;
        BanResultInfo r = banCommit.apply(new ProjectResource(projectState, user), input).value();
        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 (Exception e) {
        throw die(e);
    }
}
Also used : BanCommitInput(com.google.gerrit.extensions.api.projects.BanCommitInput) BanResultInfo(com.google.gerrit.server.restapi.project.BanCommit.BanResultInfo) ProjectResource(com.google.gerrit.server.project.ProjectResource)

Example 3 with BanResultInfo

use of com.google.gerrit.server.restapi.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/", BanCommitInput.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
    r.consume();
    r = adminRestSession.put("/projects/" + project.get() + "/ban/", BanCommitInput.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.restapi.project.BanCommit.BanResultInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

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