Search in sources :

Example 1 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class MigrateTickets method migrate.

/**
	 * Migrate all tickets
	 *
	 * @param baseFolder
	 * @param settings
	 * @param outputServiceName
	 */
protected void migrate(File baseFolder, IStoredSettings settings, String outputServiceName) {
    // disable some services
    settings.overrideSetting(Keys.web.allowLuceneIndexing, false);
    settings.overrideSetting(Keys.git.enableGarbageCollection, false);
    settings.overrideSetting(Keys.git.enableMirroring, false);
    settings.overrideSetting(Keys.web.activityCacheDays, 0);
    settings.overrideSetting(ITicketService.SETTING_UPDATE_DIFFSTATS, false);
    XssFilter xssFilter = new AllowXssFilter();
    IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter, baseFolder).start();
    IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, null, null).start();
    String inputServiceName = settings.getString(Keys.tickets.service, BranchTicketService.class.getSimpleName());
    if (StringUtils.isEmpty(inputServiceName)) {
        System.err.println(MessageFormat.format("Please define a ticket service in \"{0}\"", Keys.tickets.service));
        System.exit(1);
    }
    ITicketService inputService = null;
    ITicketService outputService = null;
    try {
        inputService = getService(inputServiceName, runtimeManager, repositoryManager);
        outputService = getService(outputServiceName, runtimeManager, repositoryManager);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    if (!inputService.isReady()) {
        System.err.println(String.format("%s INPUT service is not ready, check config.", inputService.getClass().getSimpleName()));
        System.exit(1);
    }
    if (!outputService.isReady()) {
        System.err.println(String.format("%s OUTPUT service is not ready, check config.", outputService.getClass().getSimpleName()));
        System.exit(1);
    }
    // migrate tickets
    long start = System.nanoTime();
    long totalTickets = 0;
    long totalChanges = 0;
    for (RepositoryModel repository : repositoryManager.getRepositoryModels()) {
        Set<Long> ids = inputService.getIds(repository);
        if (ids == null || ids.isEmpty()) {
            // nothing to migrate
            continue;
        }
        // delete any tickets we may have in the output ticket service
        outputService.deleteAll(repository);
        for (long id : ids) {
            List<Change> journal = inputService.getJournal(repository, id);
            if (journal == null || journal.size() == 0) {
                continue;
            }
            TicketModel ticket = outputService.createTicket(repository, id, journal.get(0));
            if (ticket == null) {
                System.err.println(String.format("Failed to migrate %s #%s", repository.name, id));
                System.exit(1);
            }
            totalTickets++;
            System.out.println(String.format("%s #%s: %s", repository.name, ticket.number, ticket.title));
            for (int i = 1; i < journal.size(); i++) {
                TicketModel updated = outputService.updateTicket(repository, ticket.number, journal.get(i));
                if (updated != null) {
                    System.out.println(String.format("   applied change %d", i));
                    totalChanges++;
                } else {
                    System.err.println(String.format("Failed to apply change %d:\n%s", i, journal.get(i)));
                    System.exit(1);
                }
            }
        }
    }
    inputService.stop();
    outputService.stop();
    repositoryManager.stop();
    runtimeManager.stop();
    long end = System.nanoTime();
    System.out.println(String.format("Migrated %d tickets composed of %d journal entries in %d seconds", totalTickets, totalTickets + totalChanges, TimeUnit.NANOSECONDS.toSeconds(end - start)));
}
Also used : ITicketService(com.gitblit.tickets.ITicketService) BranchTicketService(com.gitblit.tickets.BranchTicketService) IRuntimeManager(com.gitblit.manager.IRuntimeManager) RuntimeManager(com.gitblit.manager.RuntimeManager) IRepositoryManager(com.gitblit.manager.IRepositoryManager) TicketModel(com.gitblit.models.TicketModel) RepositoryModel(com.gitblit.models.RepositoryModel) Change(com.gitblit.models.TicketModel.Change) CmdLineException(org.kohsuke.args4j.CmdLineException) IRuntimeManager(com.gitblit.manager.IRuntimeManager) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) XssFilter(com.gitblit.utils.XssFilter) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) IRepositoryManager(com.gitblit.manager.IRepositoryManager) RepositoryManager(com.gitblit.manager.RepositoryManager)

Example 2 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketReferenceTest method noReferencesOnTicketCreation.

