use of com.gitblit.extensions.TicketHook in project gitblit by gitblit.
the class ITicketService method updateTicket.
/**
* Updates a ticket and promotes pending links into references.
*
* @param repository
* @param ticketId, or 0 to action pending links in general
* @param change
* @return the ticket model if successful, null if failure or using 0 ticketId
* @since 1.4.0
*/
public final TicketModel updateTicket(RepositoryModel repository, long ticketId, Change change) {
if (change == null) {
throw new RuntimeException("change can not be null!");
}
if (StringUtils.isEmpty(change.author)) {
throw new RuntimeException("must specify a change author!");
}
boolean success = true;
TicketModel ticket = null;
if (ticketId > 0) {
TicketKey key = new TicketKey(repository, ticketId);
ticketsCache.invalidate(key);
success = commitChangeImpl(repository, ticketId, change);
if (success) {
ticket = getTicket(repository, ticketId);
ticketsCache.put(key, ticket);
indexer.index(ticket);
// call the ticket hooks
if (pluginManager != null) {
for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
try {
hook.onUpdateTicket(ticket, change);
} catch (Exception e) {
log.error("Failed to execute extension", e);
}
}
}
}
}
if (success) {
//Now that the ticket has been successfully persisted add references to this ticket from linked tickets
if (change.hasPendingLinks()) {
for (TicketLink link : change.pendingLinks) {
TicketModel linkedTicket = getTicket(repository, link.targetTicketId);
Change dstChange = null;
//Ignore if not available or self reference
if (linkedTicket != null && link.targetTicketId != ticketId) {
dstChange = new Change(change.author, change.date);
switch(link.action) {
case Comment:
{
if (ticketId == 0) {
throw new RuntimeException("must specify a ticket when linking a comment!");
}
dstChange.referenceTicket(ticketId, change.comment.id);
}
break;
case Commit:
{
dstChange.referenceCommit(link.hash);
}
break;
default:
{
throw new RuntimeException(String.format("must add persist logic for link of type %s", link.action));
}
}
}
if (dstChange != null) {
//If not deleted then remain null in journal
if (link.isDelete) {
dstChange.reference.deleted = true;
}
if (updateTicket(repository, link.targetTicketId, dstChange) != null) {
link.success = true;
}
}
}
}
}
return ticket;
}
use of com.gitblit.extensions.TicketHook in project gitblit by gitblit.
the class ITicketService method createTicket.
/**
* Creates a ticket. Your change must include a repository, author & title,
* at a minimum. If your change does not have those minimum requirements a
* RuntimeException will be thrown.
*
* @param repository
* @param ticketId (if <=0 the ticket id will be assigned)
* @param change
* @return true if successful
* @since 1.4.0
*/
public TicketModel createTicket(RepositoryModel repository, long ticketId, Change change) {
if (repository == null) {
throw new RuntimeException("Must specify a repository!");
}
if (StringUtils.isEmpty(change.author)) {
throw new RuntimeException("Must specify a change author!");
}
if (!change.hasField(Field.title)) {
throw new RuntimeException("Must specify a title!");
}
change.watch(change.author);
if (ticketId <= 0L) {
ticketId = assignNewId(repository);
}
change.setField(Field.status, Status.New);
boolean success = commitChangeImpl(repository, ticketId, change);
if (success) {
TicketModel ticket = getTicket(repository, ticketId);
indexer.index(ticket);
// call the ticket hooks
if (pluginManager != null) {
for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
try {
hook.onNewTicket(ticket);
} catch (Exception e) {
log.error("Failed to execute extension", e);
}
}
}
return ticket;
}
return null;
}
Aggregations