diff --git a/build.sbt b/build.sbt index afb502a..dadafbd 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ val Organization = "io.github.gitbucket" val Name = "gitbucket" val GitBucketVersion = "4.9.0" -val ScalatraVersion = "2.4.1" +val ScalatraVersion = "2.5.0" val JettyVersion = "9.3.9.v20160517" lazy val root = (project in file(".")).enablePlugins(SbtTwirl, JettyPlugin) @@ -10,7 +10,7 @@ organization := Organization name := Name version := GitBucketVersion -scalaVersion := "2.11.8" +scalaVersion := "2.12.0" // dependency settings resolvers ++= Seq( @@ -21,45 +21,46 @@ "amateras-snapshot" at "http://amateras.sourceforge.jp/mvn-snapshot/" ) libraryDependencies ++= Seq( - "org.scala-lang.modules" %% "scala-java8-compat" % "0.7.0", - "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.6.0.201612231935-r", - "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.6.0.201612231935-r", - "org.scalatra" %% "scalatra" % ScalatraVersion, - "org.scalatra" %% "scalatra-json" % ScalatraVersion, - "org.json4s" %% "json4s-jackson" % "3.3.0", - "io.github.gitbucket" %% "scalatra-forms" % "1.0.0", - "commons-io" % "commons-io" % "2.4", - "io.github.gitbucket" % "solidbase" % "1.0.0", - "io.github.gitbucket" % "markedj" % "1.0.9", - "org.apache.commons" % "commons-compress" % "1.11", - "org.apache.commons" % "commons-email" % "1.4", - "org.apache.httpcomponents" % "httpclient" % "4.5.1", - "org.apache.sshd" % "apache-sshd" % "1.2.0", - "org.apache.tika" % "tika-core" % "1.13", - "com.typesafe.slick" %% "slick" % "2.1.0", - "com.novell.ldap" % "jldap" % "2009-10-07", - "com.h2database" % "h2" % "1.4.192", - "mysql" % "mysql-connector-java" % "5.1.39", - "org.postgresql" % "postgresql" % "9.4.1208", - "ch.qos.logback" % "logback-classic" % "1.1.7", - "com.zaxxer" % "HikariCP" % "2.4.6", - "com.typesafe" % "config" % "1.3.0", - "com.typesafe.akka" %% "akka-actor" % "2.3.15", - "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.0.0", - "com.github.bkromhout" % "java-diff-utils" % "2.1.1", - "org.cache2k" % "cache2k-all" % "1.0.0.CR1", - "com.enragedginger" %% "akka-quartz-scheduler" % "1.4.0-akka-2.3.x" exclude("c3p0","c3p0"), - "net.coobird" % "thumbnailator" % "0.4.8", - "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided", - "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided", - "junit" % "junit" % "4.12" % "test", - "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test", - "com.wix" % "wix-embedded-mysql" % "2.1.4" % "test", - "ru.yandex.qatools.embed" % "postgresql-embedded" % "1.14" % "test" + "org.scala-lang.modules" %% "scala-java8-compat" % "0.8.0", + "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.6.0.201612231935-r", + "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.6.0.201612231935-r", + "org.scalatra" %% "scalatra" % ScalatraVersion, + "org.scalatra" %% "scalatra-json" % ScalatraVersion, + "org.json4s" %% "json4s-jackson" % "3.5.0", + "io.github.gitbucket" %% "scalatra-forms" % "1.1.0", + "commons-io" % "commons-io" % "2.4", + "io.github.gitbucket" % "solidbase" % "1.0.0", + "io.github.gitbucket" % "markedj" % "1.0.9", + "org.apache.commons" % "commons-compress" % "1.11", + "org.apache.commons" % "commons-email" % "1.4", + "org.apache.httpcomponents" % "httpclient" % "4.5.1", + "org.apache.sshd" % "apache-sshd" % "1.2.0", + "org.apache.tika" % "tika-core" % "1.13", + "com.github.takezoe" %% "blocking-slick-32" % "0.0.7", + "joda-time" % "joda-time" % "2.9.6", + "com.novell.ldap" % "jldap" % "2009-10-07", + "com.h2database" % "h2" % "1.4.192", + "mysql" % "mysql-connector-java" % "5.1.39", + "org.postgresql" % "postgresql" % "9.4.1208", + "ch.qos.logback" % "logback-classic" % "1.1.7", + "com.zaxxer" % "HikariCP" % "2.4.6", + "com.typesafe" % "config" % "1.3.0", + "com.typesafe.akka" %% "akka-actor" % "2.4.12", + "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.0.0", + "com.github.bkromhout" % "java-diff-utils" % "2.1.1", + "org.cache2k" % "cache2k-all" % "1.0.0.CR1", + "com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x" exclude("c3p0","c3p0"), + "net.coobird" % "thumbnailator" % "0.4.8", + "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided", + "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided", + "junit" % "junit" % "4.12" % "test", + "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test", + "com.wix" % "wix-embedded-mysql" % "2.1.4" % "test", + "ru.yandex.qatools.embed" % "postgresql-embedded" % "1.14" % "test" ) // Compiler settings -scalacOptions := Seq("-deprecation", "-language:postfixOps", "-Ybackend:GenBCode", "-Ydelambdafy:method", "-target:jvm-1.8") +scalacOptions := Seq("-deprecation", "-language:postfixOps", "-Ydelambdafy:method", "-target:jvm-1.8") javacOptions in compile ++= Seq("-target", "8", "-source", "8") javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml" diff --git a/project/build.properties b/project/build.properties index 35c88ba..27e88aa 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.12 +sbt.version=0.13.13 diff --git a/project/plugins.sbt b/project/plugins.sbt index 07a7ebe..0ec8f00 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,8 +1,8 @@ scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature") -addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.4") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0") -addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.1.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.0") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3") +addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.1.1") addSbtPlugin("fi.gekkio.sbtplugins" % "sbt-jrebel-plugin" % "0.10.0") addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15") diff --git a/src/main/scala/gitbucket/core/model/AccessToken.scala b/src/main/scala/gitbucket/core/model/AccessToken.scala index de29857..a460b90 100644 --- a/src/main/scala/gitbucket/core/model/AccessToken.scala +++ b/src/main/scala/gitbucket/core/model/AccessToken.scala @@ -2,7 +2,8 @@ trait AccessTokenComponent { self: Profile => - import profile.simple._ + import profile.api._ + lazy val AccessTokens = TableQuery[AccessTokens] class AccessTokens(tag: Tag) extends Table[AccessToken](tag, "ACCESS_TOKEN") { diff --git a/src/main/scala/gitbucket/core/model/Account.scala b/src/main/scala/gitbucket/core/model/Account.scala index aa0d553..1f4931e 100644 --- a/src/main/scala/gitbucket/core/model/Account.scala +++ b/src/main/scala/gitbucket/core/model/Account.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait AccountComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val Accounts = TableQuery[Accounts] diff --git a/src/main/scala/gitbucket/core/model/Activity.scala b/src/main/scala/gitbucket/core/model/Activity.scala index 0f49ee3..8c5b8bd 100644 --- a/src/main/scala/gitbucket/core/model/Activity.scala +++ b/src/main/scala/gitbucket/core/model/Activity.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait ActivityComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val Activities = TableQuery[Activities] diff --git a/src/main/scala/gitbucket/core/model/BasicTemplate.scala b/src/main/scala/gitbucket/core/model/BasicTemplate.scala index 53388fc..c3b8e1b 100644 --- a/src/main/scala/gitbucket/core/model/BasicTemplate.scala +++ b/src/main/scala/gitbucket/core/model/BasicTemplate.scala @@ -1,7 +1,7 @@ package gitbucket.core.model protected[model] trait TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ trait BasicTemplate { self: Table[_] => val userName = column[String]("USER_NAME") @@ -10,7 +10,7 @@ def byRepository(owner: String, repository: String) = (userName === owner.bind) && (repositoryName === repository.bind) - def byRepository(userName: Column[String], repositoryName: Column[String]) = + def byRepository(userName: Rep[String], repositoryName: Rep[String]) = (this.userName === userName) && (this.repositoryName === repositoryName) } @@ -20,7 +20,7 @@ def byIssue(owner: String, repository: String, issueId: Int) = byRepository(owner, repository) && (this.issueId === issueId.bind) - def byIssue(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = + def byIssue(userName: Rep[String], repositoryName: Rep[String], issueId: Rep[Int]) = byRepository(userName, repositoryName) && (this.issueId === issueId) } @@ -31,7 +31,7 @@ def byLabel(owner: String, repository: String, labelId: Int) = byRepository(owner, repository) && (this.labelId === labelId.bind) - def byLabel(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = + def byLabel(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) = byRepository(userName, repositoryName) && (this.labelId === labelId) def byLabel(owner: String, repository: String, labelName: String) = @@ -44,7 +44,7 @@ def byMilestone(owner: String, repository: String, milestoneId: Int) = byRepository(owner, repository) && (this.milestoneId === milestoneId.bind) - def byMilestone(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = + def byMilestone(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) = byRepository(userName, repositoryName) && (this.milestoneId === milestoneId) } @@ -54,13 +54,13 @@ def byCommit(owner: String, repository: String, commitId: String) = byRepository(owner, repository) && (this.commitId === commitId) - def byCommit(owner: Column[String], repository: Column[String], commitId: Column[String]) = + def byCommit(owner: Rep[String], repository: Rep[String], commitId: Rep[String]) = byRepository(userName, repositoryName) && (this.commitId === commitId) } trait BranchTemplate extends BasicTemplate{ self: Table[_] => val branch = column[String]("BRANCH") def byBranch(owner: String, repository: String, branchName: String) = byRepository(owner, repository) && (branch === branchName.bind) - def byBranch(owner: Column[String], repository: Column[String], branchName: Column[String]) = byRepository(owner, repository) && (this.branch === branchName) + def byBranch(owner: Rep[String], repository: Rep[String], branchName: Rep[String]) = byRepository(owner, repository) && (this.branch === branchName) } } diff --git a/src/main/scala/gitbucket/core/model/Collaborator.scala b/src/main/scala/gitbucket/core/model/Collaborator.scala index c810613..3cee46b 100644 --- a/src/main/scala/gitbucket/core/model/Collaborator.scala +++ b/src/main/scala/gitbucket/core/model/Collaborator.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait CollaboratorComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ lazy val Collaborators = TableQuery[Collaborators] @@ -37,4 +37,4 @@ // // def valueOf(name: String): Option[Permission] = map.get(name) -} \ No newline at end of file +} diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index cab001c..310be7e 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -6,12 +6,10 @@ } trait IssueCommentComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ - lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){ - def autoInc = this returning this.map(_.commentId) - } + lazy val IssueComments = TableQuery[IssueComments] class IssueComments(tag: Tag) extends Table[IssueComment](tag, "ISSUE_COMMENT") with IssueTemplate { val commentId = column[Int]("COMMENT_ID", O AutoInc) @@ -39,12 +37,10 @@ ) extends Comment trait CommitCommentComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ - lazy val CommitComments = new TableQuery(tag => new CommitComments(tag)){ - def autoInc = this returning this.map(_.commentId) - } + lazy val CommitComments = TableQuery[CommitComments] class CommitComments(tag: Tag) extends Table[CommitComment](tag, "COMMIT_COMMENT") with CommitTemplate { val commentId = column[Int]("COMMENT_ID", O AutoInc) diff --git a/src/main/scala/gitbucket/core/model/CommitStatus.scala b/src/main/scala/gitbucket/core/model/CommitStatus.scala index f108403..4bb01e0 100644 --- a/src/main/scala/gitbucket/core/model/CommitStatus.scala +++ b/src/main/scala/gitbucket/core/model/CommitStatus.scala @@ -1,9 +1,7 @@ package gitbucket.core.model -import scala.slick.jdbc._ - trait CommitStatusComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name , i => CommitState(i)) @@ -89,7 +87,5 @@ } } - implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<)) - implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.< - import profile.simple._ + import profile.api._ lazy val GroupMembers = TableQuery[GroupMembers] diff --git a/src/main/scala/gitbucket/core/model/Issue.scala b/src/main/scala/gitbucket/core/model/Issue.scala index 24568d3..fd7a5ce 100644 --- a/src/main/scala/gitbucket/core/model/Issue.scala +++ b/src/main/scala/gitbucket/core/model/Issue.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait IssueComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val IssueId = TableQuery[IssueId] diff --git a/src/main/scala/gitbucket/core/model/IssueLabels.scala b/src/main/scala/gitbucket/core/model/IssueLabels.scala index c56cec7..57d3a65 100644 --- a/src/main/scala/gitbucket/core/model/IssueLabels.scala +++ b/src/main/scala/gitbucket/core/model/IssueLabels.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait IssueLabelComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ lazy val IssueLabels = TableQuery[IssueLabels] diff --git a/src/main/scala/gitbucket/core/model/Labels.scala b/src/main/scala/gitbucket/core/model/Labels.scala index 84a4e6d..a9abf8b 100644 --- a/src/main/scala/gitbucket/core/model/Labels.scala +++ b/src/main/scala/gitbucket/core/model/Labels.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait LabelComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ lazy val Labels = TableQuery[Labels] @@ -12,7 +12,7 @@ def * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply) def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId) + def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) = byLabel(userName, repositoryName, labelId) } } diff --git a/src/main/scala/gitbucket/core/model/Milestone.scala b/src/main/scala/gitbucket/core/model/Milestone.scala index 5c09b5d..81c4f2b 100644 --- a/src/main/scala/gitbucket/core/model/Milestone.scala +++ b/src/main/scala/gitbucket/core/model/Milestone.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait MilestoneComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val Milestones = TableQuery[Milestones] @@ -15,7 +15,7 @@ def * = (userName, repositoryName, milestoneId, title, description.?, dueDate.?, closedDate.?) <> (Milestone.tupled, Milestone.unapply) def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId) + def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) = byMilestone(userName, repositoryName, milestoneId) } } diff --git a/src/main/scala/gitbucket/core/model/Profile.scala b/src/main/scala/gitbucket/core/model/Profile.scala index 26bb225..ad01a4c 100644 --- a/src/main/scala/gitbucket/core/model/Profile.scala +++ b/src/main/scala/gitbucket/core/model/Profile.scala @@ -1,10 +1,11 @@ package gitbucket.core.model import gitbucket.core.util.DatabaseConfig +import com.github.takezoe.slick.blocking.BlockingJdbcProfile trait Profile { - val profile: slick.driver.JdbcProfile - import profile.simple._ + val profile: BlockingJdbcProfile + import profile.blockingApi._ /** * java.util.Date Mapped Column Types @@ -17,8 +18,8 @@ /** * Extends Column to add conditional condition */ - implicit class RichColumn(c1: Column[Boolean]){ - def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1 + implicit class RichColumn(c1: Rep[Boolean]){ + def &&(c2: => Rep[Boolean], guard: => Boolean): Rep[Boolean] = if(guard) c1 && c2 else c1 } /** diff --git a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala b/src/main/scala/gitbucket/core/model/ProtectedBranch.scala index 9679faf..b143b4f 100644 --- a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala +++ b/src/main/scala/gitbucket/core/model/ProtectedBranch.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait ProtectedBranchComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val ProtectedBranches = TableQuery[ProtectedBranches] @@ -9,7 +9,7 @@ val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN") def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply) def byPrimaryKey(userName: String, repositoryName: String, branch: String) = byBranch(userName, repositoryName, branch) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], branch: Column[String]) = byBranch(userName, repositoryName, branch) + def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) = byBranch(userName, repositoryName, branch) } lazy val ProtectedBranchContexts = TableQuery[ProtectedBranchContexts] diff --git a/src/main/scala/gitbucket/core/model/PullRequest.scala b/src/main/scala/gitbucket/core/model/PullRequest.scala index ed5acac..dba1a3f 100644 --- a/src/main/scala/gitbucket/core/model/PullRequest.scala +++ b/src/main/scala/gitbucket/core/model/PullRequest.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait PullRequestComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ lazy val PullRequests = TableQuery[PullRequests] @@ -15,7 +15,7 @@ def * = (userName, repositoryName, issueId, branch, requestUserName, requestRepositoryName, requestBranch, commitIdFrom, commitIdTo) <> (PullRequest.tupled, PullRequest.unapply) def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId) + def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], issueId: Rep[Int]) = byIssue(userName, repositoryName, issueId) } } diff --git a/src/main/scala/gitbucket/core/model/Repository.scala b/src/main/scala/gitbucket/core/model/Repository.scala index 387b8ff..66cb641 100644 --- a/src/main/scala/gitbucket/core/model/Repository.scala +++ b/src/main/scala/gitbucket/core/model/Repository.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait RepositoryComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val Repositories = TableQuery[Repositories] diff --git a/src/main/scala/gitbucket/core/model/SshKey.scala b/src/main/scala/gitbucket/core/model/SshKey.scala index fa7909e..a5a41f0 100644 --- a/src/main/scala/gitbucket/core/model/SshKey.scala +++ b/src/main/scala/gitbucket/core/model/SshKey.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait SshKeyComponent { self: Profile => - import profile.simple._ + import profile.api._ lazy val SshKeys = TableQuery[SshKeys] diff --git a/src/main/scala/gitbucket/core/model/WebHook.scala b/src/main/scala/gitbucket/core/model/WebHook.scala index d87f9cb..48de21b 100644 --- a/src/main/scala/gitbucket/core/model/WebHook.scala +++ b/src/main/scala/gitbucket/core/model/WebHook.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait WebHookComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ implicit val whContentTypeColumnType = MappedColumnType.base[WebHookContentType, String](whct => whct.code , code => WebHookContentType.valueOf(code)) @@ -9,19 +9,18 @@ class WebHooks(tag: Tag) extends Table[WebHook](tag, "WEB_HOOK") with BasicTemplate { val url = column[String]("URL") - val token = column[Option[String]]("TOKEN", O.Nullable) - val ctype = column[WebHookContentType]("CTYPE", O.NotNull) + val token = column[Option[String]]("TOKEN") + val ctype = column[WebHookContentType]("CTYPE") def * = (userName, repositoryName, url, ctype, token) <> ((WebHook.apply _).tupled, WebHook.unapply) def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url === url.bind) } } -case class WebHookContentType(val code: String, val ctype: String) +abstract sealed case class WebHookContentType(code: String, ctype: String) object WebHookContentType { object JSON extends WebHookContentType("json", "application/json") - object FORM extends WebHookContentType("form", "application/x-www-form-urlencoded") val values: Vector[WebHookContentType] = Vector(JSON, FORM) @@ -43,7 +42,8 @@ ) object WebHook { - sealed class Event(var name: String) + abstract sealed class Event(val name: String) + case object CommitComment extends Event("commit_comment") case object Create extends Event("create") case object Delete extends Event("delete") @@ -63,9 +63,30 @@ case object Status extends Event("status") case object TeamAdd extends Event("team_add") case object Watch extends Event("watch") + object Event{ - val values = List(CommitComment,Create,Delete,Deployment,DeploymentStatus,Fork,Gollum,IssueComment,Issues,Member,PageBuild,Public,PullRequest,PullRequestReviewComment,Push,Release,Status,TeamAdd,Watch) - private val map:Map[String,Event] = values.map(e => e.name -> e).toMap + val values = List( + CommitComment, + Create, + Delete, + Deployment, + DeploymentStatus, + Fork, + Gollum, + IssueComment, + Issues, + Member, + PageBuild, + Public, + PullRequest, + PullRequestReviewComment, + Push, + Release, + Status, + TeamAdd, + Watch + ) + private val map: Map[String,Event] = values.map(e => e.name -> e).toMap def valueOf(name: String): Event = map(name) def valueOpt(name: String): Option[Event] = map.get(name) } diff --git a/src/main/scala/gitbucket/core/model/WebHookEvent.scala b/src/main/scala/gitbucket/core/model/WebHookEvent.scala index cc960e7..d9f5a55 100644 --- a/src/main/scala/gitbucket/core/model/WebHookEvent.scala +++ b/src/main/scala/gitbucket/core/model/WebHookEvent.scala @@ -1,7 +1,7 @@ package gitbucket.core.model trait WebHookEventComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import gitbucket.core.model.Profile.WebHooks lazy val WebHookEvents = TableQuery[WebHookEvents] @@ -14,7 +14,7 @@ def * = (userName, repositoryName, url, event) <> ((WebHookEvent.apply _).tupled, WebHookEvent.unapply) def byWebHook(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url === url.bind) - def byWebHook(owner: Column[String], repository: Column[String], url: Column[String]) = + def byWebHook(owner: Rep[String], repository: Rep[String], url: Rep[String]) = byRepository(userName, repositoryName) && (this.url === url) def byWebHook(webhook: WebHooks) = byRepository(webhook.userName, webhook.repositoryName) && (this.url === webhook.url) diff --git a/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala b/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala index 125f6a2..7b76ecc 100644 --- a/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala +++ b/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala @@ -2,7 +2,7 @@ import gitbucket.core.model.Profile._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} -import profile.simple._ +import profile.api._ trait ReceiveHook { diff --git a/src/main/scala/gitbucket/core/plugin/Sessions.scala b/src/main/scala/gitbucket/core/plugin/Sessions.scala index dc38702..e330485 100644 --- a/src/main/scala/gitbucket/core/plugin/Sessions.scala +++ b/src/main/scala/gitbucket/core/plugin/Sessions.scala @@ -1,6 +1,6 @@ package gitbucket.core.plugin -import scala.slick.jdbc.JdbcBackend.Session +import slick.jdbc.JdbcBackend.Session /** * Provides Slick Session to Plug-ins. diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index a2345be..d9a9411 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -1,8 +1,7 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile.simple._ - +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil @@ -25,23 +24,25 @@ def generateAccessToken(userName: String, note: String)(implicit s: Session): (Int, String) = { var token: String = null var hash: String = null - do{ + + do { token = makeAccessTokenString hash = tokenToHash(token) - }while(AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + //} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + } while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) val newToken = AccessToken( userName = userName, note = note, tokenHash = hash) - val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) += newToken + val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) insert newToken (tokenId, token) } def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] = Accounts - .innerJoin(AccessTokens) - .filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } - .map{ case (ac, t) => ac } + .join(AccessTokens) + .filter { case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } + .map { case (ac, t) => ac } .firstOption def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] = diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index c69a5b2..6a4b599 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -1,14 +1,13 @@ package gitbucket.core.service +import org.slf4j.LoggerFactory import gitbucket.core.model.{GroupMember, Account} import gitbucket.core.model.Profile._ -import gitbucket.core.util.{StringUtil, LDAPUtil} -import gitbucket.core.service.SystemSettingsService.SystemSettings -import profile.simple._ -import StringUtil._ -import org.slf4j.LoggerFactory -// TODO Why is direct import required? +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.util.{StringUtil, LDAPUtil} +import StringUtil._ +import gitbucket.core.service.SystemSettingsService.SystemSettings trait AccountService { diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 618d917..433909d 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -1,9 +1,9 @@ package gitbucket.core.service import gitbucket.core.model.Activity -import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile.simple._ +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait ActivityService { @@ -15,7 +15,7 @@ def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] = Activities - .innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) + .join(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) .filter { case (t1, t2) => if(isPublic){ (t1.activityUserName === activityUserName.bind) && (t2.isPrivate === false.bind) @@ -30,7 +30,7 @@ def getRecentActivities()(implicit s: Session): List[Activity] = Activities - .innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) + .join(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) .filter { case (t1, t2) => t2.isPrivate === false.bind } .sortBy { case (t1, t2) => t1.activityId desc } .map { case (t1, t2) => t1 } @@ -39,7 +39,7 @@ def getRecentActivitiesByOwners(owners : Set[String])(implicit s: Session): List[Activity] = Activities - .innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) + .join(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) .filter { case (t1, t2) => (t2.isPrivate === false.bind) || (t2.userName inSetBind owners) } .sortBy { case (t1, t2) => t1.activityId desc } .map { case (t1, t2) => t1 } diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 1c491c9..ca24ff9 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -1,11 +1,9 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile.simple._ - -import gitbucket.core.model.{CommitState, CommitStatus, Account} -import gitbucket.core.util.Implicits._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.model.{CommitState, CommitStatus, Account} trait CommitStatusService { /** insert or update */ @@ -20,7 +18,7 @@ }.update((state, targetUrl, now, creator.userName, description)) id } - case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus( + case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) insert CommitStatus( userName = userName, repositoryName = repositoryName, commitId = sha, @@ -46,7 +44,7 @@ CommitStatuses.filter(t => t.byRepository(userName, repositoryName)).filter(t => t.updatedDate > time.bind).groupBy(_.context).map(_._1).list def getCommitStatuesWithCreator(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[(CommitStatus, Account)] = - byCommitStatues(userName, repositoryName, sha).innerJoin(Accounts).filter { case (t, a) => t.creator === a.userName }.list + byCommitStatues(userName, repositoryName, sha).join(Accounts).filter { case (t, a) => t.creator === a.userName }.list protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) = CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha)).sortBy(_.updatedDate desc) diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 36b30cd..3e28f45 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -1,12 +1,9 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment -import gitbucket.core.util.Implicits - import gitbucket.core.model.Profile._ -import profile.simple._ -import Implicits._ - +import gitbucket.core.model.Profile.profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType trait CommitsService { @@ -26,7 +23,7 @@ def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String, content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], issueId: Option[Int])(implicit s: Session): Int = - CommitComments.autoInc insert CommitComment( + CommitComments returning CommitComments.map(_.commentId) insert CommitComment( userName = owner, repositoryName = repository, commitId = commitId, @@ -45,12 +42,12 @@ (t.commitId, t.oldLine, t.newLine) }.update(commitId, oldLine, newLine) - def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = + def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = { CommitComments .filter (_.byPrimaryKey(commentId)) - .map { t => - t.content -> t.updatedDate - }.update (content, currentDate) + .map { t => (t.content, t.updatedDate) } + .update (content, currentDate) + } def deleteCommitComment(commentId: Int)(implicit s: Session) = CommitComments filter (_.byPrimaryKey(commentId)) delete diff --git a/src/main/scala/gitbucket/core/service/HandleCommentService.scala b/src/main/scala/gitbucket/core/service/HandleCommentService.scala index cc5e219..fe94605 100644 --- a/src/main/scala/gitbucket/core/service/HandleCommentService.scala +++ b/src/main/scala/gitbucket/core/service/HandleCommentService.scala @@ -3,10 +3,10 @@ import gitbucket.core.controller.Context import gitbucket.core.model.Issue import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Notifier -import profile.simple._ trait HandleCommentService { self: RepositoryService with IssuesService with ActivityService diff --git a/src/main/scala/gitbucket/core/service/IssueCreationService.scala b/src/main/scala/gitbucket/core/service/IssueCreationService.scala index de2459f..a18dad3 100644 --- a/src/main/scala/gitbucket/core/service/IssueCreationService.scala +++ b/src/main/scala/gitbucket/core/service/IssueCreationService.scala @@ -2,7 +2,7 @@ import gitbucket.core.controller.Context import gitbucket.core.model.{Account, Issue} -import gitbucket.core.model.Profile.profile.simple.Session +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.util.Notifier import gitbucket.core.util.Implicits._ diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index a07d220..d9c5898 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -1,16 +1,13 @@ package gitbucket.core.service -import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil.CommitInfo -import gitbucket.core.util.StringUtil -import profile.simple._ - import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ -import gitbucket.core.model._ - -import scala.slick.jdbc.{StaticQuery => Q} -import Q.interpolation +import gitbucket.core.model.{Issue, PullRequest, IssueComment, IssueLabel, Label, Account, Repository, CommitState, Role} +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType @@ -30,8 +27,8 @@ def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] = IssueComments.filter(_.byIssue(owner, repository, issueId)) .filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment")) - .innerJoin(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName ) - .innerJoin(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) } + .join(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName ) + .join(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) } .map{ case ((t1, t2), t3) => (t1, t2, t3) } .list @@ -48,7 +45,7 @@ def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session) = IssueLabels - .innerJoin(Labels).on { (t1, t2) => + .join(Labels).on { (t1, t2) => t1.byLabel(t2.userName, t2.repositoryName, t2.labelId) } .filter ( _._1.byIssue(owner, repository, issueId) ) @@ -82,10 +79,10 @@ filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = { searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), false) - .innerJoin(IssueLabels).on { (t1, t2) => + .join(IssueLabels).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } - .innerJoin(Labels).on { case ((t1, t2), t3) => + .join(Labels).on { case ((t1, t2), t3) => t2.byLabel(t3.userName, t3.repositoryName, t3.labelId) } .groupBy { case ((t1, t2), t3) => @@ -94,62 +91,27 @@ .map { case (labelName, t) => labelName -> t.length } - .toMap + .list.toMap } - def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] ={ - if(issueList.isEmpty){ - Map.empty + def getCommitStatues(userName: String, repositoryName: String, issueId: Int)(implicit s: Session): Option[CommitStatusInfo] = { + val status = PullRequests + .filter { pr => (pr.userName === userName.bind) && (pr.repositoryName === repositoryName.bind) && (pr.issueId === issueId.bind) } + .join(CommitStatuses).on((pr, cs) => pr.userName === cs.userName && pr.repositoryName === cs.repositoryName && pr.commitIdTo === cs.commitId) + .list + + if(status.nonEmpty){ + val (_, cs) = status.head + Some(CommitStatusInfo( + count = status.length, + successCount = status.filter(_._2.state == CommitState.SUCCESS).length, + context = (if(status.length == 1) Some(cs.context) else None), + state = (if(status.length == 1) Some(cs.state) else None), + targetUrl = (if(status.length == 1) cs.targetUrl else None), + description = (if(status.length == 1) cs.description else None) + )) } else { - import scala.slick.jdbc._ - val issueIdQuery = issueList.map(i => "(PR.USER_NAME=? AND PR.REPOSITORY_NAME=? AND PR.ISSUE_ID=?)").mkString(" OR ") - implicit val qset = SetParameter[Seq[(String, String, Int)]] { - case (seq, pp) => - for (a <- seq) { - pp.setString(a._1) - pp.setString(a._2) - pp.setInt(a._3) - } - } - val query = Q.query[Seq[(String, String, Int)], (String, String, Int, Int, Int, Option[String], Option[CommitState], Option[String], Option[String])](s""" - SELECT - SUMM.USER_NAME, - SUMM.REPOSITORY_NAME, - SUMM.ISSUE_ID, - CS_ALL, - CS_SUCCESS, - CSD.CONTEXT, - CSD.STATE, - CSD.TARGET_URL, - CSD.DESCRIPTION - FROM ( - SELECT - PR.USER_NAME, - PR.REPOSITORY_NAME, - PR.ISSUE_ID, - COUNT(CS.STATE) AS CS_ALL, - CSS.CS_SUCCESS AS CS_SUCCESS, - PR.COMMIT_ID_TO AS COMMIT_ID - FROM PULL_REQUEST PR - JOIN COMMIT_STATUS CS - ON PR.USER_NAME = CS.USER_NAME AND PR.REPOSITORY_NAME = CS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CS.COMMIT_ID - JOIN ( - SELECT - COUNT(*) AS CS_SUCCESS, - USER_NAME, - REPOSITORY_NAME, - COMMIT_ID - FROM COMMIT_STATUS WHERE STATE = 'success' GROUP BY USER_NAME, REPOSITORY_NAME, COMMIT_ID - ) CSS ON PR.USER_NAME = CSS.USER_NAME AND PR.REPOSITORY_NAME = CSS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CSS.COMMIT_ID - WHERE $issueIdQuery - GROUP BY PR.USER_NAME, PR.REPOSITORY_NAME, PR.ISSUE_ID, CSS.CS_SUCCESS - ) as SUMM - LEFT OUTER JOIN COMMIT_STATUS CSD - ON SUMM.CS_ALL = 1 AND SUMM.COMMIT_ID = CSD.COMMIT_ID"""); - query(issueList).list.map { - case(userName, repositoryName, issueId, count, successCount, context, state, targetUrl, description) => - (userName, repositoryName, issueId) -> CommitStatusInfo(count, successCount, context, state, targetUrl, description) - }.toMap + None } } @@ -167,36 +129,34 @@ (implicit s: Session): List[IssueInfo] = { // get issues and comment count and labels val result = searchIssueQueryBase(condition, pullRequest, offset, limit, repos) - .leftJoin (IssueLabels) .on { case (((t1, t2), i), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } - .leftJoin (Labels) .on { case ((((t1, t2), i), t3), t4) => t3.byLabel(t4.userName, t4.repositoryName, t4.labelId) } - .leftJoin (Milestones) .on { case (((((t1, t2), i), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } - .sortBy { case (((((t1, t2), i), t3), t4), t5) => i asc } - .map { case (((((t1, t2), i), t3), t4), t5) => (t1, t2.commentCount, t4.labelId.?, t4.labelName.?, t4.color.?, t5.title.?) } - .list - .splitWith { (c1, c2) => c1._1.userName == c2._1.userName && c1._1.repositoryName == c2._1.repositoryName && c1._1.issueId == c2._1.issueId } - - val status = getCommitStatues(result.map(_.head._1).map(is => (is.userName, is.repositoryName, is.issueId))) + .joinLeft (IssueLabels) .on { case (((t1, t2), i), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } + .joinLeft (Labels) .on { case ((((t1, t2), i), t3), t4) => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) } + .joinLeft (Milestones) .on { case (((((t1, t2), i), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } + .sortBy { case (((((t1, t2), i), t3), t4), t5) => i asc } + .map { case (((((t1, t2), i), t3), t4), t5) => + (t1, t2.commentCount, t4.map(_.labelId), t4.map(_.labelName), t4.map(_.color), t5.map(_.title)) + } + .list + .splitWith { (c1, c2) => c1._1.userName == c2._1.userName && c1._1.repositoryName == c2._1.repositoryName && c1._1.issueId == c2._1.issueId } result.map { issues => issues.head match { case (issue, commentCount, _, _, _, milestone) => IssueInfo(issue, - issues.flatMap { t => t._3.map ( - Label(issue.userName, issue.repositoryName, _, t._4.get, t._5.get) - )} toList, - milestone, - commentCount, - status.get(issue.userName, issue.repositoryName, issue.issueId)) + issues.flatMap { t => t._3.map (Label(issue.userName, issue.repositoryName, _, t._4.get, t._5.get))} toList, + milestone, + commentCount, + getCommitStatues(issue.userName, issue.repositoryName, issue.issueId)) }} toList } /** for api - * @return (issue, issueUser, commentCount) - */ + * @return (issue, issueUser, commentCount) + */ def searchIssueByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*) (implicit s: Session): List[(Issue, Account)] = { // get issues and comment count and labels searchIssueQueryBase(condition, false, offset, limit, repos) - .innerJoin(Accounts).on { case (((t1, t2), i), t3) => t3.userName === t1.openedUserName } + .join(Accounts).on { case (((t1, t2), i), t3) => t3.userName === t1.openedUserName } .sortBy { case (((t1, t2), i), t3) => i asc } .map { case (((t1, t2), i), t3) => (t1, t3) } .list @@ -209,10 +169,10 @@ (implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = { // get issues and comment count and labels searchIssueQueryBase(condition, true, offset, limit, repos) - .innerJoin(PullRequests).on { case (((t1, t2), i), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } - .innerJoin(Repositories).on { case ((((t1, t2), i), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) } - .innerJoin(Accounts).on { case (((((t1, t2), i), t3), t4), t5) => t5.userName === t1.openedUserName } - .innerJoin(Accounts).on { case ((((((t1, t2), i), t3), t4), t5), t6) => t6.userName === t4.userName } + .join(PullRequests).on { case (((t1, t2), i), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } + .join(Repositories).on { case ((((t1, t2), i), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) } + .join(Accounts).on { case (((((t1, t2), i), t3), t4), t5) => t5.userName === t1.openedUserName } + .join(Accounts).on { case ((((((t1, t2), i), t3), t4), t5), t6) => t6.userName === t4.userName } .sortBy { case ((((((t1, t2), i), t3), t4), t5), t6) => i asc } .map { case ((((((t1, t2), i), t3), t4), t5), t6) => (t1, t5, t2.commentCount, t3, t4, t6) } .list @@ -221,17 +181,21 @@ private def searchIssueQueryBase(condition: IssueSearchCondition, pullRequest: Boolean, offset: Int, limit: Int, repos: Seq[(String, String)]) (implicit s: Session) = searchIssueQuery(repos, condition, pullRequest) - .innerJoin(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } + .join(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } .sortBy { case (t1, t2) => t1.issueId desc } .sortBy { case (t1, t2) => - (condition.sort match { - case "created" => t1.registeredDate - case "comments" => t2.commentCount - case "updated" => t1.updatedDate - }) match { - case sort => condition.direction match { - case "asc" => sort asc - case "desc" => sort desc + condition.sort match { + case "created" => condition.direction match { + case "asc" => t1.registeredDate asc + case "desc" => t1.registeredDate desc + } + case "comments" => condition.direction match { + case "asc" => t2.commentCount asc + case "desc" => t2.commentCount desc + } + case "updated" => condition.direction match { + case "asc" => t1.updatedDate asc + case "desc" => t1.updatedDate desc } } } @@ -245,7 +209,7 @@ Issues filter { t1 => repos .map { case (owner, repository) => t1.byRepository(owner, repository) } - .foldLeft[Column[Boolean]](false) ( _ || _ ) && + .foldLeft[Rep[Boolean]](false) ( _ || _ ) && (t1.closed === (condition.state == "closed").bind) && (t1.milestoneId.? isEmpty, condition.milestone == Some(None)) && (t1.assignedUserName.? isEmpty, condition.assigned == Some(None)) && @@ -315,25 +279,24 @@ IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) delete def createComment(owner: String, repository: String, loginUser: String, - issueId: Int, content: String, action: String)(implicit s: Session): Int = - IssueComments.autoInc insert IssueComment( - userName = owner, - repositoryName = repository, - issueId = issueId, - action = action, - commentedUserName = loginUser, - content = content, - registeredDate = currentDate, - updatedDate = currentDate) + issueId: Int, content: String, action: String)(implicit s: Session): Int = { + IssueComments returning IssueComments.map(_.commentId) insert IssueComment( + userName = owner, + repositoryName = repository, + issueId = issueId, + action = action, + commentedUserName = loginUser, + content = content, + registeredDate = currentDate, + updatedDate = currentDate) + } - def updateIssue(owner: String, repository: String, issueId: Int, - title: String, content: Option[String])(implicit s: Session) = + def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session) = { Issues .filter (_.byPrimaryKey(owner, repository, issueId)) - .map { t => - (t.title, t.content.?, t.updatedDate) - } + .map { t => (t.title, t.content.?, t.updatedDate) } .update (title, content, currentDate) + } def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session) = @@ -343,24 +306,16 @@ milestoneId: Option[Int])(implicit s: Session) = Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).update (milestoneId) - def updateComment(commentId: Int, content: String)(implicit s: Session) = - IssueComments - .filter (_.byPrimaryKey(commentId)) - .map { t => - t.content -> t.updatedDate - } - .update (content, currentDate) + def updateComment(commentId: Int, content: String)(implicit s: Session) = { + IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate) + } def deleteComment(commentId: Int)(implicit s: Session) = IssueComments filter (_.byPrimaryKey(commentId)) delete - def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = - Issues - .filter (_.byPrimaryKey(owner, repository, issueId)) - .map { t => - t.closed -> t.updatedDate - } - .update (closed, currentDate) + def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = { + (Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).update((closed, currentDate)) + } /** * Search issues by keyword. @@ -372,13 +327,13 @@ */ def searchIssuesByKeyword(owner: String, repository: String, query: String) (implicit s: Session): List[(Issue, Int, String)] = { - import slick.driver.JdbcDriver.likeEncode + //import slick.driver.JdbcDriver.likeEncode val keywords = splitWords(query.toLowerCase) // Search Issue val issues = Issues .filter(_.byRepository(owner, repository)) - .innerJoin(IssueOutline).on { case (t1, t2) => + .join(IssueOutline).on { case (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => @@ -394,10 +349,10 @@ // Search IssueComment val comments = IssueComments .filter(_.byRepository(owner, repository)) - .innerJoin(Issues).on { case (t1, t2) => + .join(Issues).on { case (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } - .innerJoin(IssueOutline).on { case ((t1, t2), t3) => + .join(IssueOutline).on { case ((t1, t2), t3) => t2.byIssue(t3.userName, t3.repositoryName, t3.issueId) } .filter { case ((t1, t2), t3) => @@ -429,7 +384,7 @@ } def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session) = { - StringUtil.extractIssueId(message).foreach { issueId => + extractIssueId(message).foreach { issueId => val content = fromIssue.issueId + ":" + fromIssue.title if(getIssue(owner, repository, issueId).isDefined){ // Not add if refer comment already exist. @@ -441,7 +396,7 @@ } def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session) = { - StringUtil.extractIssueId(commit.fullMessage).foreach { issueId => + extractIssueId(commit.fullMessage).foreach { issueId => if(getIssue(owner, repository, issueId).isDefined){ getAccountByMailAddress(commit.committerEmailAddress).foreach { account => createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit") @@ -501,6 +456,7 @@ case ("comments", "asc" ) => Some("sort:comments-asc") case ("updated" , "desc") => Some("sort:updated-desc") case ("updated" , "asc" ) => Some("sort:updated-asc") + case x => throw new MatchError(x) }, visibility.map(visibility => s"visibility:${visibility}") ).flatten ++ diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index f8026e0..e95fa06 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -2,7 +2,7 @@ import gitbucket.core.model.Label import gitbucket.core.model.Profile._ -import profile.simple._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait LabelsService { @@ -15,13 +15,14 @@ def getLabel(owner: String, repository: String, labelName: String)(implicit s: Session): Option[Label] = Labels.filter(_.byLabel(owner, repository, labelName)).firstOption - def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Int = - Labels returning Labels.map(_.labelId) += Label( + def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Int = { + Labels returning Labels.map(_.labelId) insert Label( userName = owner, repositoryName = repository, labelName = labelName, color = color ) + } def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String) (implicit s: Session): Unit = diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index 598c3ce..1e95856 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -2,8 +2,7 @@ import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ -import profile.simple._ -// TODO Why is direct import required? +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait MilestonesService { @@ -44,6 +43,7 @@ .filter { t => t.byRepository(owner, repository) && (t.milestoneId.? isDefined) } .groupBy { t => t.milestoneId -> t.closed } .map { case (t1, t2) => t1._1 -> t1._2 -> t2.length } + .list .toMap getMilestones(owner, repository).map { milestone => diff --git a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala index 07cbb2a..577b843 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -1,9 +1,9 @@ package gitbucket.core.service -import gitbucket.core.model._ -import gitbucket.core.model.Profile._ +import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitState} import gitbucket.core.plugin.ReceiveHook -import profile.simple._ +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} @@ -12,14 +12,14 @@ import ProtectedBranchService._ private def getProtectedBranchInfoOpt(owner: String, repository: String, branch: String)(implicit session: Session): Option[ProtectedBranchInfo] = ProtectedBranches - .leftJoin(ProtectedBranchContexts) - .on{ case (pb, c) => pb.byBranch(c.userName, c.repositoryName, c.branch) } - .map{ case (pb, c) => pb -> c.context.? } + .joinLeft(ProtectedBranchContexts) + .on { case (pb, c) => pb.byBranch(c.userName, c.repositoryName, c.branch) } + .map { case (pb, c) => pb -> c.map(_.context) } .filter(_._1.byPrimaryKey(owner, repository, branch)) .list .groupBy(_._1) - .map(p => p._1 -> p._2.flatMap(_._2)) - .map{ case (t1, contexts) => + .map { p => p._1 -> p._2.flatMap(_._2) } + .map { case (t1, contexts) => new ProtectedBranchInfo(t1.userName, t1.repositoryName, true, contexts, t1.statusCheckAdmin) }.headOption diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index cbd3df0..a512d2c 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -1,8 +1,9 @@ package gitbucket.core.service -import difflib.{Delta, DiffUtils} -import gitbucket.core.model.{Session => _, _} +import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState, CommitComment} import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ +import difflib.{Delta, DiffUtils} import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ @@ -11,8 +12,6 @@ import gitbucket.core.view import gitbucket.core.view.helpers import org.eclipse.jgit.api.Git -import profile.simple._ - import scala.collection.JavaConverters._ @@ -36,7 +35,7 @@ def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String]) (implicit s: Session): List[PullRequestCount] = PullRequests - .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } + .join(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => (t2.closed === closed.bind) && (t1.userName === owner.get.bind, owner.isDefined) && @@ -83,7 +82,7 @@ def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Boolean) (implicit s: Session): List[PullRequest] = PullRequests - .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } + .join(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => (t1.requestUserName === userName.bind) && (t1.requestRepositoryName === repositoryName.bind) && @@ -103,7 +102,7 @@ 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) } + .join(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => (t1.requestUserName === userName.bind) && (t1.requestRepositoryName === repositoryName.bind) && @@ -151,7 +150,7 @@ None } else { PullRequests - .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } + .join(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => (t1.userName === userName.bind) && (t1.repositoryName === repositoryName.bind) && diff --git a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala index 04aef50..c040851 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -1,6 +1,6 @@ package gitbucket.core.service -import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Directory._ import gitbucket.core.util.JGitUtil @@ -8,7 +8,6 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib.{FileMode, Constants} -import profile.simple._ trait RepositoryCreationService { self: AccountService with RepositoryService with LabelsService with WikiService with ActivityService => diff --git a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala index bba7172..a104414 100644 --- a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala +++ b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala @@ -9,8 +9,7 @@ import org.eclipse.jgit.treewalk.TreeWalk import org.eclipse.jgit.lib.FileMode import org.eclipse.jgit.api.Git -import gitbucket.core.model.Profile._ -import profile.simple._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait RepositorySearchService { self: IssuesService => import RepositorySearchService._ diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 1fee8f7..85d6832 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -1,17 +1,14 @@ package gitbucket.core.service import gitbucket.core.controller.Context -import gitbucket.core.model.{Collaborator, Repository, RepositoryOptions, Account, Role} -import gitbucket.core.model.Profile._ -import gitbucket.core.plugin.PluginRegistry -import gitbucket.core.util.JGitUtil -import gitbucket.core.util.JGitUtil.FileInfo +import gitbucket.core.util._ import gitbucket.core.util.ControlUtil._ -import gitbucket.core.util.Directory -import gitbucket.core.util.FileUtil -import gitbucket.core.util.StringUtil +import gitbucket.core.model.{Account, Collaborator, Repository, RepositoryOptions, Role} +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.util.JGitUtil.FileInfo import org.eclipse.jgit.api.Git -import profile.simple._ trait RepositoryService { self: AccountService => import RepositoryService._ @@ -129,6 +126,11 @@ userName = newUserName, repositoryName = newRepositoryName )) :_*) + IssueLabels.insertAll(issueLabels.map(x => x.copy( + labelId = newLabelMap(oldLabelMap(x.labelId)), + userName = newUserName, + repositoryName = newRepositoryName + )) :_*) // TODO Drop transfered owner from collaborators? Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) @@ -248,8 +250,7 @@ }.list } - def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false) - (implicit s: Session): List[RepositoryInfo] = { + def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false)(implicit s: Session): List[RepositoryInfo] = { Repositories.filter { t1 => (t1.userName === userName.bind) || (t1.userName in (GroupMembers.filter(_.userName === userName.bind).map(_.groupName))) || (Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && @@ -327,8 +328,9 @@ /** * Updates the last activity date of the repository. */ - def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit = + def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit = { Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate) + } /** * Save repository options. @@ -365,7 +367,7 @@ */ def getCollaborators(userName: String, repositoryName: String)(implicit s: Session): List[(Collaborator, Boolean)] = Collaborators - .innerJoin(Accounts).on(_.collaboratorName === _.userName) + .join(Accounts).on(_.collaboratorName === _.userName) .filter { case (t1, t2) => t1.byRepository(userName, repositoryName) } .map { case (t1, t2) => (t1, t2.groupAccount) } .sortBy { case (t1, t2) => t1.collaboratorName } @@ -377,13 +379,13 @@ */ def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Role] = Nil)(implicit s: Session): List[String] = { val q1 = Collaborators - .innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === false.bind) } + .join(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === false.bind) } .filter { case (t1, t2) => t1.byRepository(userName, repositoryName) } .map { case (t1, t2) => (t1.collaboratorName, t1.role) } val q2 = Collaborators - .innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === true.bind) } - .innerJoin(GroupMembers).on { case ((t1, t2), t3) => t2.userName === t3.groupName } + .join(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === true.bind) } + .join(GroupMembers).on { case ((t1, t2), t3) => t2.userName === t3.groupName } .filter { case ((t1, t2), t3) => t1.byRepository(userName, repositoryName) } .map { case ((t1, t2), t3) => (t3.userName, t1.role) } diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index 5feb119..477413f 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -2,7 +2,7 @@ import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ -import profile.simple._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait SshKeyService { diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index ad3a304..2f060de 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -5,8 +5,8 @@ import gitbucket.core.api._ import gitbucket.core.model.{Account, CommitComment, Issue, IssueComment, PullRequest, WebHook, WebHookEvent} import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.apache.http.client.utils.URLEncodedUtils -import profile.simple._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.RepositoryName import gitbucket.core.service.RepositoryService.RepositoryInfo @@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory import scala.concurrent._ +import scala.util.{Success, Failure} import org.apache.http.HttpRequest import org.apache.http.HttpResponse import gitbucket.core.model.WebHookContentType @@ -33,24 +34,24 @@ /** get All WebHook informations of repository */ def getWebHooks(owner: String, repository: String)(implicit s: Session): List[(WebHook, Set[WebHook.Event])] = WebHooks.filter(_.byRepository(owner, repository)) - .innerJoin(WebHookEvents).on { (w, t) => t.byWebHook(w) } - .map { case (w,t) => w -> t.event } + .join(WebHookEvents).on { (w, t) => t.byWebHook(w) } + .map { case (w, t) => w -> t.event } .list.groupBy(_._1).mapValues(_.map(_._2).toSet).toList.sortBy(_._1.url) /** get All WebHook informations of repository event */ def getWebHooksByEvent(owner: String, repository: String, event: WebHook.Event)(implicit s: Session): List[WebHook] = WebHooks.filter(_.byRepository(owner, repository)) - .innerJoin(WebHookEvents).on { (wh, whe) => whe.byWebHook(wh) } + .join(WebHookEvents).on { (wh, whe) => whe.byWebHook(wh) } .filter { case (wh, whe) => whe.event === event.bind} - .map { case (wh, whe) => wh } + .map{ case (wh, whe) => wh } .list.distinct /** get All WebHook information from repository to url */ def getWebHook(owner: String, repository: String, url: String)(implicit s: Session): Option[(WebHook, Set[WebHook.Event])] = WebHooks .filter(_.byPrimaryKey(owner, repository, url)) - .innerJoin(WebHookEvents).on { (w, t) => t.byWebHook(w) } - .map { case (w,t) => w -> t.event } + .join(WebHookEvents).on { (w, t) => t.byWebHook(w) } + .map { case (w, t) => w -> t.event } .list.groupBy(_._1).mapValues(_.map(_._2).toSet).headOption def addWebHook(owner: String, repository: String, url :String, events: Set[WebHook.Event], ctype: WebHookContentType, token: Option[String])(implicit s: Session): Unit = { @@ -139,11 +140,9 @@ } } } - f.onSuccess { - case s => logger.debug(s"Success: web hook request to ${webHook.url}") - } - f.onFailure { - case t => logger.error(s"Failed: web hook request to ${webHook.url}", t) + f.onComplete { + case Success(_) => logger.debug(s"Success: web hook request to ${webHook.url}") + case Failure(t) => logger.error(s"Failed: web hook request to ${webHook.url}", t) } (webHook, json, reqPromise.future, f) } diff --git a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala index 59cd058..1136787 100644 --- a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala @@ -6,6 +6,7 @@ import gitbucket.core.service.SystemSettingsService.SystemSettings import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService} import gitbucket.core.util.{Keys, Implicits, AuthUtil} +import gitbucket.core.model.Profile.profile.blockingApi._ import org.slf4j.LoggerFactory import Implicits._ diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index 852f9c0..e84bf9e 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -5,6 +5,7 @@ import gitbucket.core.api import gitbucket.core.model.WebHook +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry} import gitbucket.core.service.IssuesService.IssueSearchCondition import gitbucket.core.service.WebHookService._ diff --git a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala index 8d55a81..5307ed4 100644 --- a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala +++ b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala @@ -10,6 +10,7 @@ import gitbucket.core.util.DatabaseConfig import gitbucket.core.util.Directory._ import gitbucket.core.util.JDBCUtil._ +import gitbucket.core.model.Profile.profile.blockingApi._ import io.github.gitbucket.solidbase.Solidbase import io.github.gitbucket.solidbase.manager.JDBCVersionManager import javax.servlet.{ServletContextListener, ServletContextEvent} diff --git a/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala b/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala index f4dc1b9..d6677d1 100644 --- a/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session} import gitbucket.core.util.Keys +import gitbucket.core.model.Profile.profile.blockingApi._ /** * Controls the transaction with the open session in view pattern. @@ -30,7 +31,7 @@ // Register Scalatra error callback to rollback transaction ScalatraBase.onFailure { _ => logger.debug("Rolled back transaction") - session.rollback() + session.conn.rollback() }(req.asInstanceOf[HttpServletRequest]) logger.debug("begin transaction") @@ -65,7 +66,7 @@ } private val db: SlickDatabase = { - SlickDatabase.forDataSource(dataSource) + SlickDatabase.forDataSource(dataSource, Some(dataSource.getMaximumPoolSize)) } def apply(): SlickDatabase = db diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index d5d8135..9620dbd 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -1,14 +1,15 @@ package gitbucket.core.ssh -import gitbucket.core.model.Session +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry} -import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService} -import gitbucket.core.servlet.{Database, CommitLogHook} -import gitbucket.core.util.{Directory, ControlUtil} -import org.apache.sshd.server.{CommandFactory, Environment, ExitCallback, Command, SessionAware} +import gitbucket.core.service.{AccountService, RepositoryService, SystemSettingsService} +import gitbucket.core.servlet.{CommitLogHook, Database} +import gitbucket.core.util.{ControlUtil, Directory} +import org.apache.sshd.server.{Command, CommandFactory, Environment, ExitCallback, SessionAware} import org.apache.sshd.server.session.ServerSession import org.slf4j.LoggerFactory import java.io.{File, InputStream, OutputStream} + import ControlUtil._ import org.eclipse.jgit.api.Git import Directory._ diff --git a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala index cc7a905..fa8d1ce 100644 --- a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala +++ b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala @@ -4,6 +4,7 @@ import gitbucket.core.service.SshKeyService import gitbucket.core.servlet.Database +import gitbucket.core.model.Profile.profile.blockingApi._ import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator import org.apache.sshd.server.session.ServerSession import org.apache.sshd.common.AttributeStore diff --git a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala index fb8d184..644c3f2 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -2,9 +2,11 @@ import com.typesafe.config.ConfigFactory import java.io.File + import Directory._ +import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, BlockingJdbcProfile} import liquibase.database.AbstractJdbcDatabase -import liquibase.database.core.{PostgresDatabase, MySQLDatabase, H2Database} +import liquibase.database.core.{H2Database, MySQLDatabase, PostgresDatabase} import org.apache.commons.io.FileUtils object DatabaseConfig { @@ -37,8 +39,8 @@ lazy val user : String = config.getString("db.user") lazy val password : String = config.getString("db.password") lazy val jdbcDriver : String = DatabaseType(url).jdbcDriver - lazy val slickDriver : slick.driver.JdbcProfile = DatabaseType(url).slickDriver - lazy val liquiDriver : AbstractJdbcDatabase = DatabaseType(url).liquiDriver + lazy val slickDriver : BlockingJdbcProfile = DatabaseType(url).slickDriver + lazy val liquiDriver : AbstractJdbcDatabase = DatabaseType(url).liquiDriver lazy val connectionTimeout : Option[Long] = getOptionValue("db.connectionTimeout", config.getLong) lazy val idleTimeout : Option[Long] = getOptionValue("db.idleTimeout" , config.getLong) lazy val maxLifetime : Option[Long] = getOptionValue("db.maxLifetime" , config.getLong) @@ -53,7 +55,7 @@ sealed trait DatabaseType { val jdbcDriver: String - val slickDriver: slick.driver.JdbcProfile + val slickDriver: BlockingJdbcProfile val liquiDriver: AbstractJdbcDatabase } @@ -73,25 +75,27 @@ object H2 extends DatabaseType { val jdbcDriver = "org.h2.Driver" - val slickDriver = slick.driver.H2Driver + val slickDriver = BlockingH2Driver val liquiDriver = new H2Database() } object MySQL extends DatabaseType { val jdbcDriver = "com.mysql.jdbc.Driver" - val slickDriver = slick.driver.MySQLDriver + val slickDriver = BlockingMySQLDriver val liquiDriver = new MySQLDatabase() } object PostgreSQL extends DatabaseType { val jdbcDriver = "org.postgresql.Driver2" - val slickDriver = new slick.driver.PostgresDriver { - override def quoteIdentifier(id: String): String = { - val s = new StringBuilder(id.length + 4) append '"' - for(c <- id) if(c == '"') s append "\"\"" else s append c.toLower - (s append '"').toString - } - } + val slickDriver = BlockingPostgresDriver val liquiDriver = new PostgresDatabase() } + + object BlockingPostgresDriver extends slick.jdbc.PostgresProfile with BlockingJdbcProfile { + override def quoteIdentifier(id: String): String = { + val s = new StringBuilder(id.length + 4) append '"' + for(c <- id) if(c == '"') s append "\"\"" else s append c.toLower + (s append '"').toString + } + } } diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 711418d..042ca9f 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -1,11 +1,13 @@ package gitbucket.core.util -import gitbucket.core.model.{Account, Issue, Session} -import gitbucket.core.service.{AccountService, IssuesService, RepositoryService, SystemSettingsService} +import gitbucket.core.model.{Session, Issue, Account} +import gitbucket.core.model.Profile.profile.blockingApi._ +import gitbucket.core.service.{RepositoryService, AccountService, IssuesService, SystemSettingsService} import gitbucket.core.servlet.Database import gitbucket.core.view.Markdown import scala.concurrent._ +import scala.util.{Success, Failure} import ExecutionContext.Implicits.global import org.apache.commons.mail.{DefaultAuthenticator, HtmlEmail} import org.slf4j.LoggerFactory @@ -96,11 +98,9 @@ } "Notifications Successful." } - f onSuccess { - case s => logger.debug(s) - } - f onFailure { - case t => logger.error("Notifications Failed.", t) + f.onComplete { + case Success(s) => logger.debug(s) + case Failure(t) => logger.error("Notifications Failed.", t) } } } diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index 0db3efe..da7dc50 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -123,4 +123,19 @@ "(?i)(? b append '^' append c +// case _ => b append c +// } +// b.toString +// } + + } diff --git a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala index 2df4822..45ab3ff 100644 --- a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala @@ -2,7 +2,9 @@ import gitbucket.core.model._ import org.scalatest.FunSuite - +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase { @@ -66,8 +68,7 @@ test("when update Account.userName then AccessToken.userName changed") { withTestDB { implicit session => val user2 = generateNewAccount("user2") val (id, token) = AccessTokenService.generateAccessToken("user2", "note") - import gitbucket.core.model.Profile._ - import profile.simple._ + Accounts.filter(_.userName === "user2".bind).map(_.userName).update("user3") assert(AccessTokenService.getAccountByAccessToken(token) match { diff --git a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala index 8c3d36b..56a29fb 100644 --- a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala @@ -2,7 +2,8 @@ import gitbucket.core.model._ import gitbucket.core.model.Profile._ -import profile.simple._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.scalatest.FunSuite diff --git a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala index ec4e5fc..0238fee 100644 --- a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala @@ -6,40 +6,42 @@ class IssuesServiceSpec extends FunSuite with ServiceSpecBase { - test("getCommitStatues") { withTestDB { implicit session => - val user1 = generateNewUserWithDBRepository("user1","repo1") + test("getCommitStatues") { + withTestDB { implicit session => + val user1 = generateNewUserWithDBRepository("user1","repo1") - def getCommitStatues = dummyService.getCommitStatues(List(("user1","repo1",1),("user1","repo1",2))) + def getCommitStatues(issueId: Int) = dummyService.getCommitStatues("user1","repo1",issueId) - assert(getCommitStatues == Map.empty) + assert(getCommitStatues(1) == None) - val now = new java.util.Date() - val issueId = generateNewIssue("user1","repo1") - assert(issueId == 1) + val now = new java.util.Date() + val issueId = generateNewIssue("user1","repo1") + assert(issueId == 1) - assert(getCommitStatues == Map.empty) + assert(getCommitStatues(1) == None) - val cs = dummyService.createCommitStatus("user1","repo1","shasha", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + val cs = dummyService.createCommitStatus("user1","repo1","shasha", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - assert(getCommitStatues == Map.empty) + assert(getCommitStatues(1) == None) - val (is2, pr2) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature1") - assert(pr2.issueId == 2) + val (is2, pr2) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature1") + assert(pr2.issueId == 2) - // if there are no statuses, state is none - assert(getCommitStatues == Map.empty) + // if there are no statuses, state is none + assert(getCommitStatues(2) == None) - // if there is a status, state is that - val cs2 = dummyService.createCommitStatus("user1","repo1","feature1", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(1,1,Some("default"),Some(CommitState.SUCCESS),Some("http://exmple.com/ci"),Some("exampleService")))) + // if there is a status, state is that + val cs2 = dummyService.createCommitStatus("user1","repo1","feature1", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + assert(getCommitStatues(2) == Some(CommitStatusInfo(1,1,Some("default"),Some(CommitState.SUCCESS),Some("http://exmple.com/ci"),Some("exampleService")))) - // if there are two statuses, state is none - val cs3 = dummyService.createCommitStatus("user1","repo1","feature1", "pend", CommitState.PENDING, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None))) + // if there are two statuses, state is none + val cs3 = dummyService.createCommitStatus("user1","repo1","feature1", "pend", CommitState.PENDING, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + assert(getCommitStatues(2) == Some(CommitStatusInfo(2,1,None,None,None,None))) - // get only statuses in query issues - val (is3, pr3) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature3") - val cs4 = dummyService.createCommitStatus("user1","repo1","feature3", "none", CommitState.PENDING, None, None, now, user1) - assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None))) - } } + // get only statuses in query issues + val (is3, pr3) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature3") + val cs4 = dummyService.createCommitStatus("user1","repo1","feature3", "none", CommitState.PENDING, None, None, now, user1) + assert(getCommitStatues(2) == Some(CommitStatusInfo(2,1,None,None,None,None))) + } + } } \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala index 037a098..7eb7ba5 100644 --- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala +++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala @@ -3,12 +3,13 @@ import gitbucket.core.GitBucketCoreModule import gitbucket.core.util.{DatabaseConfig, FileUtil} import gitbucket.core.util.ControlUtil._ -import gitbucket.core.model._ -import gitbucket.core.model.Profile._ import io.github.gitbucket.solidbase.Solidbase import liquibase.database.core.H2Database import liquibase.database.jvm.JdbcConnection -import profile.simple._ +import gitbucket.core.model._ +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.apache.commons.io.FileUtils