*/ | */ | ||||
public abstract void onCreation(RepositoryModel repository); | 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. | * Called after a repository has been deleted. | ||||
* | * |
import com.gitblit.Constants.Role; | import com.gitblit.Constants.Role; | ||||
import com.gitblit.GitBlitException; | import com.gitblit.GitBlitException; | ||||
import com.gitblit.IStoredSettings; | import com.gitblit.IStoredSettings; | ||||
import com.gitblit.extensions.RepositoryLifeCycleListener; | |||||
import com.gitblit.models.FederationModel; | import com.gitblit.models.FederationModel; | ||||
import com.gitblit.models.FederationProposal; | import com.gitblit.models.FederationProposal; | ||||
import com.gitblit.models.FederationSet; | import com.gitblit.models.FederationSet; | ||||
// add this clone to the cached model | // add this clone to the cached model | ||||
repositoryManager.addToCachedRepositoryList(cloneModel); | 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; | return cloneModel; | ||||
} | } | ||||
repository.name = repository.name.substring(projectPath.length() + 1); | repository.name = repository.name.substring(projectPath.length() + 1); | ||||
} | } | ||||
} | } | ||||
boolean isRename = false; | |||||
if (isCreate) { | if (isCreate) { | ||||
// ensure created repository name ends with .git | // ensure created repository name ends with .git | ||||
if (!repository.name.toLowerCase().endsWith(org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { | if (!repository.name.toLowerCase().endsWith(org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { | ||||
r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared); | r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared); | ||||
} else { | } else { | ||||
// rename repository | // rename repository | ||||
if (!repositoryName.equalsIgnoreCase(repository.name)) { | |||||
isRename = !repositoryName.equalsIgnoreCase(repository.name); | |||||
if (isRename) { | |||||
if (!repository.name.toLowerCase().endsWith( | if (!repository.name.toLowerCase().endsWith( | ||||
org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { | org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { | ||||
repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT; | repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT; | ||||
logger.error(String.format("failed to call plugin onCreation %s", repositoryName), t); | 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); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
log.info("Gitblit created {}", repo); | 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 | @Override | ||||
public void onDeletion(RepositoryModel repo) { | public void onDeletion(RepositoryModel repo) { | ||||
log.info("Gitblit deleted {}", repo); | log.info("Gitblit deleted {}", repo); |