From aa89bef3a9e06404afb268426cbab1ef20c3857c Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 11 Apr 2014 19:28:50 -0400 Subject: Add PatchsetHook extensions --- .../java/com/gitblit/extensions/PatchsetHook.java | 53 ++++++++++++++++++++++ .../java/com/gitblit/git/PatchsetReceivePack.java | 33 ++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/main/java/com/gitblit/extensions/PatchsetHook.java (limited to 'src/main/java') diff --git a/src/main/java/com/gitblit/extensions/PatchsetHook.java b/src/main/java/com/gitblit/extensions/PatchsetHook.java new file mode 100644 index 00000000..e465f507 --- /dev/null +++ b/src/main/java/com/gitblit/extensions/PatchsetHook.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.extensions; + +import ro.fortsoft.pf4j.ExtensionPoint; + +import com.gitblit.models.TicketModel; + +/** + * Extension point for plugins to respond to Ticket patchset changes. + * + * @author James Moger + * + */ +public abstract class PatchsetHook implements ExtensionPoint { + + /** + * Called after a new patchset has been created. This patchset + * may not be the first patchset of the ticket. The ticket may be a new + * proposal or it may be a existing ticket that now has a new patchset. + * + * @param ticket + */ + public abstract void onNewPatchset(TicketModel ticket); + + /** + * Called after a patchset has been FAST-FORWARD updated. + * + * @param ticket + */ + public abstract void onUpdatePatchset(TicketModel ticket); + + /** + * Called after a patchset has been merged to the integration branch specified + * in the ticket. + * + * @param ticket + */ + public abstract void onMergePatchset(TicketModel ticket); +} diff --git a/src/main/java/com/gitblit/git/PatchsetReceivePack.java b/src/main/java/com/gitblit/git/PatchsetReceivePack.java index 2c3b957b..77d5a71e 100644 --- a/src/main/java/com/gitblit/git/PatchsetReceivePack.java +++ b/src/main/java/com/gitblit/git/PatchsetReceivePack.java @@ -51,6 +51,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.Constants; import com.gitblit.Keys; +import com.gitblit.extensions.PatchsetHook; import com.gitblit.manager.IGitblit; import com.gitblit.models.RepositoryModel; import com.gitblit.models.TicketModel; @@ -716,6 +717,15 @@ public class PatchsetReceivePack extends GitblitReceivePack { 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"); @@ -743,6 +753,20 @@ public class PatchsetReceivePack extends GitblitReceivePack { 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 { @@ -1167,6 +1191,15 @@ public class PatchsetReceivePack extends GitblitReceivePack { ObjectId.fromString(mergeResult.sha), oldRef.getName()); RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd)); } + + // 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); -- cgit v1.2.3