@Test
public void noReferencesOnTicketCreation() throws Exception {
    TicketModel a = ticketService.createTicket(repo, newTicket("noReferencesOnCreation"));
    assertNotNull(a);
    assertFalse(a.hasReferences());
    //Ensure retrieval process doesn't affect anything
    a = ticketService.getTicket(repo, a.number);
    assertNotNull(a);
    assertFalse(a.hasReferences());
}
Also used : TicketModel(com.gitblit.models.TicketModel) Test(org.junit.Test)

Example 3 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketServiceTest method testPriorityAndSeverity.

@Test
public void testPriorityAndSeverity() throws Exception {
    // C1: create and insert a ticket
    Change c1 = newChange("testPriorityAndSeverity() " + Long.toHexString(System.currentTimeMillis()));
    TicketModel ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);
    assertEquals(TicketModel.Priority.Normal, ticket.priority);
    assertEquals(TicketModel.Severity.Unrated, ticket.severity);
    TicketModel constructed = service.getTicket(getRepository(), ticket.number);
    compare(ticket, constructed);
    // C2: Change Priority max
    Change c2 = new Change("C2");
    c2.setField(Field.priority, TicketModel.Priority.Urgent);
    constructed = service.updateTicket(getRepository(), ticket.number, c2);
    assertNotNull(constructed);
    assertEquals(2, constructed.changes.size());
    assertEquals(TicketModel.Priority.Urgent, constructed.priority);
    assertEquals(TicketModel.Severity.Unrated, constructed.severity);
    // C3: Change Severity max
    Change c3 = new Change("C3");
    c3.setField(Field.severity, TicketModel.Severity.Catastrophic);
    constructed = service.updateTicket(getRepository(), ticket.number, c3);
    assertNotNull(constructed);
    assertEquals(3, constructed.changes.size());
    assertEquals(TicketModel.Priority.Urgent, constructed.priority);
    assertEquals(TicketModel.Severity.Catastrophic, constructed.severity);
    // C4: Change Priority min
    Change c4 = new Change("C3");
    c4.setField(Field.priority, TicketModel.Priority.Low);
    constructed = service.updateTicket(getRepository(), ticket.number, c4);
    assertNotNull(constructed);
    assertEquals(4, constructed.changes.size());
    assertEquals(TicketModel.Priority.Low, constructed.priority);
    assertEquals(TicketModel.Severity.Catastrophic, constructed.severity);
}
Also used : TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) Test(org.junit.Test)

