Search in sources :

Example 41 with TicketModel

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

the class ITicketService method deletePatchset.

/**
	 * Deletes a patchset from a ticket.
	 *
	 * @param ticket
	 * @param patchset
	 *            the patchset to delete (should be the highest revision)
	 * @param userName
	 * 			the user deleting the commit
	 * @return the revised ticket if the deletion was successful
	 * @since 1.8.0
	 */
public final TicketModel deletePatchset(TicketModel ticket, Patchset patchset, String userName) {
    Change deletion = new Change(userName);
    deletion.patchset = new Patchset();
    deletion.patchset.number = patchset.number;
    deletion.patchset.rev = patchset.rev;
    deletion.patchset.type = PatchsetType.Delete;
    //Find and delete references to tickets by the removed commits
    List<TicketLink> patchsetTicketLinks = JGitUtils.identifyTicketsBetweenCommits(repositoryManager.getRepository(ticket.repository), settings, patchset.base, patchset.tip);
    for (TicketLink link : patchsetTicketLinks) {
        link.isDelete = true;
    }
    deletion.pendingLinks = patchsetTicketLinks;
    RepositoryModel repositoryModel = repositoryManager.getRepositoryModel(ticket.repository);
    TicketModel revisedTicket = updateTicket(repositoryModel, ticket.number, deletion);
    return revisedTicket;
}
Also used : Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel) TicketLink(com.gitblit.models.TicketModel.TicketLink)

Example 42 with TicketModel

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

the class ITicketService method reindex.

/**
	 * Destroys an existing index and reindexes all tickets.
	 * This operation may be expensive and time-consuming.
	 * @since 1.4.0
	 */
public void reindex() {
    long start = System.nanoTime();
    indexer.deleteAll();
    for (String name : repositoryManager.getRepositoryList()) {
        RepositoryModel repository = repositoryManager.getRepositoryModel(name);
        try {
            List<TicketModel> tickets = getTickets(repository);
            if (!tickets.isEmpty()) {
                log.info("reindexing {} tickets from {} ...", tickets.size(), repository);
                indexer.index(tickets);
                System.gc();
            }
        } catch (Exception e) {
            log.error("failed to reindex {}", repository.name);
            log.error(null, e);
        }
    }
    long end = System.nanoTime();
    long secs = TimeUnit.NANOSECONDS.toMillis(end - start);
    log.info("reindexing completed in {} msecs.", secs);
}
Also used : TicketModel(com.gitblit.models.TicketModel) RepositoryModel(com.gitblit.models.RepositoryModel) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 43 with TicketModel

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

the class ITicketService method deleteMilestone.

/**
	 * Deletes a milestone.
	 *
	 * @param repository
	 * @param milestone
	 * @param createdBy
	 * @param notifyOpenTickets
	 * @return true if successful
	 * @since 1.6.0
	 */
public synchronized boolean deleteMilestone(RepositoryModel repository, String milestone, String createdBy, boolean notifyOpenTickets) {
    if (StringUtils.isEmpty(milestone)) {
        throw new IllegalArgumentException("milestone can not be empty!");
    }
    Repository db = null;
    try {
        TicketMilestone tm = getMilestone(repository, milestone);
        if (tm == null) {
            return false;
        }
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.unsetSection(MILESTONE, milestone);
        config.save();
        milestonesCache.remove(repository.name);
        TicketNotifier notifier = createNotifier();
        for (QueryResult qr : tm.tickets) {
            Change change = new Change(createdBy);
            change.setField(Field.milestone, "");
            TicketModel ticket = updateTicket(repository, qr.number, change);
            if (notifyOpenTickets && ticket.isOpen()) {
                notifier.queueMailing(ticket);
            }
        }
        if (notifyOpenTickets) {
            notifier.sendAll();
        }
        return true;
    } catch (IOException e) {
        log.error("failed to delete milestone " + milestone + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException)

Example 44 with TicketModel

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

the class ITicketService method deleteTicket.

/**
	 * Deletes a ticket.
	 *
	 * @param repository
	 * @param ticketId
	 * @param deletedBy
	 * @return true if successful
	 * @since 1.4.0
	 */
public boolean deleteTicket(RepositoryModel repository, long ticketId, String deletedBy) {
    TicketModel ticket = getTicket(repository, ticketId);
    boolean success = deleteTicketImpl(repository, ticket, deletedBy);
    if (success) {
        log.info(MessageFormat.format("Deleted {0} ticket #{1,number,0}: {2}", repository.name, ticketId, ticket.title));
        ticketsCache.invalidate(new TicketKey(repository, ticketId));
        indexer.delete(ticket);
        return true;
    }
    return false;
}
Also used : TicketModel(com.gitblit.models.TicketModel)

Example 45 with TicketModel

use of com.gitblit.models.TicketModel 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)

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