mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-08 03:56:06 +02:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c73e89ccd4 | ||
|
|
f58a506780 | ||
|
|
411d19e74e | ||
|
|
bd51ffd9d2 | ||
|
|
83980fdccd | ||
|
|
baab243bc8 | ||
|
|
4dd8e1dc63 | ||
|
|
0b11b8b084 | ||
|
|
704775dc60 | ||
|
|
c7a7be1de0 | ||
|
|
e21a970977 | ||
|
|
a526dcf2dd | ||
|
|
e86710fbbd | ||
|
|
73e850493a | ||
|
|
7d735f6f8a | ||
|
|
043e99a9eb | ||
|
|
65e079b1d3 | ||
|
|
32e6f584d8 | ||
|
|
ebc5219ce6 | ||
|
|
ad8e620bdf | ||
|
|
8590c693b9 | ||
|
|
8b29bf7d93 | ||
|
|
43b7f83082 | ||
|
|
9ef5c981ef | ||
|
|
f027ac34d4 | ||
|
|
2ea31d6869 | ||
|
|
a1af7d0f9c | ||
|
|
797bf37bfa | ||
|
|
7f78815c11 | ||
|
|
d8a3f308ed | ||
|
|
74e18a982d | ||
|
|
e86ad423c5 | ||
|
|
2f00060c57 | ||
|
|
3b7e6aa68e | ||
|
|
5f3d6242fd | ||
|
|
6793a86bae | ||
|
|
d99ce20529 | ||
|
|
93e7b604cd | ||
|
|
5c81ce9b68 | ||
|
|
c9cf62701f | ||
|
|
f65babca4b | ||
|
|
23c146fc5d | ||
|
|
e14f336142 | ||
|
|
54647be5bd | ||
|
|
9517d65646 | ||
|
|
d6817796b3 | ||
|
|
ab19d473c4 |
@@ -79,9 +79,14 @@ Run the following commands in `Terminal` to
|
||||
|
||||
Release Notes
|
||||
--------
|
||||
### 3.2 - 3 May 2015
|
||||
- Directory history button
|
||||
- Compare / pull request button
|
||||
- Limit of activity log
|
||||
|
||||
### 3.1.1 - 4 Apr 2015
|
||||
- Rolled back H2 version to avoid version compatibility issue
|
||||
- Plug-ins can access ServletContext
|
||||
- Plug-ins became possible to access ServletContext
|
||||
|
||||
### 3.1 - 28 Mar 2015
|
||||
- Web APIs for Jenkins github pull-request builder
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<property name="embed.classes.dir" value="${target.dir}/embed-classes"/>
|
||||
<property name="jetty.dir" value="embed-jetty"/>
|
||||
<property name="scala.version" value="2.11"/>
|
||||
<property name="gitbucket.version" value="3.1.1"/>
|
||||
<property name="gitbucket.version" value="3.2.0"/>
|
||||
<property name="jetty.version" value="8.1.16.v20140903"/>
|
||||
<property name="servlet.version" value="3.0.0.v201112011016"/>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ This directory has following structure:
|
||||
|
||||
```
|
||||
* /HOME/gitbucket
|
||||
* /repositoties
|
||||
* /repositories
|
||||
* /USER_NAME
|
||||
* / REPO_NAME.git (substance of repository. GitServlet sees this directory)
|
||||
* / REPO_NAME
|
||||
|
||||
@@ -4,6 +4,6 @@ mvn deploy:deploy-file \
|
||||
-DartifactId=gitbucket-assembly\
|
||||
-Dversion=3.1.1\
|
||||
-Dpackaging=jar\
|
||||
-Dfile=../target/scala-2.11/gitbucket-assembly-3.1.1.jar\
|
||||
-Dfile=../target/scala-2.11/gitbucket-assembly-3.2.0.jar\
|
||||
-DrepositoryId=sourceforge.jp\
|
||||
-Durl=scp://shell.sourceforge.jp/home/groups/a/am/amateras/htdocs/mvn/
|
||||
|
||||
@@ -10,7 +10,7 @@ import sbtassembly.AssemblyKeys._
|
||||
object MyBuild extends Build {
|
||||
val Organization = "gitbucket"
|
||||
val Name = "gitbucket"
|
||||
val Version = "3.1.1"
|
||||
val Version = "3.2.0"
|
||||
val ScalaVersion = "2.11.6"
|
||||
val ScalatraVersion = "2.3.1"
|
||||
|
||||
@@ -64,7 +64,9 @@ object MyBuild extends Build {
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.mchange" % "c3p0" % "0.9.5",
|
||||
"com.typesafe" % "config" % "1.2.1",
|
||||
"com.typesafe.play" %% "twirl-compiler" % "1.0.4"
|
||||
"com.typesafe.play" %% "twirl-compiler" % "1.0.4",
|
||||
"com.typesafe.akka" %% "akka-actor" % "2.3.10",
|
||||
"com.enragedginger" %% "akka-quartz-scheduler" % "1.3.0-akka-2.3.x"
|
||||
),
|
||||
play.twirl.sbt.Import.TwirlKeys.templateImports += "gitbucket.core._",
|
||||
EclipseKeys.withSource := true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import gitbucket.core.controller._
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.servlet.{AccessTokenAuthenticationFilter, BasicAuthenticationFilter, TransactionFilter}
|
||||
import gitbucket.core.servlet.{AccessTokenAuthenticationFilter, BasicAuthenticationFilter, Database, TransactionFilter}
|
||||
import gitbucket.core.util.Directory
|
||||
|
||||
import java.util.EnumSet
|
||||
@@ -47,4 +47,8 @@ class ScalatraBootstrap extends LifeCycle {
|
||||
dir.mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
override def destroy(context: ServletContext): Unit = {
|
||||
Database.closeDataSource()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ trait IndexControllerBase extends ControllerBase {
|
||||
get("/_user/proposals")(usersOnly {
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray)
|
||||
Map("options" -> getAllUsers(false).filter(!_.isGroupAccount).map(_.userName).toArray)
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -132,11 +132,11 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
|
||||
// call web hooks
|
||||
callIssuesWebHook("opened", repository, issue, context.baseUrl, context.loginAccount.get)
|
||||
}
|
||||
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
||||
Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issue, form.content.getOrElse("")){
|
||||
Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||
}
|
||||
}
|
||||
|
||||
redirect(s"/${owner}/${name}/issues/${issueId}")
|
||||
@@ -418,13 +418,13 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
Notifier() match {
|
||||
case f =>
|
||||
content foreach {
|
||||
f.toNotify(repository, issueId, _){
|
||||
f.toNotify(repository, issue, _){
|
||||
Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${
|
||||
if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId.get}")
|
||||
}
|
||||
}
|
||||
action foreach {
|
||||
f.toNotify(repository, issueId, _){
|
||||
f.toNotify(repository, issue, _){
|
||||
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +125,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
(for{
|
||||
issueId <- params("id").toIntOpt
|
||||
(issue, pullRequest) <- getPullRequest(repository.owner, repository.name, issueId)
|
||||
users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName, issue.userName), Set())
|
||||
users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName, issue.openedUserName), Set())
|
||||
baseOwner <- users.get(repository.owner)
|
||||
headOwner <- users.get(pullRequest.requestUserName)
|
||||
issueUser <- users.get(issue.userName)
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl)
|
||||
} yield {
|
||||
JsonFormat(ApiPullRequest(
|
||||
@@ -236,7 +236,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
callPullRequestWebHook("closed", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issueId, "merge"){
|
||||
Notifier().toNotify(repository, issue, "merge"){
|
||||
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
|
||||
}
|
||||
|
||||
@@ -248,6 +248,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
||||
val headBranch:Option[String] = params.get("head")
|
||||
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
||||
case (Some(originUserName), Some(originRepositoryName)) => {
|
||||
getRepository(originUserName, originRepositoryName, context.baseUrl).map { originRepository =>
|
||||
@@ -255,8 +256,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
Git.open(getRepositoryDir(originUserName, originRepositoryName)),
|
||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||
){ (oldGit, newGit) =>
|
||||
val oldBranch = JGitUtil.getDefaultBranch(oldGit, originRepository).get._2
|
||||
val newBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository).get._2
|
||||
val newBranch = headBranch.getOrElse(JGitUtil.getDefaultBranch(newGit, forkedRepository).get._2)
|
||||
val oldBranch = originRepository.branchList.find( _ == newBranch).getOrElse(JGitUtil.getDefaultBranch(oldGit, originRepository).get._2)
|
||||
|
||||
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${originUserName}:${oldBranch}...${newBranch}")
|
||||
}
|
||||
@@ -265,7 +266,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
case _ => {
|
||||
using(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))){ git =>
|
||||
JGitUtil.getDefaultBranch(git, forkedRepository).map { case (_, defaultBranch) =>
|
||||
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${defaultBranch}...${defaultBranch}")
|
||||
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${defaultBranch}...${headBranch.getOrElse(defaultBranch)}")
|
||||
} getOrElse {
|
||||
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}")
|
||||
}
|
||||
@@ -394,8 +395,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
||||
Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||
getIssue(repository.owner, repository.name, issueId.toString) foreach { issue =>
|
||||
Notifier().toNotify(repository, issue, form.content.getOrElse("")){
|
||||
Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||
}
|
||||
}
|
||||
|
||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||
|
||||
@@ -163,7 +163,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
post("/:owner/:repository/settings/hooks/test", webHookForm)(ownerOnly { (form, repository) =>
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
import scala.collection.JavaConverters._
|
||||
val commits = git.log
|
||||
val commits = if(repository.commitCount == 0) List.empty else git.log
|
||||
.add(git.getRepository.resolve(repository.repository.defaultBranch))
|
||||
.setMaxCount(3)
|
||||
.call.iterator.asScala.map(new CommitInfo(_))
|
||||
|
||||
@@ -294,9 +294,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||
if(raw){
|
||||
// Download
|
||||
defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
||||
JGitUtil.getContentFromId(git, objectId, true).map {bytes =>
|
||||
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||
}
|
||||
} getOrElse NotFound
|
||||
} else {
|
||||
html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
||||
new JGitUtil.CommitInfo(lastModifiedCommit), hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||
@@ -525,6 +525,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}, // groups of current user
|
||||
new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit
|
||||
files, readme, hasWritePermission(repository.owner, repository.name, context.loginAccount),
|
||||
getPullRequestFromBranch(repository.owner, repository.name, revstr, repository.repository.defaultBranch),
|
||||
flash.get("info"), flash.get("error"))
|
||||
}
|
||||
} getOrElse NotFound
|
||||
|
||||
@@ -21,6 +21,7 @@ trait SystemSettingsControllerBase extends ControllerBase {
|
||||
"isCreateRepoOptionPublic" -> trim(label("Default option to create a new repository", boolean())),
|
||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||
"notification" -> trim(label("Notification", boolean())),
|
||||
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
||||
"ssh" -> trim(label("SSH access", boolean())),
|
||||
"sshPort" -> trim(label("SSH port", optional(number()))),
|
||||
"smtp" -> optionalIfNotChecked("notification", mapping(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gitbucket.core.plugin
|
||||
|
||||
import javax.servlet.ServletContext
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.Version
|
||||
|
||||
/**
|
||||
@@ -18,12 +19,12 @@ trait Plugin {
|
||||
* This method is invoked in initialization of plugin system.
|
||||
* Register plugin functionality to PluginRegistry.
|
||||
*/
|
||||
def initialize(registry: PluginRegistry, context: ServletContext): Unit
|
||||
def initialize(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit
|
||||
|
||||
/**
|
||||
* This method is invoked in shutdown of plugin system.
|
||||
* If the plugin has any resources, release them in this method.
|
||||
*/
|
||||
def shutdown(registry: PluginRegistry, context: ServletContext): Unit
|
||||
def shutdown(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||
|
||||
import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.JDBCUtil._
|
||||
@@ -89,7 +90,7 @@ object PluginRegistry {
|
||||
/**
|
||||
* Initializes all installed plugins.
|
||||
*/
|
||||
def initialize(context: ServletContext, conn: java.sql.Connection): Unit = {
|
||||
def initialize(context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit = {
|
||||
val pluginDir = new File(PluginHome)
|
||||
if(pluginDir.exists && pluginDir.isDirectory){
|
||||
pluginDir.listFiles(new FilenameFilter {
|
||||
@@ -119,7 +120,7 @@ object PluginRegistry {
|
||||
}
|
||||
|
||||
// Initialize
|
||||
plugin.initialize(instance,context)
|
||||
plugin.initialize(instance, context, settings)
|
||||
instance.addPlugin(PluginInfo(
|
||||
pluginId = plugin.pluginId,
|
||||
pluginName = plugin.pluginName,
|
||||
@@ -137,10 +138,10 @@ object PluginRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
def shutdown(context: ServletContext): Unit = {
|
||||
def shutdown(context: ServletContext, settings: SystemSettings): Unit = {
|
||||
instance.getPlugins().foreach { pluginInfo =>
|
||||
try {
|
||||
pluginInfo.pluginClass.shutdown(instance, context)
|
||||
pluginInfo.pluginClass.shutdown(instance, context, settings)
|
||||
} catch {
|
||||
case e: Exception => {
|
||||
logger.error(s"Error during plugin shutdown", e)
|
||||
|
||||
@@ -7,6 +7,12 @@ import profile.simple._
|
||||
|
||||
trait ActivityService {
|
||||
|
||||
def deleteOldActivities(limit: Int)(implicit s: Session): Int = {
|
||||
Activities.map(_.activityId).sortBy(_ desc).drop(limit).firstOption.map { id =>
|
||||
Activities.filter(_.activityId <= id.bind).delete
|
||||
} getOrElse 0
|
||||
}
|
||||
|
||||
def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] =
|
||||
Activities
|
||||
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||
|
||||
@@ -22,10 +22,11 @@ trait IssuesService {
|
||||
def getComments(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||
IssueComments filter (_.byIssue(owner, repository, issueId)) list
|
||||
|
||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||
/** @return IssueComment and commentedUser */
|
||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account)] =
|
||||
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
||||
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
||||
.innerJoin(Accounts).on( (t1, t2) => t1.userName === t2.userName )
|
||||
.innerJoin(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
||||
.list
|
||||
|
||||
def getComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
||||
@@ -168,7 +169,7 @@ trait IssuesService {
|
||||
}
|
||||
|
||||
/** for api
|
||||
* @return (issue, commentCount, pullRequest, headRepository, headOwner)
|
||||
* @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner)
|
||||
*/
|
||||
def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)
|
||||
(implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = {
|
||||
@@ -176,7 +177,7 @@ trait IssuesService {
|
||||
searchIssueQueryBase(condition, true, offset, limit, repos)
|
||||
.innerJoin(PullRequests).on { case ((t1, t2), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) }
|
||||
.innerJoin(Repositories).on { case (((t1, t2), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) }
|
||||
.innerJoin(Accounts).on { case ((((t1, t2), t3), t4), t5) => t5.userName === t1.userName }
|
||||
.innerJoin(Accounts).on { case ((((t1, t2), t3), t4), t5) => t5.userName === t1.openedUserName }
|
||||
.innerJoin(Accounts).on { case (((((t1, t2), t3), t4), t5), t6) => t6.userName === t4.userName }
|
||||
.map { case (((((t1, t2), t3), t4), t5), t6) =>
|
||||
(t1, t5, t2.commentCount, t3, t4, t6)
|
||||
|
||||
@@ -83,6 +83,28 @@ trait PullRequestService { self: IssuesService =>
|
||||
.map { case (t1, t2) => t1 }
|
||||
.list
|
||||
|
||||
/**
|
||||
* for repository viewer.
|
||||
* 1. find pull request from from `branch` to othre branch on same repository
|
||||
* 1. return if exists pull request to `defaultBranch`
|
||||
* 2. return if exists pull request to othre branch
|
||||
* 2. return None
|
||||
*/
|
||||
def getPullRequestFromBranch(userName: String, repositoryName: String, branch: String, defaultBranch: String)
|
||||
(implicit s: Session): Option[(PullRequest, Issue)] =
|
||||
PullRequests
|
||||
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||
.filter { case (t1, t2) =>
|
||||
(t1.requestUserName === userName.bind) &&
|
||||
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||
(t1.requestBranch === branch.bind) &&
|
||||
(t1.userName === userName.bind) &&
|
||||
(t1.repositoryName === repositoryName.bind) &&
|
||||
(t2.closed === false.bind)
|
||||
}
|
||||
.sortBy{ case (t1, t2) => t1.branch =!= defaultBranch.bind }
|
||||
.firstOption
|
||||
|
||||
/**
|
||||
* Fetch pull request contents into refs/pull/${issueId}/head and update pull request table.
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,7 @@ trait SystemSettingsService {
|
||||
props.setProperty(IsCreateRepoOptionPublic, settings.isCreateRepoOptionPublic.toString)
|
||||
props.setProperty(Gravatar, settings.gravatar.toString)
|
||||
props.setProperty(Notification, settings.notification.toString)
|
||||
settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString))
|
||||
props.setProperty(Ssh, settings.ssh.toString)
|
||||
settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString))
|
||||
if(settings.notification) {
|
||||
@@ -65,12 +66,13 @@ trait SystemSettingsService {
|
||||
}
|
||||
SystemSettings(
|
||||
getOptionValue[String](props, BaseURL, None).map(x => x.replaceFirst("/\\Z", "")),
|
||||
getOptionValue[String](props, Information, None),
|
||||
getOptionValue(props, Information, None),
|
||||
getValue(props, AllowAccountRegistration, false),
|
||||
getValue(props, AllowAnonymousAccess, true),
|
||||
getValue(props, IsCreateRepoOptionPublic, true),
|
||||
getValue(props, Gravatar, true),
|
||||
getValue(props, Notification, false),
|
||||
getOptionValue[Int](props, ActivityLogLimit, None),
|
||||
getValue(props, Ssh, false),
|
||||
getOptionValue(props, SshPort, Some(DefaultSshPort)),
|
||||
if(getValue(props, Notification, false)){
|
||||
@@ -120,6 +122,7 @@ object SystemSettingsService {
|
||||
isCreateRepoOptionPublic: Boolean,
|
||||
gravatar: Boolean,
|
||||
notification: Boolean,
|
||||
activityLogLimit: Option[Int],
|
||||
ssh: Boolean,
|
||||
sshPort: Option[Int],
|
||||
smtp: Option[Smtp],
|
||||
@@ -166,6 +169,7 @@ object SystemSettingsService {
|
||||
private val IsCreateRepoOptionPublic = "is_create_repository_option_public"
|
||||
private val Gravatar = "gravatar"
|
||||
private val Notification = "notification"
|
||||
private val ActivityLogLimit = "activity_log_limit"
|
||||
private val Ssh = "ssh"
|
||||
private val SshPort = "ssh.port"
|
||||
private val SmtpHost = "smtp.host"
|
||||
|
||||
@@ -50,6 +50,7 @@ trait WebHookService {
|
||||
val f = Future {
|
||||
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
||||
val httpPost = new HttpPost(webHookUrl.url)
|
||||
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
httpPost.addHeader("X-Github-Event", eventName)
|
||||
|
||||
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
||||
@@ -80,10 +81,10 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
// https://developer.github.com/v3/activity/events/types/#issuesevent
|
||||
def callIssuesWebHook(action: String, repository: RepositoryService.RepositoryInfo, issue: Issue, baseUrl: String, sender: Account)(implicit s: Session, context:JsonFormat.Context): Unit = {
|
||||
callWebHookOf(repository.owner, repository.name, "issues"){
|
||||
val users = getAccountsByUserNames(Set(repository.owner, issue.userName), Set(sender))
|
||||
val users = getAccountsByUserNames(Set(repository.owner, issue.openedUserName), Set(sender))
|
||||
for{
|
||||
repoOwner <- users.get(repository.owner)
|
||||
issueUser <- users.get(issue.userName)
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
} yield {
|
||||
WebHookIssuesPayload(
|
||||
action = action,
|
||||
@@ -100,14 +101,16 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
callWebHookOf(repository.owner, repository.name, "pull_request"){
|
||||
for{
|
||||
(issue, pullRequest) <- getPullRequest(repository.owner, repository.name, issueId)
|
||||
users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName), Set(sender))
|
||||
users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName, issue.openedUserName), Set(sender))
|
||||
baseOwner <- users.get(repository.owner)
|
||||
headOwner <- users.get(pullRequest.requestUserName)
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl)
|
||||
} yield {
|
||||
WebHookPullRequestPayload(
|
||||
action = action,
|
||||
issue = issue,
|
||||
issueUser = issueUser,
|
||||
pullRequest = pullRequest,
|
||||
headRepository = headRepo,
|
||||
headOwner = headOwner,
|
||||
@@ -118,8 +121,9 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
}
|
||||
}
|
||||
|
||||
/** @return Map[(issue, issueUser, pullRequest, baseOwner, headOwner), webHooks] */
|
||||
def getPullRequestsByRequestForWebhook(userName:String, repositoryName:String, branch:String)
|
||||
(implicit s: Session): Map[(Issue, PullRequest, Account, Account), List[WebHook]] =
|
||||
(implicit s: Session): Map[(Issue, Account, PullRequest, Account, Account), List[WebHook]] =
|
||||
(for{
|
||||
is <- Issues if is.closed === false.bind
|
||||
pr <- PullRequests if pr.byPrimaryKey(is.userName, is.repositoryName, is.issueId)
|
||||
@@ -128,20 +132,22 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
if pr.requestBranch === branch.bind
|
||||
bu <- Accounts if bu.userName === pr.userName
|
||||
ru <- Accounts if ru.userName === pr.requestUserName
|
||||
iu <- Accounts if iu.userName === is.openedUserName
|
||||
wh <- WebHooks if wh.byRepository(is.userName , is.repositoryName)
|
||||
} yield {
|
||||
((is, pr, bu, ru), wh)
|
||||
((is, iu, pr, bu, ru), wh)
|
||||
}).list.groupBy(_._1).mapValues(_.map(_._2))
|
||||
|
||||
def callPullRequestWebHookByRequestBranch(action: String, requestRepository: RepositoryService.RepositoryInfo, requestBranch: String, baseUrl: String, sender: Account)(implicit s: Session, context:JsonFormat.Context): Unit = {
|
||||
import WebHookService._
|
||||
for{
|
||||
((issue, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
|
||||
((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
|
||||
baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName, baseUrl)
|
||||
} yield {
|
||||
val payload = WebHookPullRequestPayload(
|
||||
action = action,
|
||||
issue = issue,
|
||||
issueUser = issueUser,
|
||||
pullRequest = pullRequest,
|
||||
headRepository = requestRepository,
|
||||
headOwner = headOwner,
|
||||
@@ -161,10 +167,10 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
|
||||
callWebHookOf(repository.owner, repository.name, "issue_comment"){
|
||||
for{
|
||||
issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString())
|
||||
users = getAccountsByUserNames(Set(issue.userName, repository.owner, issueComment.userName), Set(sender))
|
||||
issueUser <- users.get(issue.userName)
|
||||
users = getAccountsByUserNames(Set(issue.openedUserName, repository.owner, issueComment.commentedUserName), Set(sender))
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
repoOwner <- users.get(repository.owner)
|
||||
commenter <- users.get(issueComment.userName)
|
||||
commenter <- users.get(issueComment.commentedUserName)
|
||||
} yield {
|
||||
WebHookIssueCommentPayload(
|
||||
issue = issue,
|
||||
@@ -224,6 +230,7 @@ object WebHookService {
|
||||
object WebHookPullRequestPayload{
|
||||
def apply(action: String,
|
||||
issue: Issue,
|
||||
issueUser: Account,
|
||||
pullRequest: PullRequest,
|
||||
headRepository: RepositoryInfo,
|
||||
headOwner: Account,
|
||||
@@ -233,7 +240,7 @@ object WebHookService {
|
||||
val headRepoPayload = ApiRepository(headRepository, headOwner)
|
||||
val baseRepoPayload = ApiRepository(baseRepository, baseOwner)
|
||||
val senderPayload = ApiUser(sender)
|
||||
val pr = ApiPullRequest(issue, pullRequest, headRepoPayload, baseRepoPayload, senderPayload)
|
||||
val pr = ApiPullRequest(issue, pullRequest, headRepoPayload, baseRepoPayload, ApiUser(issueUser))
|
||||
WebHookPullRequestPayload(
|
||||
action = action,
|
||||
number = issue.issueId,
|
||||
|
||||
167
src/main/scala/gitbucket/core/servlet/AutoUpdate.scala
Normal file
167
src/main/scala/gitbucket/core/servlet/AutoUpdate.scala
Normal file
@@ -0,0 +1,167 @@
|
||||
package gitbucket.core.servlet
|
||||
|
||||
import java.io.File
|
||||
import java.sql.{DriverManager, Connection}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.SystemSettingsService
|
||||
import gitbucket.core.util._
|
||||
import org.apache.commons.io.FileUtils
|
||||
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
||||
import org.slf4j.LoggerFactory
|
||||
import Directory._
|
||||
import ControlUtil._
|
||||
import JDBCUtil._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import gitbucket.core.util.Versions
|
||||
import gitbucket.core.util.Directory
|
||||
|
||||
object AutoUpdate {
|
||||
|
||||
/**
|
||||
* The history of versions. A head of this sequence is the current BitBucket version.
|
||||
*/
|
||||
val versions = Seq(
|
||||
new Version(3, 2),
|
||||
new Version(3, 1),
|
||||
new Version(3, 0),
|
||||
new Version(2, 8),
|
||||
new Version(2, 7) {
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT * FROM REPOSITORY"){ rs =>
|
||||
// Rename attached files directory from /issues to /comments
|
||||
val userName = rs.getString("USER_NAME")
|
||||
val repoName = rs.getString("REPOSITORY_NAME")
|
||||
defining(Directory.getAttachedDir(userName, repoName)){ newDir =>
|
||||
val oldDir = new File(newDir.getParentFile, "issues")
|
||||
if(oldDir.exists && oldDir.isDirectory){
|
||||
oldDir.renameTo(newDir)
|
||||
}
|
||||
}
|
||||
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME if it does not exist
|
||||
val originalUserName = rs.getString("ORIGIN_USER_NAME")
|
||||
val originalRepoName = rs.getString("ORIGIN_REPOSITORY_NAME")
|
||||
if(originalUserName != null && originalRepoName != null){
|
||||
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||
originalUserName, originalRepoName) == 0){
|
||||
conn.update("UPDATE REPOSITORY SET ORIGIN_USER_NAME = NULL, ORIGIN_REPOSITORY_NAME = NULL " +
|
||||
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||
}
|
||||
}
|
||||
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME if it does not exist
|
||||
val parentUserName = rs.getString("PARENT_USER_NAME")
|
||||
val parentRepoName = rs.getString("PARENT_REPOSITORY_NAME")
|
||||
if(parentUserName != null && parentRepoName != null){
|
||||
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||
parentUserName, parentRepoName) == 0){
|
||||
conn.update("UPDATE REPOSITORY SET PARENT_USER_NAME = NULL, PARENT_REPOSITORY_NAME = NULL " +
|
||||
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Version(2, 6),
|
||||
new Version(2, 5),
|
||||
new Version(2, 4),
|
||||
new Version(2, 3) {
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT ACTIVITY_ID, ADDITIONAL_INFO FROM ACTIVITY WHERE ACTIVITY_TYPE='push'"){ rs =>
|
||||
val curInfo = rs.getString("ADDITIONAL_INFO")
|
||||
val newInfo = curInfo.split("\n").filter(_ matches "^[0-9a-z]{40}:.*").mkString("\n")
|
||||
if (curInfo != newInfo) {
|
||||
conn.update("UPDATE ACTIVITY SET ADDITIONAL_INFO = ? WHERE ACTIVITY_ID = ?", newInfo, rs.getInt("ACTIVITY_ID"))
|
||||
}
|
||||
}
|
||||
ignore {
|
||||
FileUtils.deleteDirectory(Directory.getPluginCacheDir())
|
||||
//FileUtils.deleteDirectory(new File(Directory.PluginHome))
|
||||
}
|
||||
}
|
||||
},
|
||||
new Version(2, 2),
|
||||
new Version(2, 1),
|
||||
new Version(2, 0){
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
import eu.medsea.mimeutil.{MimeUtil2, MimeType}
|
||||
|
||||
val mimeUtil = new MimeUtil2()
|
||||
mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector")
|
||||
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||
defining(Directory.getAttachedDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME"))){ dir =>
|
||||
if(dir.exists && dir.isDirectory){
|
||||
dir.listFiles.foreach { file =>
|
||||
if(file.getName.indexOf('.') < 0){
|
||||
val mimeType = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file, new MimeType("application/octet-stream"))).toString
|
||||
if(mimeType.startsWith("image/")){
|
||||
file.renameTo(new File(file.getParent, file.getName + "." + mimeType.split("/")(1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Version(1, 13),
|
||||
Version(1, 12),
|
||||
Version(1, 11),
|
||||
Version(1, 10),
|
||||
Version(1, 9),
|
||||
Version(1, 8),
|
||||
Version(1, 7),
|
||||
Version(1, 6),
|
||||
Version(1, 5),
|
||||
Version(1, 4),
|
||||
new Version(1, 3){
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
// Fix wiki repository configuration
|
||||
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||
using(Git.open(getWikiRepositoryDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME")))){ git =>
|
||||
defining(git.getRepository.getConfig){ config =>
|
||||
if(!config.getBoolean("http", "receivepack", false)){
|
||||
config.setBoolean("http", null, "receivepack", true)
|
||||
config.save
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Version(1, 2),
|
||||
Version(1, 1),
|
||||
Version(1, 0),
|
||||
Version(0, 0)
|
||||
)
|
||||
|
||||
/**
|
||||
* The head version of BitBucket.
|
||||
*/
|
||||
val headVersion = versions.head
|
||||
|
||||
/**
|
||||
* The version file (GITBUCKET_HOME/version).
|
||||
*/
|
||||
lazy val versionFile = new File(GitBucketHome, "version")
|
||||
|
||||
/**
|
||||
* Returns the current version from the version file.
|
||||
*/
|
||||
def getCurrentVersion(): Version = {
|
||||
if(versionFile.exists){
|
||||
FileUtils.readFileToString(versionFile, "UTF-8").trim.split("\\.") match {
|
||||
case Array(majorVersion, minorVersion) => {
|
||||
versions.find { v =>
|
||||
v.majorVersion == majorVersion.toInt && v.minorVersion == minorVersion.toInt
|
||||
}.getOrElse(Version(0, 0))
|
||||
}
|
||||
case _ => Version(0, 0)
|
||||
}
|
||||
} else Version(0, 0)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,15 +40,19 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
|
||||
} else {
|
||||
request.getHeader("Authorization") match {
|
||||
case null => requireAuth(response)
|
||||
case auth => decodeAuthHeader(auth).split(":") match {
|
||||
case auth => decodeAuthHeader(auth).split(":", 2) match {
|
||||
case Array(username, password) => {
|
||||
authenticate(settings, username, password) match {
|
||||
case Some(account) if (isUpdating || repository.repository.isPrivate) => {
|
||||
if(hasWritePermission(repository.owner, repository.name, Some(account))){
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
chain.doFilter(req, wrappedResponse)
|
||||
case Some(account) => {
|
||||
if (isUpdating || repository.repository.isPrivate) {
|
||||
if(hasWritePermission(repository.owner, repository.name, Some(account))){
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
chain.doFilter(req, wrappedResponse)
|
||||
} else {
|
||||
requireAuth(response)
|
||||
}
|
||||
} else {
|
||||
requireAuth(response)
|
||||
chain.doFilter(req, wrappedResponse)
|
||||
}
|
||||
}
|
||||
case _ => requireAuth(response)
|
||||
|
||||
@@ -1,176 +1,22 @@
|
||||
package gitbucket.core.servlet
|
||||
|
||||
import java.io.File
|
||||
import java.sql.{DriverManager, Connection}
|
||||
import akka.event.Logging
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.service.{ActivityService, SystemSettingsService}
|
||||
import org.apache.commons.io.FileUtils
|
||||
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
||||
import org.slf4j.LoggerFactory
|
||||
import Directory._
|
||||
import ControlUtil._
|
||||
import JDBCUtil._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import gitbucket.core.util.Versions
|
||||
import gitbucket.core.util.Directory
|
||||
import gitbucket.core.plugin._
|
||||
|
||||
object AutoUpdate {
|
||||
|
||||
/**
|
||||
* The history of versions. A head of this sequence is the current BitBucket version.
|
||||
*/
|
||||
val versions = Seq(
|
||||
new Version(3, 1),
|
||||
new Version(3, 0),
|
||||
new Version(2, 8),
|
||||
new Version(2, 7) {
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT * FROM REPOSITORY"){ rs =>
|
||||
// Rename attached files directory from /issues to /comments
|
||||
val userName = rs.getString("USER_NAME")
|
||||
val repoName = rs.getString("REPOSITORY_NAME")
|
||||
defining(Directory.getAttachedDir(userName, repoName)){ newDir =>
|
||||
val oldDir = new File(newDir.getParentFile, "issues")
|
||||
if(oldDir.exists && oldDir.isDirectory){
|
||||
oldDir.renameTo(newDir)
|
||||
}
|
||||
}
|
||||
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME if it does not exist
|
||||
val originalUserName = rs.getString("ORIGIN_USER_NAME")
|
||||
val originalRepoName = rs.getString("ORIGIN_REPOSITORY_NAME")
|
||||
if(originalUserName != null && originalRepoName != null){
|
||||
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||
originalUserName, originalRepoName) == 0){
|
||||
conn.update("UPDATE REPOSITORY SET ORIGIN_USER_NAME = NULL, ORIGIN_REPOSITORY_NAME = NULL " +
|
||||
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||
}
|
||||
}
|
||||
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME if it does not exist
|
||||
val parentUserName = rs.getString("PARENT_USER_NAME")
|
||||
val parentRepoName = rs.getString("PARENT_REPOSITORY_NAME")
|
||||
if(parentUserName != null && parentRepoName != null){
|
||||
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||
parentUserName, parentRepoName) == 0){
|
||||
conn.update("UPDATE REPOSITORY SET PARENT_USER_NAME = NULL, PARENT_REPOSITORY_NAME = NULL " +
|
||||
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Version(2, 6),
|
||||
new Version(2, 5),
|
||||
new Version(2, 4),
|
||||
new Version(2, 3) {
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT ACTIVITY_ID, ADDITIONAL_INFO FROM ACTIVITY WHERE ACTIVITY_TYPE='push'"){ rs =>
|
||||
val curInfo = rs.getString("ADDITIONAL_INFO")
|
||||
val newInfo = curInfo.split("\n").filter(_ matches "^[0-9a-z]{40}:.*").mkString("\n")
|
||||
if (curInfo != newInfo) {
|
||||
conn.update("UPDATE ACTIVITY SET ADDITIONAL_INFO = ? WHERE ACTIVITY_ID = ?", newInfo, rs.getInt("ACTIVITY_ID"))
|
||||
}
|
||||
}
|
||||
ignore {
|
||||
FileUtils.deleteDirectory(Directory.getPluginCacheDir())
|
||||
//FileUtils.deleteDirectory(new File(Directory.PluginHome))
|
||||
}
|
||||
}
|
||||
},
|
||||
new Version(2, 2),
|
||||
new Version(2, 1),
|
||||
new Version(2, 0){
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
import eu.medsea.mimeutil.{MimeUtil2, MimeType}
|
||||
|
||||
val mimeUtil = new MimeUtil2()
|
||||
mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector")
|
||||
|
||||
super.update(conn, cl)
|
||||
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||
defining(Directory.getAttachedDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME"))){ dir =>
|
||||
if(dir.exists && dir.isDirectory){
|
||||
dir.listFiles.foreach { file =>
|
||||
if(file.getName.indexOf('.') < 0){
|
||||
val mimeType = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file, new MimeType("application/octet-stream"))).toString
|
||||
if(mimeType.startsWith("image/")){
|
||||
file.renameTo(new File(file.getParent, file.getName + "." + mimeType.split("/")(1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Version(1, 13),
|
||||
Version(1, 12),
|
||||
Version(1, 11),
|
||||
Version(1, 10),
|
||||
Version(1, 9),
|
||||
Version(1, 8),
|
||||
Version(1, 7),
|
||||
Version(1, 6),
|
||||
Version(1, 5),
|
||||
Version(1, 4),
|
||||
new Version(1, 3){
|
||||
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||
super.update(conn, cl)
|
||||
// Fix wiki repository configuration
|
||||
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||
using(Git.open(getWikiRepositoryDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME")))){ git =>
|
||||
defining(git.getRepository.getConfig){ config =>
|
||||
if(!config.getBoolean("http", "receivepack", false)){
|
||||
config.setBoolean("http", null, "receivepack", true)
|
||||
config.save
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Version(1, 2),
|
||||
Version(1, 1),
|
||||
Version(1, 0),
|
||||
Version(0, 0)
|
||||
)
|
||||
|
||||
/**
|
||||
* The head version of BitBucket.
|
||||
*/
|
||||
val headVersion = versions.head
|
||||
|
||||
/**
|
||||
* The version file (GITBUCKET_HOME/version).
|
||||
*/
|
||||
lazy val versionFile = new File(GitBucketHome, "version")
|
||||
|
||||
/**
|
||||
* Returns the current version from the version file.
|
||||
*/
|
||||
def getCurrentVersion(): Version = {
|
||||
if(versionFile.exists){
|
||||
FileUtils.readFileToString(versionFile, "UTF-8").trim.split("\\.") match {
|
||||
case Array(majorVersion, minorVersion) => {
|
||||
versions.find { v =>
|
||||
v.majorVersion == majorVersion.toInt && v.minorVersion == minorVersion.toInt
|
||||
}.getOrElse(Version(0, 0))
|
||||
}
|
||||
case _ => Version(0, 0)
|
||||
}
|
||||
} else Version(0, 0)
|
||||
}
|
||||
|
||||
}
|
||||
import akka.actor.{Actor, Props, ActorSystem}
|
||||
import com.typesafe.akka.extension.quartz.QuartzSchedulerExtension
|
||||
import AutoUpdate._
|
||||
|
||||
/**
|
||||
* Initialize GitBucket system.
|
||||
* Update database schema and load plug-ins automatically in the context initializing.
|
||||
*/
|
||||
class InitializeListener extends ServletContextListener {
|
||||
import AutoUpdate._
|
||||
class InitializeListener extends ServletContextListener with SystemSettingsService {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(classOf[InitializeListener])
|
||||
|
||||
@@ -181,28 +27,62 @@ class InitializeListener extends ServletContextListener {
|
||||
}
|
||||
org.h2.Driver.load()
|
||||
|
||||
defining(getConnection()){ conn =>
|
||||
Database() withTransaction { session =>
|
||||
val conn = session.conn
|
||||
|
||||
// Migration
|
||||
logger.debug("Start schema update")
|
||||
Versions.update(conn, headVersion, getCurrentVersion(), versions, Thread.currentThread.getContextClassLoader){ conn =>
|
||||
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
||||
}
|
||||
|
||||
// Load plugins
|
||||
logger.debug("Initialize plugins")
|
||||
PluginRegistry.initialize(event.getServletContext, conn)
|
||||
PluginRegistry.initialize(event.getServletContext, loadSystemSettings(), conn)
|
||||
}
|
||||
|
||||
// Start Quartz scheduler
|
||||
val system = ActorSystem("job", ConfigFactory.parseString(
|
||||
"""
|
||||
|akka {
|
||||
| quartz {
|
||||
| schedules {
|
||||
| Daily {
|
||||
| expression = "0 0 0 * * ?"
|
||||
| }
|
||||
| }
|
||||
| }
|
||||
|}
|
||||
""".stripMargin))
|
||||
|
||||
val scheduler = QuartzSchedulerExtension(system)
|
||||
|
||||
scheduler.schedule("Daily", system.actorOf(Props[DeleteOldActivityActor]), "DeleteOldActivity")
|
||||
}
|
||||
|
||||
def contextDestroyed(event: ServletContextEvent): Unit = {
|
||||
override def contextDestroyed(event: ServletContextEvent): Unit = {
|
||||
// Shutdown plugins
|
||||
PluginRegistry.shutdown(event.getServletContext)
|
||||
PluginRegistry.shutdown(event.getServletContext, loadSystemSettings())
|
||||
// Close datasource
|
||||
Database.closeDataSource()
|
||||
}
|
||||
|
||||
private def getConnection(): Connection =
|
||||
DriverManager.getConnection(
|
||||
DatabaseConfig.url,
|
||||
DatabaseConfig.user,
|
||||
DatabaseConfig.password)
|
||||
|
||||
}
|
||||
|
||||
class DeleteOldActivityActor extends Actor with SystemSettingsService with ActivityService {
|
||||
|
||||
private val logger = Logging(context.system, this)
|
||||
|
||||
def receive = {
|
||||
case s: String => {
|
||||
loadSystemSettings().activityLogLimit.foreach { limit =>
|
||||
if(limit > 0){
|
||||
Database() withTransaction { implicit session =>
|
||||
val rows = deleteOldActivities(limit)
|
||||
logger.info(s"Deleted ${rows} activity logs")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import javax.servlet._
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource
|
||||
import gitbucket.core.util.DatabaseConfig
|
||||
import org.scalatra.ScalatraBase
|
||||
import org.slf4j.LoggerFactory
|
||||
import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session}
|
||||
import gitbucket.core.util.Keys
|
||||
@@ -25,6 +26,12 @@ class TransactionFilter extends Filter {
|
||||
chain.doFilter(req, res)
|
||||
} else {
|
||||
Database() withTransaction { session =>
|
||||
// Register Scalatra error callback to rollback transaction
|
||||
ScalatraBase.onFailure { _ =>
|
||||
logger.debug("Rolled back transaction")
|
||||
session.rollback()
|
||||
}(req.asInstanceOf[HttpServletRequest])
|
||||
|
||||
logger.debug("begin transaction")
|
||||
req.setAttribute(Keys.Request.DBSession, session)
|
||||
chain.doFilter(req, res)
|
||||
@@ -39,17 +46,18 @@ object Database {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(Database.getClass)
|
||||
|
||||
private val db: SlickDatabase = {
|
||||
val datasource = new ComboPooledDataSource
|
||||
|
||||
datasource.setDriverClass(DatabaseConfig.driver)
|
||||
datasource.setJdbcUrl(DatabaseConfig.url)
|
||||
datasource.setUser(DatabaseConfig.user)
|
||||
datasource.setPassword(DatabaseConfig.password)
|
||||
|
||||
private val dataSource: ComboPooledDataSource = {
|
||||
val ds = new ComboPooledDataSource
|
||||
ds.setDriverClass(DatabaseConfig.driver)
|
||||
ds.setJdbcUrl(DatabaseConfig.url)
|
||||
ds.setUser(DatabaseConfig.user)
|
||||
ds.setPassword(DatabaseConfig.password)
|
||||
logger.debug("load database connection pool")
|
||||
ds
|
||||
}
|
||||
|
||||
SlickDatabase.forDataSource(datasource)
|
||||
private val db: SlickDatabase = {
|
||||
SlickDatabase.forDataSource(dataSource)
|
||||
}
|
||||
|
||||
def apply(): SlickDatabase = db
|
||||
@@ -57,4 +65,6 @@ object Database {
|
||||
def getSession(req: ServletRequest): Session =
|
||||
req.getAttribute(Keys.Request.DBSession).asInstanceOf[Session]
|
||||
|
||||
def closeDataSource(): Unit = dataSource.close
|
||||
|
||||
}
|
||||
|
||||
@@ -287,9 +287,6 @@ object JGitUtil {
|
||||
}
|
||||
}
|
||||
revWalk.markStart(revCommit)
|
||||
if(path != "."){
|
||||
revWalk.setTreeFilter(PathFilter.create(path))
|
||||
}
|
||||
val it = revWalk.iterator
|
||||
val lastCommit = it.next
|
||||
val nextParentsMap = Option(lastCommit).map(_.getParents.map(_ -> lastCommit).toMap).getOrElse(Map())
|
||||
@@ -357,12 +354,7 @@ object JGitUtil {
|
||||
} else {
|
||||
revWalk.markStart(revWalk.parseCommit(objectId))
|
||||
if(path.nonEmpty){
|
||||
revWalk.setRevFilter(new RevFilter(){
|
||||
def include(walk: RevWalk, commit: RevCommit): Boolean = {
|
||||
getDiffs(git, commit.getName, false)._1.find(_.newPath == path).nonEmpty
|
||||
}
|
||||
override def clone(): RevFilter = this
|
||||
})
|
||||
revWalk.setTreeFilter(AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF))
|
||||
}
|
||||
Right(getCommitLog(revWalk.iterator, 0, Nil))
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import SystemSettingsService.Smtp
|
||||
import ControlUtil.defining
|
||||
|
||||
trait Notifier extends RepositoryService with AccountService with IssuesService {
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String)
|
||||
(msg: String => String)(implicit context: Context): Unit
|
||||
|
||||
protected def recipients(issue: Issue)(notify: String => Unit)(implicit session: Session, context: Context) =
|
||||
@@ -67,16 +67,15 @@ object Notifier {
|
||||
class Mailer(private val smtp: Smtp) extends Notifier {
|
||||
private val logger = LoggerFactory.getLogger(classOf[Mailer])
|
||||
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String)
|
||||
(msg: String => String)(implicit context: Context) = {
|
||||
val database = Database()
|
||||
|
||||
val f = Future {
|
||||
database withSession { implicit session =>
|
||||
getIssue(r.owner, r.name, issueId.toString) foreach { issue =>
|
||||
defining(
|
||||
s"[${r.name}] ${issue.title} (#${issueId})" ->
|
||||
msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) =>
|
||||
defining(
|
||||
s"[${r.name}] ${issue.title} (#${issue.issueId})" ->
|
||||
msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) =>
|
||||
recipients(issue) { to =>
|
||||
val email = new HtmlEmail
|
||||
email.setHostName(smtp.host)
|
||||
@@ -92,14 +91,13 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
||||
.orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName))
|
||||
.foreach { case (address, name) =>
|
||||
email.setFrom(address, name)
|
||||
}
|
||||
}
|
||||
email.setCharset("UTF-8")
|
||||
email.setSubject(subject)
|
||||
email.setHtmlMsg(msg)
|
||||
|
||||
email.addTo(to).send
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"Notifications Successful."
|
||||
@@ -113,6 +111,6 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
||||
}
|
||||
}
|
||||
class MockMailer extends Notifier {
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String)
|
||||
(msg: String => String)(implicit context: Context): Unit = {}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,10 @@ class GitBucketHtmlSerializer(
|
||||
}
|
||||
|
||||
private def fixUrl(url: String, isImage: Boolean = false): String = {
|
||||
if(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("#") || url.startsWith("/")){
|
||||
if(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")){
|
||||
url
|
||||
} else if(url.startsWith("#")){
|
||||
("#" + GitBucketHtmlSerializer.generateAnchorName(url.substring(1)))
|
||||
} else if(!enableWikiLink){
|
||||
if(context.currentPath.contains("/blob/")){
|
||||
url + (if(isImage) "?raw=true" else "")
|
||||
|
||||
@@ -148,7 +148,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
||||
import scala.util.matching.Regex._
|
||||
implicit class RegexReplaceString(s: String) {
|
||||
def replaceAll(pattern: String, replacer: (Match) => String): String = {
|
||||
pattern.r.replaceAllIn(s, replacer)
|
||||
pattern.r.replaceAllIn(s, (m: Match) => replacer(m).replace("$", "\\$"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,15 @@
|
||||
</label>
|
||||
</fieldset>
|
||||
<!--====================================================================-->
|
||||
<!-- Activity -->
|
||||
<!--====================================================================-->
|
||||
<hr>
|
||||
<label><span class="strong">Limit of activity logs</span> (Unlimited if it's not specified or zero)</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="activityLogLimit" name="activityLogLimit" class="input-mini" value="@settings.activityLogLimit"/>
|
||||
<span id="error-activityLogLimit" class="error"></span>
|
||||
</div>
|
||||
<!--====================================================================-->
|
||||
<!-- Services -->
|
||||
<!--====================================================================-->
|
||||
<hr>
|
||||
|
||||
@@ -160,7 +160,7 @@ $(function(){
|
||||
return $('<tr class="not-diff"><td colspan="3" class="comment-box-container"></td></tr>');
|
||||
}
|
||||
if (typeof $('#show-notes')[0] !== 'undefined' && !$('#show-notes')[0].checked) {
|
||||
$('.inline-comment').hide();
|
||||
$('#comment-list').children('.inline-comment').hide();
|
||||
}
|
||||
$('.diff-outside').on('click','table.diff .add-comment',function() {
|
||||
var $this = $(this),
|
||||
|
||||
@@ -42,6 +42,13 @@ div#clickable {
|
||||
line-height: 120px;
|
||||
}
|
||||
|
||||
div.dz-message, div.dz-fallback {
|
||||
width: 240px;
|
||||
color: #000000;
|
||||
font-size: 12px;
|
||||
line-height: 14px;
|
||||
}
|
||||
|
||||
div#avatar {
|
||||
background-color: #f8f8f8;
|
||||
border: 1px dashed silver;
|
||||
|
||||
@@ -10,13 +10,8 @@
|
||||
<title>@title</title>
|
||||
<link rel="icon" href="@assets/common/images/gitbucket.png" type="image/vnd.microsoft.icon" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- Le styles -->
|
||||
<link href="@assets/vendors/bootstrap/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="@assets/vendors/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="@assets/vendors/bootstrap/js/html5shiv.js"></script>
|
||||
<![endif]-->
|
||||
<link href="@assets/vendors/datepicker/css/datepicker.css" rel="stylesheet">
|
||||
<link href="@assets/vendors/colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet">
|
||||
<link href="@assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
@@ -63,11 +58,11 @@
|
||||
<li><a href="@path/new">New repository</a></li>
|
||||
<li><a href="@path/groups/new">New group</a></li>
|
||||
</ul>
|
||||
<a href="@url(loginAccount.get.userName)/_edit" class="menu" data-toggle="tooltip" data-placement="bottom" title="Account settings"><i class="icon-user"></i></a>
|
||||
<a href="@url(loginAccount.get.userName)/_edit" class="menu" data-toggle="tooltip" data-placement="bottom" title="Account settings"><i class="icon-user" aria-label="Account settings"></i></a>
|
||||
@if(loginAccount.get.isAdmin){
|
||||
<a href="@path/admin/users" class="menu" data-toggle="tooltip" data-placement="bottom" title="Administration"><i class="icon-wrench"></i></a>
|
||||
<a href="@path/admin/users" class="menu" data-toggle="tooltip" data-placement="bottom" title="Administration"><i class="icon-wrench" aria-label="Administration"></i></a>
|
||||
}
|
||||
<a href="@path/signout" class="menu-last" data-toggle="tooltip" data-placement="bottom" title="Sign out"><i class="icon-share-alt"></i></a>
|
||||
<a href="@path/signout" class="menu-last" data-toggle="tooltip" data-placement="bottom" title="Sign out"><i class="icon-share-alt" aria-label="Sign out"></i></a>
|
||||
} else {
|
||||
<a href="@path/signin?redirect=@urlEncode(currentPath)" class="btn btn-last" id="signin">Sign in</a>
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
files: List[gitbucket.core.util.JGitUtil.FileInfo],
|
||||
readme: Option[(List[String], String)],
|
||||
hasWritePermission: Boolean,
|
||||
branchPullRequest: Option[(gitbucket.core.model.PullRequest, gitbucket.core.model.Issue)],
|
||||
info: Option[Any] = None,
|
||||
error: Option[Any] = None)(implicit context: gitbucket.core.controller.Context)
|
||||
@import context._
|
||||
@@ -13,6 +14,16 @@
|
||||
@html.main(s"${repository.owner}/${repository.name}", Some(repository)) {
|
||||
@html.menu("code", repository, Some(branch), pathList.isEmpty, groupNames.isEmpty, info, error){
|
||||
<div class="head">
|
||||
<div class="pull-right">
|
||||
@if(pathList.nonEmpty){
|
||||
<a href="@url(repository)/commits/@encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-mini" data-toggle="tooltip" data-placement="bottom" title="Browse commits for this branch"><i class="icon icon-time"></i></a>
|
||||
}
|
||||
</div>
|
||||
@branchPullRequest.map{ case (pullRequest, issue) =>
|
||||
<a href="@url(repository)/pull/@pullRequest.issueId" class="btn btn-pullrequest-branch btn-mini" title="@issue.title" data-toggle="tooltip">#@pullRequest.issueId</a>
|
||||
}.getOrElse{
|
||||
<a href="@url(repository)/compare?head=@urlEncode(encodeRefName(branch))" class="btn btn-success btn-mini"><i class="icon-white icon-retweet" data-toggle="tooltip" title="Compare, review, create a pull request"></i></a>
|
||||
}
|
||||
@helper.html.branchcontrol(
|
||||
branch,
|
||||
repository,
|
||||
|
||||
@@ -701,6 +701,12 @@ span.simplified-path {
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
.btn-pullrequest-branch{
|
||||
background: none;
|
||||
border: 1px solid #0088cc;
|
||||
color: #0088cc;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* nav pulls group */
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -29,6 +29,9 @@ DAMAGE.
|
||||
***/
|
||||
/* Author: Chas Emerick <cemerick@snowtide.com> */
|
||||
__whitespace = {" ":true, "\t":true, "\n":true, "\f":true, "\r":true};
|
||||
function __hasOwnProperty(obj, target){
|
||||
return Object.prototype.hasOwnProperty.call(obj, target);
|
||||
}
|
||||
|
||||
difflib = {
|
||||
defaultJunkFunction: function (c) {
|
||||
@@ -93,7 +96,7 @@ difflib = {
|
||||
|
||||
// replacement for python's dict.get function -- need easy default values
|
||||
__dictget: function (dict, key, defaultValue) {
|
||||
return dict.hasOwnProperty(key) ? dict[key] : defaultValue;
|
||||
return __hasOwnProperty(dict, key) ? dict[key] : defaultValue;
|
||||
},
|
||||
|
||||
SequenceMatcher: function (a, b, isjunk) {
|
||||
@@ -122,7 +125,7 @@ difflib = {
|
||||
var populardict = {};
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
var elt = b[i];
|
||||
if (b2j.hasOwnProperty(elt)) {
|
||||
if (__hasOwnProperty(b2j, elt)) {
|
||||
var indices = b2j[elt];
|
||||
if (n >= 200 && indices.length * 100 > n) {
|
||||
populardict[elt] = 1;
|
||||
@@ -151,7 +154,7 @@ difflib = {
|
||||
}
|
||||
}
|
||||
for (var elt in b2j) {
|
||||
if (b2j.hasOwnProperty(elt) && isjunk(elt)) {
|
||||
if (__hasOwnProperty(b2j, elt) && isjunk(elt)) {
|
||||
junkdict[elt] = 1;
|
||||
delete b2j[elt];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.model._
|
||||
import gitbucket.core.model.Profile._
|
||||
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class PullRequestServiceSpec extends Specification with ServiceSpecBase with PullRequestService with IssuesService {
|
||||
def swap(r: (Issue, PullRequest)) = (r._2 -> r._1)
|
||||
"PullRequestService.getPullRequestFromBranch" should {
|
||||
"""
|
||||
|return pull request if exists pull request from `branch` to `defaultBranch` and not closed.
|
||||
|return pull request if exists pull request from `branch` to othre branch and not closed.
|
||||
|return None if all pull request is closed""".stripMargin.trim in { withTestDB { implicit se =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
generateNewUserWithDBRepository("user2", "repo1")
|
||||
generateNewPullRequest("user1/repo1/master", "user1/repo1/head2") // not target branch
|
||||
generateNewPullRequest("user1/repo1/head1", "user1/repo1/master") // not target branch ( swap from, to )
|
||||
generateNewPullRequest("user1/repo1/master", "user2/repo1/head1") // othre user
|
||||
generateNewPullRequest("user1/repo1/master", "user1/repo2/head1") // othre repository
|
||||
val r1 = swap(generateNewPullRequest("user1/repo1/master2", "user1/repo1/head1"))
|
||||
val r2 = swap(generateNewPullRequest("user1/repo1/master", "user1/repo1/head1"))
|
||||
val r3 = swap(generateNewPullRequest("user1/repo1/master4", "user1/repo1/head1"))
|
||||
getPullRequestFromBranch("user1", "repo1", "head1", "master") must_== Some(r2)
|
||||
updateClosed("user1", "repo1", r2._1.issueId, true)
|
||||
getPullRequestFromBranch("user1", "repo1", "head1", "master").get must beOneOf(r1, r2)
|
||||
updateClosed("user1", "repo1", r1._1.issueId, true)
|
||||
updateClosed("user1", "repo1", r3._1.issueId, true)
|
||||
getPullRequestFromBranch("user1", "repo1", "head1", "master") must beNone
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -32,23 +32,25 @@ trait ServiceSpecBase {
|
||||
|
||||
def generateNewAccount(name:String)(implicit s:Session):Account = {
|
||||
AccountService.createAccount(name, name, name, s"${name}@example.com", false, None)
|
||||
AccountService.getAccountByUserName(name).get
|
||||
user(name)
|
||||
}
|
||||
|
||||
def user(name:String)(implicit s:Session):Account = AccountService.getAccountByUserName(name).get
|
||||
|
||||
lazy val dummyService = new RepositoryService with AccountService with IssuesService with PullRequestService
|
||||
with CommitStatusService (){}
|
||||
|
||||
def generateNewUserWithDBRepository(userName:String, repositoryName:String)(implicit s:Session):Account = {
|
||||
val ac = generateNewAccount(userName)
|
||||
val ac = AccountService.getAccountByUserName(userName).getOrElse(generateNewAccount(userName))
|
||||
dummyService.createRepository(repositoryName, userName, None, false)
|
||||
ac
|
||||
}
|
||||
|
||||
def generateNewIssue(userName:String, repositoryName:String, requestUserName:String="root")(implicit s:Session): Int = {
|
||||
def generateNewIssue(userName:String, repositoryName:String, loginUser:String="root")(implicit s:Session): Int = {
|
||||
dummyService.createIssue(
|
||||
owner = userName,
|
||||
repository = repositoryName,
|
||||
loginUser = requestUserName,
|
||||
loginUser = loginUser,
|
||||
title = "issue title",
|
||||
content = None,
|
||||
assignedUserName = None,
|
||||
@@ -56,10 +58,10 @@ trait ServiceSpecBase {
|
||||
isPullRequest = true)
|
||||
}
|
||||
|
||||
def generateNewPullRequest(base:String, request:String)(implicit s:Session):(Issue, PullRequest) = {
|
||||
def generateNewPullRequest(base:String, request:String, loginUser:String=null)(implicit s:Session):(Issue, PullRequest) = {
|
||||
val Array(baseUserName, baseRepositoryName, baesBranch)=base.split("/")
|
||||
val Array(requestUserName, requestRepositoryName, requestBranch)=request.split("/")
|
||||
val issueId = generateNewIssue(baseUserName, baseRepositoryName, requestUserName)
|
||||
val issueId = generateNewIssue(baseUserName, baseRepositoryName, Option(loginUser).getOrElse(requestUserName))
|
||||
dummyService.createPullRequest(
|
||||
originUserName = baseUserName,
|
||||
originRepositoryName = baseRepositoryName,
|
||||
|
||||
@@ -11,9 +11,10 @@ class WebHookServiceSpec extends Specification with ServiceSpecBase {
|
||||
val user1 = generateNewUserWithDBRepository("user1","repo1")
|
||||
val user2 = generateNewUserWithDBRepository("user2","repo2")
|
||||
val user3 = generateNewUserWithDBRepository("user3","repo3")
|
||||
val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2")
|
||||
val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2")
|
||||
val (issue32, pullreq32) = generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2")
|
||||
val issueUser = user("root")
|
||||
val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2", loginUser="root")
|
||||
val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2", loginUser="root")
|
||||
val (issue32, pullreq32) = generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2", loginUser="root")
|
||||
generateNewPullRequest("user2/repo2/master2", "user1/repo1/master2")
|
||||
service.addWebHookURL("user1", "repo1", "webhook1-1")
|
||||
service.addWebHookURL("user1", "repo1", "webhook1-2")
|
||||
@@ -25,18 +26,19 @@ class WebHookServiceSpec extends Specification with ServiceSpecBase {
|
||||
service.getPullRequestsByRequestForWebhook("user1","repo1","master1") must_== Map.empty
|
||||
|
||||
var r = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet)
|
||||
|
||||
r.size must_== 3
|
||||
r((issue1, pullreq1, user1, user2)) must_== Set("webhook1-1","webhook1-2")
|
||||
r((issue3, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r((issue32, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r((issue1, issueUser, pullreq1, user1, user2)) must_== Set("webhook1-1","webhook1-2")
|
||||
r((issue3, issueUser, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r((issue32, issueUser, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
|
||||
// when closed, it not founds.
|
||||
service.updateClosed("user1","repo1",issue1.issueId, true)
|
||||
|
||||
var r2 = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet)
|
||||
r2.size must_== 2
|
||||
r2((issue3, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r2((issue32, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r2((issue3, issueUser, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
r2((issue32, issueUser, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2")
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -90,4 +90,14 @@ class JGitUtilSpec extends Specification {
|
||||
list("master", "dir/subdir") mustEqual List(("File3.md", "commit7", false), ("File4.md", "commit4", false))
|
||||
}
|
||||
}
|
||||
}
|
||||
"getFileList subfolder multi-origin (issue #721)" should {
|
||||
withTestRepository { git =>
|
||||
def list(branch: String, path: String) =
|
||||
JGitUtil.getFileList(git, branch, path).map(finfo => (finfo.name, finfo.message, finfo.isDirectory))
|
||||
createFile(git, "master", "README.md", "body1", message = "commit1")
|
||||
createFile(git, "branch", "test/text2.txt", "body2", message = "commit2")
|
||||
mergeAndCommit(git, "master", "branch", message = "merge3")
|
||||
list("master", "test") mustEqual List(("text2.txt", "commit2", false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ class AvatarImageProviderSpec extends Specification with Mockito {
|
||||
isCreateRepoOptionPublic = true,
|
||||
gravatar = useGravatar,
|
||||
notification = false,
|
||||
activityLogLimit = None,
|
||||
ssh = false,
|
||||
sshPort = None,
|
||||
smtp = None,
|
||||
|
||||
Reference in New Issue
Block a user