Example 4 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketServiceTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    // query non-existent ticket
    TicketModel nonExistent = service.getTicket(getRepository(), 0);
    assertNull(nonExistent);
    // create and insert a ticket
    Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));
    TicketModel ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);
    // retrieve ticket and compare
    TicketModel constructed = service.getTicket(getRepository(), ticket.number);
    compare(ticket, constructed);
    assertEquals(1, constructed.changes.size());
    // C1: create the ticket
    int changeCount = 0;
    c1 = newChange("testUpdates() " + Long.toHexString(System.currentTimeMillis()));
    ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);
    changeCount++;
    constructed = service.getTicket(getRepository(), ticket.number);
    compare(ticket, constructed);
    assertEquals(1, constructed.changes.size());
    // C2: set owner
    Change c2 = new Change("C2");
    c2.comment("I'll fix this");
    c2.setField(Field.responsible, c2.author);
    constructed = service.updateTicket(getRepository(), ticket.number, c2);
    assertNotNull(constructed);
    assertEquals(2, constructed.changes.size());
    assertEquals(c2.author, constructed.responsible);
    changeCount++;
    // C3: add a note
    Change c3 = new Change("C3");
    c3.comment("yeah, this is working");
    constructed = service.updateTicket(getRepository(), ticket.number, c3);
    assertNotNull(constructed);
    assertEquals(3, constructed.changes.size());
    changeCount++;
    if (service.supportsAttachments()) {
        // C4: add attachment
        Change c4 = new Change("C4");
        Attachment a = newAttachment();
        c4.addAttachment(a);
        constructed = service.updateTicket(getRepository(), ticket.number, c4);
        assertNotNull(constructed);
        assertTrue(constructed.hasAttachments());
        Attachment a1 = service.getAttachment(getRepository(), ticket.number, a.name);
        assertEquals(a.content.length, a1.content.length);
        assertTrue(Arrays.areEqual(a.content, a1.content));
        changeCount++;
    }
    // C5: close the issue
    Change c5 = new Change("C5");
    c5.comment("closing issue");
    c5.setField(Field.status, Status.Resolved);
    constructed = service.updateTicket(getRepository(), ticket.number, c5);
    assertNotNull(constructed);
    changeCount++;
    assertTrue(constructed.isClosed());
    assertEquals(changeCount, constructed.changes.size());
    List<TicketModel> allTickets = service.getTickets(getRepository());
    List<TicketModel> openTickets = service.getTickets(getRepository(), new TicketFilter() {

        @Override
        public boolean accept(TicketModel ticket) {
            return ticket.isOpen();
        }
    });
    List<TicketModel> closedTickets = service.getTickets(getRepository(), new TicketFilter() {

        @Override
        public boolean accept(TicketModel ticket) {
            return ticket.isClosed();
        }
    });
    assertTrue(allTickets.size() > 0);
    assertEquals(1, openTickets.size());
    assertEquals(1, closedTickets.size());
    // build a new Lucene index
    service.reindex(getRepository());
    List<QueryResult> hits = service.searchFor(getRepository(), "working", 1, 10);
    assertEquals(1, hits.size());
    // reindex a ticket
    ticket = allTickets.get(0);
    Change change = new Change("reindex");
    change.comment("this is a test of reindexing a ticket");
    service.updateTicket(getRepository(), ticket.number, change);
    ticket = service.getTicket(getRepository(), ticket.number);
    hits = service.searchFor(getRepository(), "reindexing", 1, 10);
    assertEquals(1, hits.size());
    service.stop();
    service = getService(false);
    // Lucene field query
    List<QueryResult> results = service.queryFor(Lucene.status.matches(Status.New.name()), 1, 10, Lucene.created.name(), true);
    assertEquals(1, results.size());
    assertTrue(results.get(0).title.startsWith("testCreation"));
    // Lucene field query
    results = service.queryFor(Lucene.status.matches(Status.Resolved.name()), 1, 10, Lucene.created.name(), true);
    assertEquals(1, results.size());
    assertTrue(results.get(0).title.startsWith("testUpdates"));
    // check the ids
    assertEquals("[1, 2]", service.getIds(getRepository()).toString());
    // delete all tickets
    for (TicketModel aTicket : allTickets) {
        assertTrue(service.deleteTicket(getRepository(), aTicket.number, "D"));
    }
}
Also used : QueryResult(com.gitblit.tickets.QueryResult) TicketModel(com.gitblit.models.TicketModel) Attachment(com.gitblit.models.TicketModel.Attachment) Change(com.gitblit.models.TicketModel.Change) TicketFilter(com.gitblit.tickets.ITicketService.TicketFilter) Test(org.junit.Test)

Example 5 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketServiceTest method testDeleteComment.

@Test
public void testDeleteComment() throws Exception {
    // C1: create the ticket
    Change c1 = newChange("testDeleteComment() " + Long.toHexString(System.currentTimeMillis()));
    TicketModel ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);
    assertTrue(ticket.changes.get(0).hasComment());
    ticket = service.deleteComment(ticket, c1.comment.id, "D1");
    assertNotNull(ticket);
    assertEquals(1, ticket.changes.size());
    assertFalse(ticket.changes.get(0).hasComment());
    assertTrue(service.deleteTicket(getRepository(), ticket.number, "D"));
}
Also used : TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) Test(org.junit.Test)

Aggregations

TicketModel (com.gitblit.models.TicketModel)62 Change (com.gitblit.models.TicketModel.Change)32 Test (org.junit.Test)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)21 IOException (java.io.IOException)18 Reference (com.gitblit.models.TicketModel.Reference)16 Repository (org.eclipse.jgit.lib.Repository)12 Patchset (com.gitblit.models.TicketModel.Patchset)8 RepositoryModel (com.gitblit.models.RepositoryModel)7 TicketLink (com.gitblit.models.TicketModel.TicketLink)7 Ref (org.eclipse.jgit.lib.Ref)5 UserModel (com.gitblit.models.UserModel)4 ArrayList (java.util.ArrayList)4 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)4 Attachment (com.gitblit.models.TicketModel.Attachment)3 ParseException (java.text.ParseException)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 TicketHook (com.gitblit.extensions.TicketHook)2 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)2 BranchTicketService (com.gitblit.tickets.BranchTicketService)2