summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/git
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-11 17:55:53 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-12 11:31:03 -0400
commit819efdc8c5ea633e9be1e744ade8b197d21a1962 (patch)
treefa178791fd466a50537a9d2046d114b8f855032f /src/main/java/com/gitblit/git
parenta57d0c36910a96391b79511224eeb2989f52f6e3 (diff)
downloadgitblit-819efdc8c5ea633e9be1e744ade8b197d21a1962.tar.gz
gitblit-819efdc8c5ea633e9be1e744ade8b197d21a1962.zip
Allow ReceiveHook extensions
Diffstat (limited to 'src/main/java/com/gitblit/git')
-rw-r--r--src/main/java/com/gitblit/git/GitblitReceivePack.java51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePack.java b/src/main/java/com/gitblit/git/GitblitReceivePack.java
index 73da3d3e..0cc41987 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePack.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePack.java
@@ -47,6 +47,7 @@ import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.client.Translation;
+import com.gitblit.extensions.ReceiveHook;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
@@ -157,6 +158,14 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
@Override
public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
+ if (commands.size() == 0) {
+ // no receive commands to process
+ // this can happen if receive pack subclasses intercept and filter
+ // the commands
+ LOGGER.debug("skipping pre-receive processing, no refs created, updated, or removed");
+ return;
+ }
+
if (repository.isMirror) {
// repository is a mirror
for (ReceiveCommand cmd : commands) {
@@ -276,6 +285,15 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
}
}
+ // call pre-receive plugins
+ for (ReceiveHook hook : gitblit.getExtensions(ReceiveHook.class)) {
+ try {
+ hook.onPreReceive(this, commands);
+ } catch (Exception e) {
+ LOGGER.error("Failed to execute extension", e);
+ }
+ }
+
Set<String> scripts = new LinkedHashSet<String>();
scripts.addAll(gitblit.getPreReceiveScriptsInherited(repository));
if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {
@@ -298,7 +316,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
@Override
public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
if (commands.size() == 0) {
- LOGGER.debug("skipping post-receive hooks, no refs created, updated, or removed");
+ LOGGER.debug("skipping post-receive processing, no refs created, updated, or removed");
return;
}
@@ -379,6 +397,15 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
}
}
+ // call post-receive plugins
+ for (ReceiveHook hook : gitblit.getExtensions(ReceiveHook.class)) {
+ try {
+ hook.onPostReceive(this, commands);
+ } catch (Exception e) {
+ LOGGER.error("Failed to execute extension", e);
+ }
+ }
+
// run Groovy hook scripts
Set<String> scripts = new LinkedHashSet<String>();
scripts.addAll(gitblit.getPostReceiveScriptsInherited(repository));
@@ -434,7 +461,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
this.gitblitUrl = url;
}
- protected void sendRejection(final ReceiveCommand cmd, final String why, Object... objects) {
+ public void sendRejection(final ReceiveCommand cmd, final String why, Object... objects) {
String text;
if (ArrayUtils.isEmpty(objects)) {
text = why;
@@ -445,15 +472,15 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
LOGGER.error(text + " (" + user.username + ")");
}
- protected void sendHeader(String msg, Object... objects) {
+ public void sendHeader(String msg, Object... objects) {
sendInfo("--> ", msg, objects);
}
- protected void sendInfo(String msg, Object... objects) {
+ public void sendInfo(String msg, Object... objects) {
sendInfo(" ", msg, objects);
}
- protected void sendInfo(String prefix, String msg, Object... objects) {
+ private void sendInfo(String prefix, String msg, Object... objects) {
String text;
if (ArrayUtils.isEmpty(objects)) {
text = msg;
@@ -467,7 +494,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
}
}
- protected void sendError(String msg, Object... objects) {
+ public void sendError(String msg, Object... objects) {
String text;
if (ArrayUtils.isEmpty(objects)) {
text = msg;
@@ -532,4 +559,16 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
}
}
}
+
+ public IGitblit getGitblit() {
+ return gitblit;
+ }
+
+ public RepositoryModel getRepositoryModel() {
+ return repository;
+ }
+
+ public UserModel getUserModel() {
+ return user;
+ }
}