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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations