mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 19:15:59 +01:00
(refs #110) Add CommitHook sample
WIP: Some important functions are not implement yet.
This commit is contained in:
@@ -8,6 +8,9 @@ import org.eclipse.jgit.api.Git
|
||||
import util.Directory._
|
||||
import org.eclipse.jgit.transport.{ReceivePack, UploadPack}
|
||||
import org.apache.sshd.server.command.UnknownCommand
|
||||
import servlet.{Database, CommitLogHook}
|
||||
import service.SystemSettingsService.SystemSettings
|
||||
import service.SystemSettingsService
|
||||
|
||||
|
||||
class GitCommandFactory extends CommandFactory {
|
||||
@@ -85,16 +88,25 @@ class GitUploadPack(command: String) extends GitCommand(command: String) {
|
||||
}
|
||||
}
|
||||
|
||||
class GitReceivePack(command: String) extends GitCommand(command: String) {
|
||||
class GitReceivePack(command: String) extends GitCommand(command: String) with SystemSettingsService {
|
||||
override def runnable = new Runnable {
|
||||
|
||||
// TODO correct this info
|
||||
val pusher: String = "user1"
|
||||
val baseURL: String = loadSystemSettings().baseUrl.getOrElse("http://localhost:8080")
|
||||
|
||||
override def run(): Unit = {
|
||||
using(Git.open(getRepositoryDir(owner, repositoryName))) { git =>
|
||||
val repository = git.getRepository
|
||||
// TODO hook commit
|
||||
val receive = new ReceivePack(repository)
|
||||
receive.receive(in, out, err)
|
||||
callback.onExit(0)
|
||||
receive.setPostReceiveHook(new CommitLogHook(owner, repositoryName, pusher, baseURL))
|
||||
Database(SshServer.getServletContext) withTransaction {
|
||||
receive.receive(in, out, err)
|
||||
callback.onExit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ssh
|
||||
|
||||
import javax.servlet.{ServletContextEvent, ServletContextListener}
|
||||
import javax.servlet.{ServletContext, ServletContextEvent, ServletContextListener}
|
||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@@ -13,6 +13,9 @@ object SshServer {
|
||||
|
||||
private val server = org.apache.sshd.SshServer.setUpDefaultServer()
|
||||
|
||||
// TODO think other way to create database session
|
||||
private var context: ServletContext = null
|
||||
|
||||
|
||||
private def configure() = {
|
||||
server.setPort(DEFAULT_PORT)
|
||||
@@ -23,8 +26,9 @@ object SshServer {
|
||||
server.setCommandFactory(new GitCommandFactory)
|
||||
}
|
||||
|
||||
def start() = {
|
||||
def start(context: ServletContext) = {
|
||||
if (SSH_SERVICE_ENABLE) {
|
||||
this.context = context
|
||||
configure()
|
||||
server.start()
|
||||
logger.info(s"Start SSH Server Listen on ${server.getPort}")
|
||||
@@ -34,6 +38,8 @@ object SshServer {
|
||||
def stop() = {
|
||||
server.stop(true)
|
||||
}
|
||||
|
||||
def getServletContext = this.context;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -46,7 +52,7 @@ object SshServer {
|
||||
class SshServerListener extends ServletContextListener {
|
||||
|
||||
override def contextInitialized(sce: ServletContextEvent): Unit = {
|
||||
SshServer.start()
|
||||
SshServer.start(sce.getServletContext())
|
||||
}
|
||||
|
||||
override def contextDestroyed(sce: ServletContextEvent): Unit = {
|
||||
|
||||
Reference in New Issue
Block a user