} else {
// vetos are binding
allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
}
MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo);
if (allowMerge) {
if (MergeStatus.MERGEABLE == mergeStatus) {
// patchset can be cleanly merged to integration branch OR has already been merged
Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
if (user.canPush(repository)) {
// user can merge locally
SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// ensure the patchset is still current AND not vetoed
Patchset patchset = ticket.getCurrentPatchset();
final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
// patchset is current, check for recent veto
if (!refreshedTicket.isVetoed(patchset)) {
// patchset is not vetoed
// execute the merge using the ticket service
app().tickets().exec(new Runnable() {
@Override
public void run() {
PatchsetReceivePack rp = new PatchsetReceivePack(
app().gitblit(),
getRepository(),
getRepositoryModel(),
GitBlitWebSession.get().getUser());
MergeStatus result = rp.merge(refreshedTicket);
if (MergeStatus.MERGED == result) {
// notify participants and watchers
rp.sendAll();
} else {
// merge failure
String msg = MessageFormat.format("Failed to merge ticket {0,number,0}: {1}", ticket.number, result.name());
logger.error(msg);
GitBlitWebSession.get().cacheErrorMessage(msg);
}
}
});