Search in sources :

Example 6 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testSendHtmlMail.

@Test
public void testSendHtmlMail() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
    commands.add(new ReceiveCommand(ObjectId.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
    RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
    repository.mailingLists.add("list@helloworld.git");
    test("sendmail-html.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(1, logger.messages.size());
    assertEquals(1, gitblit.messages.size());
    MockMail m = gitblit.messages.get(0);
    assertEquals(5, m.toAddresses.size());
    assertTrue(m.message.contains("BIT"));
    assertTrue(m.message.contains("<html>"));
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Test(org.junit.Test)

Example 7 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testFogbugz.

@Test
public void testFogbugz() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
    commands.add(new ReceiveCommand(ObjectId.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
    RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
    repository.customFields = new HashMap<String, String>();
    repository.customFields.put("fogbugzUrl", "http://bugs.test.com");
    repository.customFields.put("fogbugzRepositoryId", "1");
    repository.customFields.put("fogbugzCommitMessageRegex", "\\s*[Bb][Uu][Gg][(Zz)(Ss)]*\\s*[(IDs)]*\\s*[#:; ]+((\\d+[ ,:;#]*)+)");
    test("fogbugz.groovy", gitblit, logger, clientLogger, commands, repository);
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Test(org.junit.Test)

Example 8 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testProtectRefsDeleteMasterBranch.

@Test
public void testProtectRefsDeleteMasterBranch() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    ReceiveCommand command = new ReceiveCommand(ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), "refs/heads/master");
    commands.add(command);
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());
    assertEquals(0, logger.messages.size());
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 9 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testProtectRefsCreateTag.

@Test
public void testProtectRefsCreateTag() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(0, logger.messages.size());
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 10 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.

the class CommentsUtil method deleteAllDraftsFromAllUsers.

public void deleteAllDraftsFromAllUsers(Change.Id changeId) throws IOException {
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        BatchRefUpdate bru = repo.getRefDatabase().newBatchUpdate();
        for (Ref ref : getDraftRefs(repo, changeId)) {
            bru.addCommand(new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName()));
        }
        bru.setRefLogMessage("Delete drafts from NoteDb", false);
        bru.execute(rw, NullProgressMonitor.INSTANCE);
        for (ReceiveCommand cmd : bru.getCommands()) {
            if (cmd.getResult() != ReceiveCommand.Result.OK) {
                throw new IOException(String.format("Failed to delete draft comment ref %s at %s: %s (%s)", cmd.getRefName(), cmd.getOldId(), cmd.getResult(), cmd.getMessage()));
            }
        }
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Aggregations

ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)55 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 RepositoryModel (com.gitblit.models.RepositoryModel)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 Repository (org.eclipse.jgit.lib.Repository)9 Date (java.util.Date)8 Ref (org.eclipse.jgit.lib.Ref)7 OrmException (com.google.gwtorm.server.OrmException)6 Map (java.util.Map)6 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)5 Change (com.google.gerrit.reviewdb.client.Change)5 PersonIdent (org.eclipse.jgit.lib.PersonIdent)5 TicketModel (com.gitblit.models.TicketModel)4 Change (com.gitblit.models.TicketModel.Change)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Account (com.google.gerrit.reviewdb.client.Account)4