diff --git a/build.sbt b/build.sbt index 41ef043..ce788a5 100644 --- a/build.sbt +++ b/build.sbt @@ -35,7 +35,8 @@ "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" % "3.2.0-M1", + //"com.typesafe.slick" %% "slick" % "3.2.0-M1", + "com.github.takezoe" %% "blocking-slick" % "0.0.3-SNAPSHOT", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", "mysql" % "mysql-connector-java" % "5.1.39", 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 cd2190a..57673c0 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 5036e3a..0838165 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 75ed261..f6f773b 100644 --- a/src/main/scala/gitbucket/core/model/CommitStatus.scala +++ b/src/main/scala/gitbucket/core/model/CommitStatus.scala @@ -1,10 +1,10 @@ package gitbucket.core.model -import scala.slick.lifted.MappedTo -import scala.slick.jdbc._ +//import scala.slick.lifted.MappedTo +//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)) @@ -90,7 +90,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 4700a04..b143b4f 100644 --- a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala +++ b/src/main/scala/gitbucket/core/model/ProtectedBranch.scala @@ -1,10 +1,7 @@ package gitbucket.core.model -import scala.slick.lifted.MappedTo -import scala.slick.jdbc._ - trait ProtectedBranchComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val ProtectedBranches = TableQuery[ProtectedBranches] @@ -12,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..6f89b0e 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,8 +9,8 @@ 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) 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 0a8109d..c04fccc 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -1,7 +1,8 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.blockingApi._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil @@ -25,21 +26,23 @@ 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) + .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 diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index d583255..5a6c748 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -1,13 +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.service.SystemSettingsService.SystemSettings +import profile._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait AccountService { diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 618d917..a7e61cd 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -3,7 +3,8 @@ import gitbucket.core.model.Activity import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile.simple._ +import profile._ +import profile.blockingApi._ trait ActivityService { @@ -15,7 +16,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 +31,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 +40,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 ae613ff..07fe47f 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -1,14 +1,10 @@ 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.util.StringUtil._ -import gitbucket.core.service.RepositoryService.RepositoryInfo -import org.joda.time.LocalDateTime +import profile._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.model.{CommitState, CommitStatus, Account} trait CommitStatusService { /** insert or update */ @@ -23,7 +19,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, @@ -49,7 +45,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 5ccffd5..a7a8fc4 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -1,15 +1,10 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment -import gitbucket.core.util.{StringUtil, Implicits} - -import scala.slick.jdbc.{StaticQuery => Q} -import Q.interpolation import gitbucket.core.model.Profile._ -import profile.simple._ -import Implicits._ -import StringUtil._ - +import profile._ +import profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType trait CommitsService { @@ -29,7 +24,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, @@ -42,12 +37,12 @@ updatedDate = currentDate, issueId = issueId) - 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 22cfc88..225766b 100644 --- a/src/main/scala/gitbucket/core/service/HandleCommentService.scala +++ b/src/main/scala/gitbucket/core/service/HandleCommentService.scala @@ -6,7 +6,7 @@ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Notifier -import profile.simple._ +import profile.blockingApi._ trait HandleCommentService { self: RepositoryService with IssuesService with ActivityService diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index ecbfa55..e43f399 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.Profile._ +import profile._ +import profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType trait IssuesService { @@ -29,8 +26,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 @@ -43,7 +40,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) ) @@ -77,10 +74,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) => @@ -89,63 +86,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) - } - } - import gitbucket.core.model.Profile.commitStateColumnType - 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 } } @@ -163,39 +124,37 @@ (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) } + .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, pullRequest, headRepo, headOwner) */ def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*) (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 @@ -204,17 +163,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 } } } @@ -228,7 +191,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)) && @@ -298,25 +261,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) = @@ -326,24 +288,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. @@ -355,13 +309,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) => @@ -377,10 +331,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) => @@ -412,7 +366,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. @@ -424,7 +378,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") diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index f8026e0..716ae32 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -2,7 +2,8 @@ import gitbucket.core.model.Label import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.blockingApi._ trait LabelsService { @@ -15,13 +16,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/MergeService.scala b/src/main/scala/gitbucket/core/service/MergeService.scala index d427d17..74a329d 100644 --- a/src/main/scala/gitbucket/core/service/MergeService.scala +++ b/src/main/scala/gitbucket/core/service/MergeService.scala @@ -1,9 +1,7 @@ package gitbucket.core.service import gitbucket.core.model.Account -import gitbucket.core.util.LockUtil import gitbucket.core.util.Directory._ -import gitbucket.core.util.Implicits._ import gitbucket.core.util.ControlUtil._ import org.eclipse.jgit.merge.MergeStrategy diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index 598c3ce..b94ca39 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -2,8 +2,8 @@ import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ -import profile.simple._ -// TODO Why is direct import required? +import profile._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait MilestonesService { @@ -44,6 +44,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 165910b..9cd63b6 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -1,9 +1,10 @@ package gitbucket.core.service -import gitbucket.core.model._ +import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitState} import gitbucket.core.model.Profile._ import gitbucket.core.plugin.ReceiveHook -import profile.simple._ +import profile._ +import profile.blockingApi._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} @@ -12,14 +13,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 e90ba3f..fbdee92 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -3,7 +3,8 @@ import gitbucket.core.model.{Account, Issue, PullRequest, WebHook, CommitStatus, CommitState} import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile.simple._ +import profile._ +import profile.blockingApi._ trait PullRequestService { self: IssuesService => @@ -26,7 +27,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) && @@ -73,7 +74,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) && @@ -93,7 +94,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) && @@ -111,6 +112,7 @@ def updatePullRequests(owner: String, repository: String, branch: String)(implicit s: Session): Unit = getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq => if(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists.run){ + //if(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists.run){ val (commitIdTo, commitIdFrom) = JGitUtil.updatePullRequest( pullreq.userName, pullreq.repositoryName, pullreq.branch, pullreq.issueId, pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch) @@ -124,7 +126,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..85962f3 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -8,7 +8,7 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib.{FileMode, Constants} -import profile.simple._ +import profile.blockingApi._ 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..09bd276 100644 --- a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala +++ b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala @@ -10,7 +10,7 @@ import org.eclipse.jgit.lib.FileMode import org.eclipse.jgit.api.Git import gitbucket.core.model.Profile._ -import profile.simple._ +import 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 26fa159..6ecc93a 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -1,10 +1,12 @@ package gitbucket.core.service import gitbucket.core.controller.Context +import gitbucket.core.util.JGitUtil import gitbucket.core.model.{Collaborator, Repository, RepositoryOptions, Account, Permission} import gitbucket.core.model.Profile._ -import gitbucket.core.util.JGitUtil -import profile.simple._ +import profile._ +import profile.blockingApi._ +import gitbucket.core.model.Profile.dateColumnType trait RepositoryService { self: AccountService => import RepositoryService._ @@ -122,6 +124,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)) :_*) @@ -239,8 +246,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) || (Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName === userName.bind)} exists) @@ -311,8 +317,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. @@ -349,7 +356,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 } @@ -361,13 +368,13 @@ */ def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Permission] = 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.permission) } 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.permission) } diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index 5feb119..a0e142c 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -2,7 +2,8 @@ import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import 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 d50f9e7..9d64779 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -6,7 +6,8 @@ import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent, CommitComment} import gitbucket.core.model.Profile._ import org.apache.http.client.utils.URLEncodedUtils -import profile.simple._ +import profile._ +import profile.blockingApi._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.RepositoryName import gitbucket.core.service.RepositoryService.RepositoryInfo @@ -32,14 +33,14 @@ /** 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) } + .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 } .list.distinct @@ -48,13 +49,13 @@ 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) } + .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 = { WebHooks insert WebHook(owner, repository, url, ctype, token) - events.toSet.map{ event: WebHook.Event => + events.toSet.map { event: WebHook.Event => WebHookEvents insert WebHookEvent(owner, repository, url, event) } } @@ -62,7 +63,7 @@ def updateWebHook(owner: String, repository: String, url :String, events: Set[WebHook.Event], ctype: WebHookContentType, token: Option[String])(implicit s: Session): Unit = { WebHooks.filter(_.byPrimaryKey(owner, repository, url)).map(w => (w.ctype, w.token)).update((ctype, token)) WebHookEvents.filter(_.byWebHook(owner, repository, url)).delete - events.toSet.map{ event: WebHook.Event => + events.toSet.map { event: WebHook.Event => WebHookEvents insert WebHookEvent(owner, repository, url, event) } } diff --git a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala index 8d55a81..e29bea9 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._ 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 c25a2fe..891f1f0 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._ /** * Controls the transaction with the open session in view pattern. @@ -29,7 +30,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") diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index f1ebb09..c7b4277 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -1,6 +1,7 @@ package gitbucket.core.ssh import gitbucket.core.model.Session +import gitbucket.core.model.Profile.profile._ import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry} import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService} import gitbucket.core.servlet.{Database, CommitLogHook} diff --git a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala index 8ed2cfb..6b9a60e 100644 --- a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala +++ b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala @@ -2,9 +2,9 @@ import java.security.PublicKey -import gitbucket.core.model.SshKey import gitbucket.core.service.SshKeyService import gitbucket.core.servlet.Database +import gitbucket.core.model.Profile.profile._ 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..681cebc 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.driver.PostgresDriver 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 24a883d..41d5b6b 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -1,6 +1,7 @@ package gitbucket.core.util import gitbucket.core.model.{Session, Issue} +import gitbucket.core.model.Profile.profile._ import gitbucket.core.service.{RepositoryService, AccountService, IssuesService, SystemSettingsService} import gitbucket.core.servlet.Database import gitbucket.core.view.Markdown diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index 76cc389..9710b50 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -100,4 +100,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..7202b7c 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 profile._ +import 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..54cc670 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 profile._ +import 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 0bf208b..d564a99 100644 --- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala +++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala @@ -8,7 +8,8 @@ import io.github.gitbucket.solidbase.Solidbase import liquibase.database.core.H2Database import liquibase.database.jvm.JdbcConnection -import profile.simple._ +import profile._ +import profile.blockingApi._ import org.apache.commons.io.FileUtils