mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
Add an argument RepositoryInfo to RepositoryAction
This commit is contained in:
@@ -3,19 +3,19 @@ package plugin
|
||||
import org.mozilla.javascript.{Context => JsContext}
|
||||
import org.mozilla.javascript.{Function => JsFunction}
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import plugin.PluginSystem.{Action, GlobalMenu, RepositoryMenu}
|
||||
import plugin.PluginSystem._
|
||||
|
||||
class JavaScriptPlugin(val id: String, val version: String,
|
||||
val author: String, val url: String, val description: String) extends Plugin {
|
||||
|
||||
private val repositoryMenuList = ListBuffer[RepositoryMenu]()
|
||||
private val globalMenuList = ListBuffer[GlobalMenu]()
|
||||
private val repositoryActionList = ListBuffer[Action]()
|
||||
private val repositoryActionList = ListBuffer[RepositoryAction]()
|
||||
private val globalActionList = ListBuffer[Action]()
|
||||
|
||||
def repositoryMenus : List[RepositoryMenu] = repositoryMenuList.toList
|
||||
def globalMenus : List[GlobalMenu] = globalMenuList.toList
|
||||
def repositoryActions : List[Action] = repositoryActionList.toList
|
||||
def repositoryActions : List[RepositoryAction] = repositoryActionList.toList
|
||||
def globalActions : List[Action] = globalActionList.toList
|
||||
|
||||
def addRepositoryMenu(label: String, name: String, url: String, icon: String, condition: JsFunction): Unit = {
|
||||
@@ -52,10 +52,10 @@ class JavaScriptPlugin(val id: String, val version: String,
|
||||
}
|
||||
|
||||
def addRepositoryAction(path: String, function: JsFunction): Unit = {
|
||||
repositoryActionList += Action(path, (request, response) => {
|
||||
repositoryActionList += RepositoryAction(path, (request, response, repository) => {
|
||||
val context = JsContext.enter()
|
||||
try {
|
||||
function.call(context, function, function, Array(request, response))
|
||||
function.call(context, function, function, Array(request, response, repository))
|
||||
} finally {
|
||||
JsContext.exit()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package plugin
|
||||
|
||||
import plugin.PluginSystem.{Action, GlobalMenu, RepositoryMenu}
|
||||
import plugin.PluginSystem._
|
||||
|
||||
trait Plugin {
|
||||
val id: String
|
||||
@@ -11,6 +11,6 @@ trait Plugin {
|
||||
|
||||
def repositoryMenus : List[RepositoryMenu]
|
||||
def globalMenus : List[GlobalMenu]
|
||||
def repositoryActions : List[Action]
|
||||
def repositoryActions : List[RepositoryAction]
|
||||
def globalActions : List[Action]
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import util.ControlUtil._
|
||||
import org.apache.commons.io.FileUtils
|
||||
import util.JGitUtil
|
||||
import org.eclipse.jgit.api.Git
|
||||
import service.RepositoryService.RepositoryInfo
|
||||
|
||||
/**
|
||||
* Provides extension points to plug-ins.
|
||||
@@ -78,7 +79,7 @@ object PluginSystem {
|
||||
|
||||
def repositoryMenus : List[RepositoryMenu] = pluginsMap.values.flatMap(_.repositoryMenus).toList
|
||||
def globalMenus : List[GlobalMenu] = pluginsMap.values.flatMap(_.globalMenus).toList
|
||||
def repositoryActions : List[Action] = pluginsMap.values.flatMap(_.repositoryActions).toList
|
||||
def repositoryActions : List[RepositoryAction] = pluginsMap.values.flatMap(_.repositoryActions).toList
|
||||
def globalActions : List[Action] = pluginsMap.values.flatMap(_.globalActions).toList
|
||||
|
||||
// Case classes to hold plug-ins information internally in GitBucket
|
||||
@@ -86,6 +87,7 @@ object PluginSystem {
|
||||
case class GlobalMenu(label: String, url: String, icon: String, condition: Context => Boolean)
|
||||
case class RepositoryMenu(label: String, name: String, url: String, icon: String, condition: Context => Boolean)
|
||||
case class Action(path: String, function: (HttpServletRequest, HttpServletResponse) => Any)
|
||||
case class RepositoryAction(path: String, function: (HttpServletRequest, HttpServletResponse, RepositoryInfo) => Any)
|
||||
|
||||
/**
|
||||
* Checks whether the plugin is updatable.
|
||||
|
||||
@@ -2,8 +2,9 @@ package plugin
|
||||
|
||||
import app.Context
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import plugin.PluginSystem.{Action, GlobalMenu, RepositoryMenu}
|
||||
import plugin.PluginSystem._
|
||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||
import service.RepositoryService.RepositoryInfo
|
||||
|
||||
// TODO This is a sample implementation for Scala based plug-ins.
|
||||
class ScalaPlugin(val id: String, val version: String,
|
||||
@@ -11,12 +12,12 @@ class ScalaPlugin(val id: String, val version: String,
|
||||
|
||||
private val repositoryMenuList = ListBuffer[RepositoryMenu]()
|
||||
private val globalMenuList = ListBuffer[GlobalMenu]()
|
||||
private val repositoryActionList = ListBuffer[Action]()
|
||||
private val repositoryActionList = ListBuffer[RepositoryAction]()
|
||||
private val globalActionList = ListBuffer[Action]()
|
||||
|
||||
def repositoryMenus : List[RepositoryMenu] = repositoryMenuList.toList
|
||||
def globalMenus : List[GlobalMenu] = globalMenuList.toList
|
||||
def repositoryActions : List[Action] = repositoryActionList.toList
|
||||
def repositoryActions : List[RepositoryAction] = repositoryActionList.toList
|
||||
def globalActions : List[Action] = globalActionList.toList
|
||||
|
||||
def addRepositoryMenu(label: String, name: String, url: String, icon: String)(condition: (Context) => Boolean): Unit = {
|
||||
@@ -31,8 +32,8 @@ class ScalaPlugin(val id: String, val version: String,
|
||||
globalActionList += Action(path, function)
|
||||
}
|
||||
|
||||
def addRepositoryAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
||||
repositoryActionList += Action(path, function)
|
||||
def addRepositoryAction(path: String)(function: (HttpServletRequest, HttpServletResponse, RepositoryInfo) => Any): Unit = {
|
||||
repositoryActionList += RepositoryAction(path, function)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,14 +55,15 @@ class PluginActionInvokeFilter extends Filter with SystemSettingsService with Re
|
||||
val owner = elements(1)
|
||||
val name = elements(2)
|
||||
val remain = elements.drop(3).mkString("/", "/", "")
|
||||
getRepository(owner, name, "").flatMap { repository => // TODO fill baseUrl
|
||||
val systemSettings = loadSystemSettings()
|
||||
getRepository(owner, name, systemSettings.baseUrl(request)).flatMap { repository =>
|
||||
plugin.PluginSystem.repositoryActions.find(_.path == remain).map { action =>
|
||||
val result = action.function(request, response)
|
||||
val result = action.function(request, response, repository)
|
||||
result match {
|
||||
case x: String => {
|
||||
response.setContentType("text/html; charset=UTF-8")
|
||||
val loginAccount = request.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]
|
||||
implicit val context = app.Context(loadSystemSettings(), Option(loginAccount), request)
|
||||
implicit val context = app.Context(systemSettings, Option(loginAccount), request)
|
||||
val html = _root_.html.main("GitBucket", None)(_root_.html.menu("", repository)(Html(x))) // TODO specify active side menu
|
||||
IOUtils.write(html.toString.getBytes("UTF-8"), response.getOutputStream)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user