From a502d96a860456ec5e8c96761db70f7cabb74751 Mon Sep 17 00:00:00 2001 From: Paul Martin <paul@paulsputer.com> Date: Sat, 30 Apr 2016 04:19:14 -0400 Subject: [PATCH] Merge pull request #1073 from gitblit/1062-DocEditorUpdates --- src/main/java/com/gitblit/tickets/ITicketService.java | 93 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gitblit/tickets/ITicketService.java b/src/main/java/com/gitblit/tickets/ITicketService.java index 3261ca9..e831003 100644 --- a/src/main/java/com/gitblit/tickets/ITicketService.java +++ b/src/main/java/com/gitblit/tickets/ITicketService.java @@ -36,6 +36,7 @@ import com.gitblit.IStoredSettings; import com.gitblit.Keys; import com.gitblit.extensions.TicketHook; +import com.gitblit.manager.IManager; import com.gitblit.manager.INotificationManager; import com.gitblit.manager.IPluginManager; import com.gitblit.manager.IRepositoryManager; @@ -47,6 +48,7 @@ import com.gitblit.models.TicketModel.Change; import com.gitblit.models.TicketModel.Field; import com.gitblit.models.TicketModel.Patchset; +import com.gitblit.models.TicketModel.PatchsetType; import com.gitblit.models.TicketModel.Status; import com.gitblit.tickets.TicketIndexer.Lucene; import com.gitblit.utils.DeepCopier; @@ -63,7 +65,9 @@ * @author James Moger * */ -public abstract class ITicketService { +public abstract class ITicketService implements IManager { + + public static final String SETTING_UPDATE_DIFFSTATS = "migration.updateDiffstats"; private static final String LABEL = "label"; @@ -106,6 +110,8 @@ private final Map<String, List<TicketLabel>> labelsCache; private final Map<String, List<TicketMilestone>> milestonesCache; + + private final boolean updateDiffstats; private static class TicketKey { final String repository; @@ -164,18 +170,22 @@ this.labelsCache = new ConcurrentHashMap<String, List<TicketLabel>>(); this.milestonesCache = new ConcurrentHashMap<String, List<TicketMilestone>>(); + + this.updateDiffstats = settings.getBoolean(SETTING_UPDATE_DIFFSTATS, true); } /** * Start the service. * @since 1.4.0 */ + @Override public abstract ITicketService start(); /** * Stop the service. * @since 1.4.0 */ + @Override public final ITicketService stop() { indexer.close(); ticketsCache.invalidateAll(); @@ -245,6 +255,7 @@ */ public boolean isAcceptingTicketUpdates(RepositoryModel repository) { return isReady() + && repository.hasCommits && repository.isBare && !repository.isFrozen && !repository.isMirror; @@ -663,21 +674,24 @@ Repository db = null; try { db = repositoryManager.getRepository(repository.name); - TicketMilestone milestone = getMilestone(repository, oldName); + TicketMilestone tm = getMilestone(repository, oldName); + if (tm == null) { + return false; + } StoredConfig config = db.getConfig(); config.unsetSection(MILESTONE, oldName); - config.setString(MILESTONE, newName, STATUS, milestone.status.name()); - config.setString(MILESTONE, newName, COLOR, milestone.color); - if (milestone.due != null) { + config.setString(MILESTONE, newName, STATUS, tm.status.name()); + config.setString(MILESTONE, newName, COLOR, tm.color); + if (tm.due != null) { config.setString(MILESTONE, newName, DUE, - new SimpleDateFormat(DUE_DATE_PATTERN).format(milestone.due)); + new SimpleDateFormat(DUE_DATE_PATTERN).format(tm.due)); } config.save(); milestonesCache.remove(repository.name); TicketNotifier notifier = createNotifier(); - for (QueryResult qr : milestone.tickets) { + for (QueryResult qr : tm.tickets) { Change change = new Change(createdBy); change.setField(Field.milestone, newName); TicketModel ticket = updateTicket(repository, qr.number, change); @@ -731,6 +745,9 @@ 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); @@ -760,6 +777,15 @@ } return false; } + + /** + * Returns the set of assigned ticket ids in the repository. + * + * @param repository + * @return a set of assigned ticket ids in the repository + * @since 1.6.0 + */ + public abstract Set<Long> getIds(RepositoryModel repository); /** * Assigns a new ticket id. @@ -823,7 +849,7 @@ ticket = getTicketImpl(repository, ticketId); // if ticket exists if (ticket != null) { - if (ticket.hasPatchsets()) { + if (ticket.hasPatchsets() && updateDiffstats) { Repository r = repositoryManager.getRepository(repository.name); try { Patchset patchset = ticket.getCurrentPatchset(); @@ -855,6 +881,33 @@ * @since 1.4.0 */ protected abstract TicketModel getTicketImpl(RepositoryModel repository, long ticketId); + + + /** + * Returns the journal used to build a ticket. + * + * @param repository + * @param ticketId + * @return the journal for the ticket, if it exists, otherwise null + * @since 1.6.0 + */ + public final List<Change> getJournal(RepositoryModel repository, long ticketId) { + if (hasTicket(repository, ticketId)) { + List<Change> journal = getJournalImpl(repository, ticketId); + return journal; + } + return null; + } + + /** + * Retrieves the ticket journal. + * + * @param repository + * @param ticketId + * @return a ticket, if it exists, otherwise null + * @since 1.6.0 + */ + protected abstract List<Change> getJournalImpl(RepositoryModel repository, long ticketId); /** * Get the ticket url @@ -1161,6 +1214,30 @@ TicketModel revisedTicket = updateTicket(repository, ticket.number, deletion); return revisedTicket; } + + /** + * 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; + + RepositoryModel repository = repositoryManager.getRepositoryModel(ticket.repository); + TicketModel revisedTicket = updateTicket(repository, ticket.number, deletion); + + return revisedTicket; + } /** * Commit a ticket change to the repository. -- Gitblit v1.9.1