]> source.dussan.org Git - gitblit.git/commitdiff
Add onFork and onRename methods to RepositoryLifeCycleListener 51/251/1
authorJames Moger <james.moger@gitblit.com>
Fri, 22 May 2015 16:13:39 +0000 (12:13 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 22 May 2015 16:13:39 +0000 (12:13 -0400)
src/main/java/com/gitblit/extensions/RepositoryLifeCycleListener.java
src/main/java/com/gitblit/manager/GitblitManager.java
src/main/java/com/gitblit/manager/RepositoryManager.java
src/site/plugins_extensions.mkd

index 5ef03af70739b3e591db18c96a7314ccb26a36e4..e23fca7859e35a2d6384e853348819510bdd0f92 100644 (file)
@@ -35,6 +35,24 @@ public abstract class RepositoryLifeCycleListener implements ExtensionPoint {
         */
        public abstract void onCreation(RepositoryModel repository);
 
+       /**
+        * Called after a repository has been forked.
+        *
+        * @param origin
+        * @param fork
+        * @since 1.7.0
+        */
+       public abstract void onFork(RepositoryModel origin, RepositoryModel fork);
+
+       /**
+        * Called after a repository has been renamed.
+        *
+        * @param oldName
+        * @param repository
+        * @since 1.7.0
+        */
+       public abstract void onRename(String oldName, RepositoryModel repository);
+
        /**
         * Called after a repository has been deleted.
         *
index 9692e654ffdd2b2f784f92d4b7b79deb9aacf9f2..deaa5347343ed095b92d9b4bf026639d64ebd3e9 100644 (file)
@@ -54,6 +54,7 @@ import com.gitblit.Constants.FederationToken;
 import com.gitblit.Constants.Role;
 import com.gitblit.GitBlitException;
 import com.gitblit.IStoredSettings;
+import com.gitblit.extensions.RepositoryLifeCycleListener;
 import com.gitblit.models.FederationModel;
 import com.gitblit.models.FederationProposal;
 import com.gitblit.models.FederationSet;
@@ -276,6 +277,16 @@ public class GitblitManager implements IGitblit {
 
                // add this clone to the cached model
                repositoryManager.addToCachedRepositoryList(cloneModel);
+
+               if (pluginManager != null) {
+                       for (RepositoryLifeCycleListener listener : pluginManager.getExtensions(RepositoryLifeCycleListener.class)) {
+                               try {
+                                       listener.onFork(repository, cloneModel);
+                               } catch (Throwable t) {
+                                       logger.error(String.format("failed to call plugin onFork %s", repository.name), t);
+                               }
+                       }
+               }
                return cloneModel;
        }
 
index c2c6088e815498c866f37e50603ff69a015c45f9..23fd02246d6887260c615cfe8241dca3bd481714 100644 (file)
@@ -1375,6 +1375,7 @@ public class RepositoryManager implements IRepositoryManager {
                                repository.name = repository.name.substring(projectPath.length() + 1);
                        }
                }
+               boolean isRename = false;
                if (isCreate) {
                        // ensure created repository name ends with .git
                        if (!repository.name.toLowerCase().endsWith(org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
@@ -1391,7 +1392,8 @@ public class RepositoryManager implements IRepositoryManager {
                        r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared);
                } else {
                        // rename repository
-                       if (!repositoryName.equalsIgnoreCase(repository.name)) {
+                       isRename = !repositoryName.equalsIgnoreCase(repository.name);
+                       if (isRename) {
                                if (!repository.name.toLowerCase().endsWith(
                                                org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
                                        repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
@@ -1511,6 +1513,14 @@ public class RepositoryManager implements IRepositoryManager {
                                        logger.error(String.format("failed to call plugin onCreation %s", repositoryName), t);
                                }
                        }
+               } else if (isRename && pluginManager != null) {
+                       for (RepositoryLifeCycleListener listener : pluginManager.getExtensions(RepositoryLifeCycleListener.class)) {
+                               try {
+                                       listener.onRename(repositoryName, repository);
+                               } catch (Throwable t) {
+                                       logger.error(String.format("failed to call plugin onRename %s", repositoryName), t);
+                               }
+                       }
                }
        }
 
index 9e0d17056d32e3d12cb3415dc21a563f244a6bcd..82dd30bc2d9a75c7f7426c8d5e3634c7e25625c5 100644 (file)
@@ -337,6 +337,16 @@ public class MyRepoLifeCycleListener extends RepositoryLifeCycleListener {
        log.info("Gitblit created {}", repo);
     }
 
+    @Override
+    public void onFork(RepositoryModel origin, RepositoryModel fork) {
+       log.info("{} forked to {}", origin, fork);
+    }
+
+    @Override
+    public void onRename(String oldName, RepositoryModel repo) {
+       log.info("{} renamed to {}", oldName, repo);
+    }
+
     @Override
     public void onDeletion(RepositoryModel repo) {
        log.info("Gitblit deleted {}", repo);