use of com.gitblit.extensions.PatchsetHook in project gitblit by gitblit.
the class PatchsetReceivePack method merge.
/**
* Merge the specified patchset to the integration branch.
*
* @param ticket
* @param patchset
* @return true, if successful
*/
public MergeStatus merge(TicketModel ticket) {
PersonIdent committer = new PersonIdent(user.getDisplayName(), StringUtils.isEmpty(user.emailAddress) ? (user.username + "@gitblit") : user.emailAddress);
Patchset patchset = ticket.getCurrentPatchset();
String message = MessageFormat.format("Merged #{0,number,0} \"{1}\"", ticket.number, ticket.title);
Ref oldRef = null;
try {
oldRef = getRepository().getRef(ticket.mergeTo);
} catch (IOException e) {
LOGGER.error("failed to get ref for " + ticket.mergeTo, e);
}
MergeResult mergeResult = JGitUtils.merge(getRepository(), patchset.tip, ticket.mergeTo, getRepositoryModel().mergeType, committer, message);
if (StringUtils.isEmpty(mergeResult.sha)) {
LOGGER.error("FAILED to merge {} to {} ({})", new Object[] { patchset, ticket.mergeTo, mergeResult.status.name() });
return mergeResult.status;
}
Change change = new Change(user.username);
change.setField(Field.status, Status.Merged);
change.setField(Field.mergeSha, mergeResult.sha);
change.setField(Field.mergeTo, ticket.mergeTo);
if (StringUtils.isEmpty(ticket.responsible)) {
// unassigned tickets are assigned to the closer
change.setField(Field.responsible, user.username);
}
long ticketId = ticket.number;
ticket = ticketService.updateTicket(repository, ticket.number, change);
if (ticket != null) {
ticketNotifier.queueMailing(ticket);
if (oldRef != null) {
ReceiveCommand cmd = new ReceiveCommand(oldRef.getObjectId(), ObjectId.fromString(mergeResult.sha), oldRef.getName());
cmd.setResult(Result.OK);
List<ReceiveCommand> commands = Arrays.asList(cmd);
logRefChange(commands);
updateIncrementalPushTags(commands);
updateGitblitRefLog(commands);
}
// call patchset hooks
for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
try {
hook.onMergePatchset(ticket);
} catch (Exception e) {
LOGGER.error("Failed to execute extension", e);
}
}
return mergeResult.status;
} else {
LOGGER.error("FAILED to resolve ticket {} by merge from web ui", ticketId);
}
return mergeResult.status;
}
use of com.gitblit.extensions.PatchsetHook in project gitblit by gitblit.
the class PatchsetReceivePack method processPatchset.
/**
* Creates or updates an ticket with the specified patchset.
*
* @param cmd
* @return a ticket if the creation or update was successful
*/
private TicketModel processPatchset(PatchsetCommand cmd) {
Change change = cmd.getChange();
if (cmd.isNewTicket()) {
// create the ticket object
TicketModel ticket = ticketService.createTicket(repository, cmd.getTicketId(), change);
if (ticket != null) {
sendInfo("");
sendHeader("#{0,number,0}: {1}", ticket.number, StringUtils.trimString(ticket.title, Constants.LEN_SHORTLOG));
sendInfo("created proposal ticket from patchset");
sendInfo(ticketService.getTicketUrl(ticket));
sendInfo("");
// log the new patch ref
RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(new ReceiveCommand(cmd.getOldId(), cmd.getNewId(), cmd.getRefName())));
// call any patchset hooks
for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
try {
hook.onNewPatchset(ticket);
} catch (Exception e) {
LOGGER.error("Failed to execute extension", e);
}
}
return ticket;
} else {
sendError("FAILED to create ticket");
}
} else {
// update an existing ticket
TicketModel ticket = ticketService.updateTicket(repository, cmd.getTicketId(), change);
if (ticket != null) {
sendInfo("");
sendHeader("#{0,number,0}: {1}", ticket.number, StringUtils.trimString(ticket.title, Constants.LEN_SHORTLOG));
if (change.patchset.rev == 1) {
// new patchset
sendInfo("uploaded patchset {0} ({1})", change.patchset.number, change.patchset.type.toString());
} else {
// updated patchset
sendInfo("added {0} {1} to patchset {2}", change.patchset.added, change.patchset.added == 1 ? "commit" : "commits", change.patchset.number);
}
sendInfo(ticketService.getTicketUrl(ticket));
sendInfo("");
// log the new patchset ref
RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(new ReceiveCommand(cmd.getOldId(), cmd.getNewId(), cmd.getRefName())));
// call any patchset hooks
final boolean isNewPatchset = change.patchset.rev == 1;
for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
try {
if (isNewPatchset) {
hook.onNewPatchset(ticket);
} else {
hook.onUpdatePatchset(ticket);
}
} catch (Exception e) {
LOGGER.error("Failed to execute extension", e);
}
}
// return the updated ticket
return ticket;
} else {
sendError("FAILED to upload {0} for ticket {1,number,0}", change.patchset, cmd.getTicketId());
}
}
return null;
}
Aggregations