Search in sources :

Example 11 with Patchset

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

the class TicketIndexer method docToQueryResult.

/**
	 * Creates a query result from the Lucene document.  This result is
	 * not a high-fidelity representation of the real ticket, but it is
	 * suitable for display in a table of search results.
	 *
	 * @param doc
	 * @return a query result
	 * @throws ParseException
	 */
private QueryResult docToQueryResult(Document doc) throws ParseException {
    QueryResult result = new QueryResult();
    result.project = unpackString(doc, Lucene.project);
    result.repository = unpackString(doc, Lucene.repository);
    result.number = unpackLong(doc, Lucene.number);
    result.createdBy = unpackString(doc, Lucene.createdby);
    result.createdAt = unpackDate(doc, Lucene.created);
    result.updatedBy = unpackString(doc, Lucene.updatedby);
    result.updatedAt = unpackDate(doc, Lucene.updated);
    result.title = unpackString(doc, Lucene.title);
    result.body = unpackString(doc, Lucene.body);
    result.status = Status.fromObject(unpackString(doc, Lucene.status), Status.New);
    result.responsible = unpackString(doc, Lucene.responsible);
    result.milestone = unpackString(doc, Lucene.milestone);
    result.topic = unpackString(doc, Lucene.topic);
    result.type = TicketModel.Type.fromObject(unpackString(doc, Lucene.type), TicketModel.Type.defaultType);
    result.mergeSha = unpackString(doc, Lucene.mergesha);
    result.mergeTo = unpackString(doc, Lucene.mergeto);
    result.commentsCount = unpackInt(doc, Lucene.comments);
    result.votesCount = unpackInt(doc, Lucene.votes);
    result.attachments = unpackStrings(doc, Lucene.attachments);
    result.labels = unpackStrings(doc, Lucene.labels);
    result.participants = unpackStrings(doc, Lucene.participants);
    result.watchedby = unpackStrings(doc, Lucene.watchedby);
    result.mentions = unpackStrings(doc, Lucene.mentions);
    result.priority = TicketModel.Priority.fromObject(unpackInt(doc, Lucene.priority), TicketModel.Priority.defaultPriority);
    result.severity = TicketModel.Severity.fromObject(unpackInt(doc, Lucene.severity), TicketModel.Severity.defaultSeverity);
    if (!StringUtils.isEmpty(doc.get(Lucene.patchset.name()))) {
        // unpack most recent patchset
        String[] values = doc.get(Lucene.patchset.name()).split(":", 5);
        Patchset patchset = new Patchset();
        patchset.number = Integer.parseInt(values[0]);
        patchset.rev = Integer.parseInt(values[1]);
        patchset.tip = values[2];
        patchset.base = values[3];
        patchset.commits = Integer.parseInt(values[4]);
        result.patchset = patchset;
    }
    return result;
}
Also used : Patchset(com.gitblit.models.TicketModel.Patchset)

Example 12 with Patchset

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

the class ITicketService method getTicket.

/**
	 * Retrieves the ticket.
	 *
	 * @param repository
	 * @param ticketId
	 * @return a ticket, if it exists, otherwise null
	 * @since 1.4.0
	 */
public final TicketModel getTicket(RepositoryModel repository, long ticketId) {
    TicketKey key = new TicketKey(repository, ticketId);
    TicketModel ticket = ticketsCache.getIfPresent(key);
    // if ticket not cached
    if (ticket == null) {
        //load ticket
        ticket = getTicketImpl(repository, ticketId);
        // if ticket exists
        if (ticket != null) {
            if (ticket.hasPatchsets() && updateDiffstats) {
                Repository r = repositoryManager.getRepository(repository.name);
                try {
                    Patchset patchset = ticket.getCurrentPatchset();
                    DiffStat diffStat = DiffUtils.getDiffStat(r, patchset.base, patchset.tip);
                    // mirroring
                    if (diffStat != null) {
                        ticket.insertions = diffStat.getInsertions();
                        ticket.deletions = diffStat.getDeletions();
                    }
                } finally {
                    r.close();
                }
            }
            //cache ticket
            ticketsCache.put(key, ticket);
        }
    }
    return ticket;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) DiffStat(com.gitblit.utils.DiffUtils.DiffStat) TicketModel(com.gitblit.models.TicketModel) Patchset(com.gitblit.models.TicketModel.Patchset)

Example 13 with Patchset

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

the class TicketServiceTest method testNotifier.

@Test
public void testNotifier() throws Exception {
    Change kernel = new Change("james");
    kernel.setField(Field.title, "Sample ticket");
    kernel.setField(Field.body, "this **is** my sample body\n\n- I hope\n- you really\n- *really* like it");
    kernel.setField(Field.status, Status.New);
    kernel.setField(Field.type, Type.Proposal);
    kernel.comment("this is a sample comment on a kernel change");
    Patchset patchset = new Patchset();
    patchset.insertions = 100;
    patchset.deletions = 10;
    patchset.number = 1;
    patchset.rev = 25;
    patchset.tip = "50f57913f816d04a16b7407134de5d8406421f37";
    kernel.patchset = patchset;
    TicketModel ticket = service.createTicket(getRepository(), 0L, kernel);
    Change merge = new Change("james");
    merge.setField(Field.mergeSha, patchset.tip);
    merge.setField(Field.mergeTo, "master");
    merge.setField(Field.status, Status.Merged);
    ticket = service.updateTicket(getRepository(), ticket.number, merge);
    ticket.repository = getRepository().name;
    TicketNotifier notifier = service.createNotifier();
    Mailing mailing = notifier.queueMailing(ticket);
    assertNotNull(mailing);
}
Also used : TicketNotifier(com.gitblit.tickets.TicketNotifier) Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) Mailing(com.gitblit.models.Mailing) Test(org.junit.Test)

Aggregations

Patchset (com.gitblit.models.TicketModel.Patchset)13 TicketModel (com.gitblit.models.TicketModel)8 Change (com.gitblit.models.TicketModel.Change)8 IOException (java.io.IOException)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 TicketLink (com.gitblit.models.TicketModel.TicketLink)3 UserModel (com.gitblit.models.UserModel)3 DiffStat (com.gitblit.utils.DiffUtils.DiffStat)3 ArrayList (java.util.ArrayList)3 Ref (org.eclipse.jgit.lib.Ref)3 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)2 Review (com.gitblit.models.TicketModel.Review)2 TicketLabel (com.gitblit.tickets.TicketLabel)2 MergeStatus (com.gitblit.utils.JGitUtils.MergeStatus)2 Label (org.apache.wicket.markup.html.basic.Label)2 Fragment (org.apache.wicket.markup.html.panel.Fragment)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 PatchsetHook (com.gitblit.extensions.PatchsetHook)1 PatchsetReceivePack (com.gitblit.git.PatchsetReceivePack)1