From 825b2f9ebfa933642c065e846090516c909bc14c Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 12 Aug 2016 15:31:38 +0900 Subject: [PATCH 01/27] Experiment of blocking-slick --- build.sbt | 3 +- .../gitbucket/core/model/AccessToken.scala | 3 +- .../scala/gitbucket/core/model/Account.scala | 2 +- .../scala/gitbucket/core/model/Activity.scala | 2 +- .../gitbucket/core/model/BasicTemplate.scala | 14 +- .../gitbucket/core/model/Collaborator.scala | 2 +- .../scala/gitbucket/core/model/Comment.scala | 4 +- .../gitbucket/core/model/CommitStatus.scala | 10 +- .../gitbucket/core/model/GroupMembers.scala | 2 +- .../scala/gitbucket/core/model/Issue.scala | 2 +- .../gitbucket/core/model/IssueLabels.scala | 2 +- .../scala/gitbucket/core/model/Labels.scala | 4 +- .../gitbucket/core/model/Milestone.scala | 4 +- .../scala/gitbucket/core/model/Profile.scala | 9 +- .../core/model/ProtectedBranch.scala | 8 +- .../gitbucket/core/model/PullRequest.scala | 4 +- .../gitbucket/core/model/Repository.scala | 2 +- .../scala/gitbucket/core/model/SshKey.scala | 2 +- .../scala/gitbucket/core/model/WebHook.scala | 6 +- .../gitbucket/core/model/WebHookEvent.scala | 4 +- .../gitbucket/core/plugin/ReceiveHook.scala | 2 +- .../core/service/AccessTokenService.scala | 9 +- .../core/service/AccountService.scala | 23 +-- .../core/service/ActivityService.scala | 47 ++--- .../core/service/CommitStatusService.scala | 5 +- .../core/service/CommitsService.scala | 11 +- .../core/service/HandleCommentService.scala | 2 +- .../core/service/IssuesService.scala | 186 +++++++++--------- .../core/service/LabelsService.scala | 27 ++- .../core/service/MilestonesService.scala | 6 +- .../core/service/ProtectedBranchService.scala | 19 +- .../core/service/PullRequestService.scala | 13 +- .../service/RepositoryCreationService.scala | 2 +- .../service/RepositorySearchService.scala | 2 +- .../core/service/RepositoryService.scala | 131 ++++++------ .../core/service/SshKeyService.scala | 5 +- .../core/service/WebHookService.scala | 25 +-- .../core/servlet/InitializeListener.scala | 1 + .../core/servlet/TransactionFilter.scala | 3 +- .../scala/gitbucket/core/ssh/GitCommand.scala | 1 + .../core/ssh/PublicKeyAuthenticator.scala | 2 +- .../gitbucket/core/util/DatabaseConfig.scala | 12 +- .../scala/gitbucket/core/util/Notifier.scala | 1 + 43 files changed, 328 insertions(+), 296 deletions(-) diff --git a/build.sbt b/build.sbt index 6cbf944d2..49dbf6b84 100644 --- a/build.sbt +++ b/build.sbt @@ -35,7 +35,8 @@ libraryDependencies ++= Seq( "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.typesafe.slick" %% "slick" % "3.1.1", + "com.github.takezoe" %% "blocking-slick" % "0.0.2-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 de298577c..a460b90db 100644 --- a/src/main/scala/gitbucket/core/model/AccessToken.scala +++ b/src/main/scala/gitbucket/core/model/AccessToken.scala @@ -2,7 +2,8 @@ package gitbucket.core.model 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 cd2190a8f..57673c076 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 0f49ee3c8..8c5b8bd60 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 53388fc01..c3b8e1b36 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 @@ protected[model] trait TemplateComponent { self: Profile => 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 @@ protected[model] trait TemplateComponent { self: Profile => 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 @@ protected[model] trait TemplateComponent { self: Profile => 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 @@ protected[model] trait TemplateComponent { self: Profile => 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 @@ protected[model] trait TemplateComponent { self: Profile => 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 55ae80f14..d3af76a17 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] diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index cab001c32..5e3c110c1 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -6,7 +6,7 @@ trait Comment { } trait IssueCommentComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){ @@ -39,7 +39,7 @@ case class IssueComment ( ) 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)){ diff --git a/src/main/scala/gitbucket/core/model/CommitStatus.scala b/src/main/scala/gitbucket/core/model/CommitStatus.scala index 75ed26132..dd82f8384 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,7 @@ object CommitState { } } - implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<)) - implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => 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 24568d3f3..fd7a5cee7 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 c56cec784..57d3a655a 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 84a4e6d97..a9abf8b62 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 @@ trait LabelComponent extends TemplateComponent { self: Profile => 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 5c09b5df5..81c4f2b89 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 @@ trait MilestoneComponent extends TemplateComponent { self: Profile => 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 26bb22595..fb5e63387 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.SlickBlockingAPI trait Profile { - val profile: slick.driver.JdbcProfile - import profile.simple._ + val profile: SlickBlockingAPI + import profile.api._ /** * java.util.Date Mapped Column Types @@ -17,8 +18,8 @@ trait Profile { /** * 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 4700a0430..e37caa964 100644 --- a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala +++ b/src/main/scala/gitbucket/core/model/ProtectedBranch.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 ProtectedBranchComponent extends TemplateComponent { self: Profile => - import profile.simple._ + import profile.api._ import self._ lazy val ProtectedBranches = TableQuery[ProtectedBranches] @@ -12,7 +12,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile => 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 ed5acac37..dba1a3f5a 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 @@ trait PullRequestComponent extends TemplateComponent { self: Profile => 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 ebdfb3ac8..fbc2ff3f7 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 fa7909e6c..a5a41f0cf 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 d87f9cb57..6f89b0ec8 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 @@ trait WebHookComponent extends TemplateComponent { self: Profile => 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 cc960e73d..d9f5a55f8 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 @@ trait WebHookEventComponent extends TemplateComponent { self: Profile => 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 125f6a205..7b76ecc0d 100644 --- a/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala +++ b/src/main/scala/gitbucket/core/plugin/ReceiveHook.scala @@ -2,7 +2,7 @@ package gitbucket.core.plugin 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/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 0a8109dc8..61df80a69 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.api._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil @@ -28,7 +29,7 @@ trait AccessTokenService { do{ token = makeAccessTokenString hash = tokenToHash(token) - }while(AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + } while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) val newToken = AccessToken( userName = userName, note = note, @@ -39,7 +40,7 @@ trait AccessTokenService { 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 @@ -48,7 +49,7 @@ trait AccessTokenService { AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit = - AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete + AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) unsafeDelete } diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index 06133fce0..d6344cb96 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -4,7 +4,8 @@ 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 profile._ +import profile.api._ import StringUtil._ import org.slf4j.LoggerFactory // TODO Why is direct import required? @@ -105,7 +106,7 @@ trait AccountService { def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String]) (implicit s: Session): Unit = - Accounts insert Account( + Accounts unsafeInsert Account( userName = userName, password = password, fullName = fullName, @@ -123,7 +124,7 @@ trait AccountService { Accounts .filter { a => a.userName === account.userName.bind } .map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed) } - .update ( + .unsafeUpdate ( account.password, account.fullName, account.mailAddress, @@ -135,13 +136,13 @@ trait AccountService { account.isRemoved) def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit = - Accounts.filter(_.userName === userName.bind).map(_.image.?).update(image) + Accounts.filter(_.userName === userName.bind).map(_.image.?).unsafeUpdate(image) def updateLastLoginDate(userName: String)(implicit s: Session): Unit = - Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).update(currentDate) + Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).unsafeUpdate(currentDate) def createGroup(groupName: String, url: Option[String])(implicit s: Session): Unit = - Accounts insert Account( + Accounts unsafeInsert Account( userName = groupName, password = "", fullName = groupName, @@ -156,12 +157,12 @@ trait AccountService { isRemoved = false) def updateGroup(groupName: String, url: Option[String], removed: Boolean)(implicit s: Session): Unit = - Accounts.filter(_.userName === groupName.bind).map(t => t.url.? -> t.removed).update(url, removed) + Accounts.filter(_.userName === groupName.bind).map(t => t.url.? -> t.removed).unsafeUpdate(url, removed) def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = { GroupMembers.filter(_.groupName === groupName.bind).delete members.foreach { case (userName, isManager) => - GroupMembers insert GroupMember (groupName, userName, isManager) + GroupMembers unsafeInsert GroupMember (groupName, userName, isManager) } } @@ -179,9 +180,9 @@ trait AccountService { .list def removeUserRelatedData(userName: String)(implicit s: Session): Unit = { - GroupMembers.filter(_.userName === userName.bind).delete - Collaborators.filter(_.collaboratorName === userName.bind).delete - Repositories.filter(_.userName === userName.bind).delete + GroupMembers.filter(_.userName === userName.bind).unsafeDelete + Collaborators.filter(_.collaboratorName === userName.bind).unsafeDelete + Repositories.filter(_.userName === userName.bind).unsafeDelete } def getGroupNames(userName: String)(implicit s: Session): List[String] = { diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 618d917a7..25de82896 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -3,19 +3,20 @@ package gitbucket.core.service import gitbucket.core.model.Activity import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile.simple._ +import profile._ +import profile.api._ trait ActivityService { def deleteOldActivities(limit: Int)(implicit s: Session): Int = { Activities.map(_.activityId).sortBy(_ desc).drop(limit).firstOption.map { id => - Activities.filter(_.activityId <= id.bind).delete + Activities.filter(_.activityId <= id.bind).unsafeDelete } getOrElse 0 } def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] = Activities - .innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName)) + .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 @@ trait ActivityService { 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 @@ trait ActivityService { 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 } @@ -48,7 +49,7 @@ trait ActivityService { def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "create_repository", s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]", None, @@ -56,7 +57,7 @@ trait ActivityService { def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "open_issue", s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -64,7 +65,7 @@ trait ActivityService { def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "close_issue", s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -72,7 +73,7 @@ trait ActivityService { def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "close_issue", s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -80,7 +81,7 @@ trait ActivityService { def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "reopen_issue", s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -88,7 +89,7 @@ trait ActivityService { def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "comment_issue", s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]", Some(cut(comment, 200)), @@ -96,7 +97,7 @@ trait ActivityService { def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "comment_issue", s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(cut(comment, 200)), @@ -104,7 +105,7 @@ trait ActivityService { def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "comment_commit", s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]", Some(cut(comment, 200)), @@ -113,7 +114,7 @@ trait ActivityService { def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "create_wiki", s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki", Some(pageName), @@ -121,7 +122,7 @@ trait ActivityService { def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "edit_wiki", s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki", Some(pageName + ":" + commitId), @@ -129,7 +130,7 @@ trait ActivityService { def recordPushActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "push", s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]", Some(commits.map { commit => commit.id + ":" + commit.shortMessage }.mkString("\n")), @@ -137,7 +138,7 @@ trait ActivityService { def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String, tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "create_tag", s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]", None, @@ -145,7 +146,7 @@ trait ActivityService { def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String, tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "delete_tag", s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]", None, @@ -153,7 +154,7 @@ trait ActivityService { def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "create_branch", s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]", None, @@ -161,14 +162,14 @@ trait ActivityService { def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "delete_branch", s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]", None, currentDate) def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "fork", s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]", None, @@ -176,7 +177,7 @@ trait ActivityService { def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "open_pullreq", s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -184,7 +185,7 @@ trait ActivityService { def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String) (implicit s: Session): Unit = - Activities insert Activity(userName, repositoryName, activityUserName, + Activities unsafeInsert Activity(userName, repositoryName, activityUserName, "merge_pullreq", s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(message), diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index ae613ffbb..90a2d6b41 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -1,7 +1,8 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.api._ import gitbucket.core.model.{CommitState, CommitStatus, Account} import gitbucket.core.util.Implicits._ @@ -49,7 +50,7 @@ trait CommitStatusService { 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 5ccffd530..68a2a5332 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -3,12 +3,13 @@ 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 slick.jdbc.{StaticQuery => Q} +//import Q.interpolation import gitbucket.core.model.Profile._ -import profile.simple._ -import Implicits._ -import StringUtil._ +import profile._ +import profile.api._ +//import Implicits._ +//import StringUtil._ trait CommitsService { diff --git a/src/main/scala/gitbucket/core/service/HandleCommentService.scala b/src/main/scala/gitbucket/core/service/HandleCommentService.scala index 6a1b06869..92bdb459c 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.model.Profile._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Notifier -import profile.simple._ +import profile.api._ 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 911e3cadd..be758220f 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -3,17 +3,17 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.StringUtil -import profile.simple._ - +import profile._ +import profile.api._ import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ -import gitbucket.core.model._ +import gitbucket.core.model.{Account, CommitState, Issue, IssueComment, IssueLabel, Label, PullRequest, Repository} +import slick.profile.SqlUtilsComponent -import scala.slick.jdbc.{StaticQuery => Q} -import Q.interpolation +//import scala.slick.jdbc.{StaticQuery => Q} -trait IssuesService { +trait IssuesService extends SqlUtilsComponent { self: AccountService => import IssuesService._ @@ -29,8 +29,8 @@ trait IssuesService { 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 +43,7 @@ trait IssuesService { 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 +77,10 @@ trait IssuesService { 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,64 +89,66 @@ trait IssuesService { .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 - } 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 - } + def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] = { + Map.empty +// TODO [Slick3] +// if(issueList.isEmpty){ +// Map.empty +// } 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 +// } } /** @@ -163,11 +165,11 @@ trait IssuesService { (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), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } - .leftJoin (Labels) .on { case (((t1, t2), t3), t4) => t3.byLabel(t4.userName, t4.repositoryName, t4.labelId) } - .leftJoin (Milestones) .on { case ((((t1, t2), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } + .joinLeft (IssueLabels) .on { case ((t1, t2), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } + .joinLeft (Labels) .on { case (((t1, t2), t3), t4) => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) } + .joinLeft (Milestones) .on { case ((((t1, t2), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } .map { case ((((t1, t2), t3), t4), t5) => - (t1, t2.commentCount, t4.labelId.?, t4.labelName.?, t4.color.?, t5.title.?) + (t1, t2.commentCount, t4.map(_.labelId), t4.map(_.labelName), t4.map(_.color), t5.map(_.title)) } .list .splitWith { (c1, c2) => @@ -196,10 +198,10 @@ trait IssuesService { (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), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } - .innerJoin(Repositories).on { case (((t1, t2), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) } - .innerJoin(Accounts).on { case ((((t1, t2), t3), t4), t5) => t5.userName === t1.openedUserName } - .innerJoin(Accounts).on { case (((((t1, t2), t3), t4), t5), t6) => t6.userName === t4.userName } + .join(PullRequests).on { case ((t1, t2), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } + .join(Repositories).on { case (((t1, t2), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) } + .join(Accounts).on { case ((((t1, t2), t3), t4), t5) => t5.userName === t1.openedUserName } + .join(Accounts).on { case (((((t1, t2), t3), t4), t5), t6) => t6.userName === t4.userName } .map { case (((((t1, t2), t3), t4), t5), t6) => (t1, t5, t2.commentCount, t3, t4, t6) } @@ -209,14 +211,14 @@ trait IssuesService { 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) => (condition.sort match { case "created" => t1.registeredDate case "comments" => t2.commentCount case "updated" => t1.updatedDate }) match { - case sort => condition.direction match { + case sort: slick.lifted.ColumnOrdered[_] => condition.direction match { case "asc" => sort asc case "desc" => sort desc } @@ -232,7 +234,7 @@ trait IssuesService { 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)) && @@ -274,7 +276,7 @@ trait IssuesService { // next id number sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] .firstOption.filter { id => - Issues insert Issue( + Issues unsafeInsert Issue( owner, repository, id, @@ -292,14 +294,14 @@ trait IssuesService { IssueId .filter (_.byPrimaryKey(owner, repository)) .map (_.issueId) - .update (id) > 0 + .unsafeUpdate (id) > 0 } get def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = - IssueLabels insert IssueLabel(owner, repository, issueId, labelId) + IssueLabels unsafeInsert IssueLabel(owner, repository, issueId, labelId) def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = - IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) delete + IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) unsafeDelete def createComment(owner: String, repository: String, loginUser: String, issueId: Int, content: String, action: String)(implicit s: Session): Int = @@ -320,15 +322,15 @@ trait IssuesService { .map { t => (t.title, t.content.?, t.updatedDate) } - .update (title, content, currentDate) + .unsafeUpdate (title, content, currentDate) def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session) = - Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).update (assignedUserName) + Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).unsafeUpdate (assignedUserName) def updateMilestoneId(owner: String, repository: String, issueId: Int, milestoneId: Option[Int])(implicit s: Session) = - Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).update (milestoneId) + Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).unsafeUpdate (milestoneId) def updateComment(commentId: Int, content: String)(implicit s: Session) = IssueComments @@ -336,10 +338,10 @@ trait IssuesService { .map { t => t.content -> t.updatedDate } - .update (content, currentDate) + .unsafeUpdate (content, currentDate) def deleteComment(commentId: Int)(implicit s: Session) = - IssueComments filter (_.byPrimaryKey(commentId)) delete + IssueComments filter (_.byPrimaryKey(commentId)) unsafeDelete def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = Issues @@ -347,7 +349,7 @@ trait IssuesService { .map { t => t.closed -> t.updatedDate } - .update (closed, currentDate) + .usnafeUpdate (closed, currentDate) /** * Search issues by keyword. @@ -359,13 +361,13 @@ trait IssuesService { */ 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) => @@ -381,10 +383,10 @@ trait IssuesService { // 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) => diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index f8026e09f..f7267016a 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -2,7 +2,11 @@ package gitbucket.core.service import gitbucket.core.model.Label import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.api._ + +import scala.concurrent.Await +import scala.concurrent.duration.Duration trait LabelsService { @@ -15,13 +19,18 @@ trait LabelsService { 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( - userName = owner, - repositoryName = repository, - labelName = labelName, - color = color + def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Int = { + // TODO [Slick3]Provide blocking method for returning + val f = s.database.run( + Labels returning Labels.map(_.labelId) += Label( + userName = owner, + repositoryName = repository, + labelName = labelName, + color = color + ) ) + Await.result(f, Duration.Inf) + } def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String) (implicit s: Session): Unit = @@ -30,8 +39,8 @@ trait LabelsService { .update(labelName, color) def deleteLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Unit = { - IssueLabels.filter(_.byLabel(owner, repository, labelId)).delete - Labels.filter(_.byPrimaryKey(owner, repository, labelId)).delete + IssueLabels.filter(_.byLabel(owner, repository, labelId)).unsafeDelete + Labels.filter(_.byPrimaryKey(owner, repository, labelId)).unsafeDelete } } diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index 598c3ced7..9187bae41 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -2,7 +2,8 @@ package gitbucket.core.service import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.api._ // TODO Why is direct import required? import gitbucket.core.model.Profile.dateColumnType @@ -10,7 +11,7 @@ trait MilestonesService { def createMilestone(owner: String, repository: String, title: String, description: Option[String], dueDate: Option[java.util.Date])(implicit s: Session): Unit = - Milestones insert Milestone( + Milestones unsafeInsert Milestone( userName = owner, repositoryName = repository, title = title, @@ -44,6 +45,7 @@ trait MilestonesService { .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 165910bb7..849398be9 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.api._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} @@ -12,14 +13,14 @@ trait ProtectedBranchService { 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 @@ -32,9 +33,9 @@ trait ProtectedBranchService { def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String]) (implicit session: Session): Unit = { disableBranchProtection(owner, repository, branch) - ProtectedBranches.insert(new ProtectedBranch(owner, repository, branch, includeAdministrators && contexts.nonEmpty)) + ProtectedBranches.unsafeInsert(new ProtectedBranch(owner, repository, branch, includeAdministrators && contexts.nonEmpty)) contexts.map{ context => - ProtectedBranchContexts.insert(new ProtectedBranchContext(owner, repository, branch, context)) + ProtectedBranchContexts.unsafeInsert(new ProtectedBranchContext(owner, repository, branch, context)) } } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index e90ba3fcb..71175789d 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -3,7 +3,8 @@ package gitbucket.core.service 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.api._ trait PullRequestService { self: IssuesService => @@ -26,7 +27,7 @@ trait PullRequestService { self: IssuesService => 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) && @@ -59,7 +60,7 @@ trait PullRequestService { self: IssuesService => def createPullRequest(originUserName: String, originRepositoryName: String, issueId: Int, originBranch: String, requestUserName: String, requestRepositoryName: String, requestBranch: String, commitIdFrom: String, commitIdTo: String)(implicit s: Session): Unit = - PullRequests insert PullRequest( + PullRequests unsafeInsert PullRequest( originUserName, originRepositoryName, issueId, @@ -73,7 +74,7 @@ trait PullRequestService { self: IssuesService => 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 @@ trait PullRequestService { self: IssuesService => 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) && @@ -124,7 +125,7 @@ trait PullRequestService { self: IssuesService => 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 90e0afd63..102c8d546 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -8,7 +8,7 @@ import gitbucket.core.model.Account import org.eclipse.jgit.api.Git import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib.{FileMode, Constants} -import profile.simple._ +import profile.api._ 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 bba717215..da06a9cb2 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.treewalk.TreeWalk import org.eclipse.jgit.lib.FileMode import org.eclipse.jgit.api.Git import gitbucket.core.model.Profile._ -import profile.simple._ +import profile.api._ 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 959e735f9..568a3e3cf 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -4,7 +4,8 @@ import gitbucket.core.controller.Context import gitbucket.core.model.{Collaborator, Repository, Account} import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile.simple._ +import profile._ +import profile.api._ trait RepositoryService { self: AccountService => import RepositoryService._ @@ -23,7 +24,7 @@ trait RepositoryService { self: AccountService => originRepositoryName: Option[String] = None, originUserName: Option[String] = None, parentRepositoryName: Option[String] = None, parentUserName: Option[String] = None) (implicit s: Session): Unit = { - Repositories insert + Repositories unsafeInsert Repository( userName = userName, repositoryName = repositoryName, @@ -44,14 +45,14 @@ trait RepositoryService { self: AccountService => externalWikiUrl = None ) - IssueId insert (userName, repositoryName, 0) + IssueId unsafeInsert (userName, repositoryName, 0) } def renameRepository(oldUserName: String, oldRepositoryName: String, newUserName: String, newRepositoryName: String) (implicit s: Session): Unit = { getAccountByUserName(newUserName).foreach { account => (Repositories filter { t => t.byRepository(oldUserName, oldRepositoryName) } firstOption).map { repository => - Repositories insert repository.copy(userName = newUserName, repositoryName = newRepositoryName) + Repositories unsafeInsert repository.copy(userName = newUserName, repositoryName = newRepositoryName) val webHooks = WebHooks .filter(_.byRepository(oldUserName, oldRepositoryName)).list val webHookEvents = WebHookEvents .filter(_.byRepository(oldUserName, oldRepositoryName)).list @@ -70,62 +71,62 @@ trait RepositoryService { self: AccountService => Repositories.filter { t => (t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind) - }.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName) + }.map { t => t.originUserName -> t.originRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) Repositories.filter { t => (t.parentUserName === oldUserName.bind) && (t.parentRepositoryName === oldRepositoryName.bind) - }.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName) + }.map { t => t.originUserName -> t.originRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) // Updates activity fk before deleting repository because activity is sorted by activityId // and it can't be changed by deleting-and-inserting record. Activities.filter(_.byRepository(oldUserName, oldRepositoryName)).list.foreach { activity => Activities.filter(_.activityId === activity.activityId.bind) - .map(x => (x.userName, x.repositoryName)).update(newUserName, newRepositoryName) + .map(x => (x.userName, x.repositoryName)).unsafeUpdate(newUserName, newRepositoryName) } deleteRepository(oldUserName, oldRepositoryName) - WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*) - - val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list - Issues.insertAll(issues.map { x => x.copy( - userName = newUserName, - repositoryName = newRepositoryName, - milestoneId = x.milestoneId.map { id => - newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId - } - )} :_*) - - PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*) +// +// val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list +// Issues.insertAll(issues.map { x => x.copy( +// userName = newUserName, +// repositoryName = newRepositoryName, +// milestoneId = x.milestoneId.map { id => +// newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId +// } +// )} :_*) +// +// PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) // Update source repository of pull requests PullRequests.filter { t => (t.requestUserName === oldUserName.bind) && (t.requestRepositoryName === oldRepositoryName.bind) - }.map { t => t.requestUserName -> t.requestRepositoryName }.update(newUserName, newRepositoryName) + }.map { t => t.requestUserName -> t.requestRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) - // Convert labelId - val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap - val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap - IssueLabels.insertAll(issueLabels.map(x => x.copy( - labelId = newLabelMap(oldLabelMap(x.labelId)), - userName = newUserName, - repositoryName = newRepositoryName - )) :_*) - - if(account.isGroupAccount){ - Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*) - } else { - Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) - } +// // Convert labelId +// val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap +// val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap +// IssueLabels.insertAll(issueLabels.map(x => x.copy( +// labelId = newLabelMap(oldLabelMap(x.labelId)), +// userName = newUserName, +// repositoryName = newRepositoryName +// )) :_*) +// +// if(account.isGroupAccount){ +// Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*) +// } else { +// Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) +// } // Update activity messages Activities.filter { t => @@ -133,7 +134,7 @@ trait RepositoryService { self: AccountService => (t.message like s"%:${oldUserName}/${oldRepositoryName}#%") || (t.message like s"%:${oldUserName}/${oldRepositoryName}@%") }.map { t => t.activityId -> t.message }.list.foreach { case (activityId, message) => - Activities.filter(_.activityId === activityId.bind).map(_.message).update( + Activities.filter(_.activityId === activityId.bind).map(_.message).unsafeUpdate( message .replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]") .replace(s"[branch:${oldUserName}/${oldRepositoryName}#" ,s"[branch:${newUserName}/${newRepositoryName}#") @@ -148,19 +149,19 @@ trait RepositoryService { self: AccountService => } def deleteRepository(userName: String, repositoryName: String)(implicit s: Session): Unit = { - Activities .filter(_.byRepository(userName, repositoryName)).delete - Collaborators .filter(_.byRepository(userName, repositoryName)).delete - CommitComments.filter(_.byRepository(userName, repositoryName)).delete - IssueLabels .filter(_.byRepository(userName, repositoryName)).delete - Labels .filter(_.byRepository(userName, repositoryName)).delete - IssueComments .filter(_.byRepository(userName, repositoryName)).delete - PullRequests .filter(_.byRepository(userName, repositoryName)).delete - Issues .filter(_.byRepository(userName, repositoryName)).delete - IssueId .filter(_.byRepository(userName, repositoryName)).delete - Milestones .filter(_.byRepository(userName, repositoryName)).delete - WebHooks .filter(_.byRepository(userName, repositoryName)).delete - WebHookEvents .filter(_.byRepository(userName, repositoryName)).delete - Repositories .filter(_.byRepository(userName, repositoryName)).delete + Activities .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Collaborators .filter(_.byRepository(userName, repositoryName)).unsafeDelete + CommitComments.filter(_.byRepository(userName, repositoryName)).unsafeDelete + IssueLabels .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Labels .filter(_.byRepository(userName, repositoryName)).unsafeDelete + IssueComments .filter(_.byRepository(userName, repositoryName)).unsafeDelete + PullRequests .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Issues .filter(_.byRepository(userName, repositoryName)).unsafeDelete + IssueId .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Milestones .filter(_.byRepository(userName, repositoryName)).unsafeDelete + WebHooks .filter(_.byRepository(userName, repositoryName)).unsafeDelete + WebHookEvents .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Repositories .filter(_.byRepository(userName, repositoryName)).unsafeDelete // Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME Repositories @@ -171,7 +172,7 @@ trait RepositoryService { self: AccountService => Repositories .filter(_.byRepository(userName, repositoryName)) .map(x => (x.originUserName?, x.originRepositoryName?)) - .update(None, None) + .unsafeUpdate(None, None) } // Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME @@ -183,7 +184,7 @@ trait RepositoryService { self: AccountService => Repositories .filter(_.byRepository(userName, repositoryName)) .map(x => (x.parentUserName?, x.parentRepositoryName?)) - .update(None, None) + .unsafeUpdate(None, None) } } @@ -313,7 +314,7 @@ trait RepositoryService { self: AccountService => * Updates the last activity date of the repository. */ def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit = - Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate) + Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).unsafeUpdate(currentDate) /** * Save repository options. @@ -324,13 +325,13 @@ trait RepositoryService { self: AccountService => enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit = Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => (r.description.?, r.isPrivate, r.enableIssues, r.externalIssuesUrl.?, r.enableWiki, r.allowWikiEditing, r.externalWikiUrl.?, r.updatedDate) } - .update (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) + .unsafeUpdate (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) def saveRepositoryDefaultBranch(userName: String, repositoryName: String, defaultBranch: String)(implicit s: Session): Unit = Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => r.defaultBranch } - .update (defaultBranch) + .unsafeUpdate (defaultBranch) /** * Add collaborator to the repository. @@ -340,7 +341,7 @@ trait RepositoryService { self: AccountService => * @param collaboratorName the collaborator name */ def addCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit = - Collaborators insert Collaborator(userName, repositoryName, collaboratorName) + Collaborators unsafeInsert Collaborator(userName, repositoryName, collaboratorName) /** * Remove collaborator from the repository. @@ -350,7 +351,7 @@ trait RepositoryService { self: AccountService => * @param collaboratorName the collaborator name */ def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit = - Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete + Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).unsafeDelete /** * Remove all collaborators from the repository. @@ -359,7 +360,7 @@ trait RepositoryService { self: AccountService => * @param repositoryName the repository name */ def removeCollaborators(userName: String, repositoryName: String)(implicit s: Session): Unit = - Collaborators.filter(_.byRepository(userName, repositoryName)).delete + Collaborators.filter(_.byRepository(userName, repositoryName)).unsafeDelete /** * Returns the list of collaborators name which is sorted with ascending order. diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index 5feb1192f..357fb3660 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -2,12 +2,13 @@ package gitbucket.core.service import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ -import profile.simple._ +import profile._ +import profile.api._ trait SshKeyService { def addPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit = - SshKeys insert SshKey(userName = userName, title = title, publicKey = publicKey) + SshKeys unsafeInsert SshKey(userName = userName, title = title, publicKey = publicKey) def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] = SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index d50f9e7f5..94fc512b3 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.api._ 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.api._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.RepositoryName import gitbucket.core.service.RepositoryService.RepositoryInfo @@ -32,14 +33,14 @@ trait WebHookService { /** 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,27 +49,27 @@ trait WebHookService { 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 => - WebHookEvents insert WebHookEvent(owner, repository, url, event) + WebHooks unsafeInsert WebHook(owner, repository, url, ctype, token) + events.toSet.map { event: WebHook.Event => + WebHookEvents unsafeInsert WebHookEvent(owner, repository, url, event) } } 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 => - WebHookEvents insert WebHookEvent(owner, repository, url, event) + WebHooks.filter(_.byPrimaryKey(owner, repository, url)).map(w => (w.ctype, w.token)).unsafeUpdate((ctype, token)) + WebHookEvents.filter(_.byWebHook(owner, repository, url)).unsafeDelete + events.toSet.map { event: WebHook.Event => + WebHookEvents unsafeInsert WebHookEvent(owner, repository, url, event) } } def deleteWebHook(owner: String, repository: String, url :String)(implicit s: Session): Unit = - WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete + WebHooks.filter(_.byPrimaryKey(owner, repository, url)).unsafeDelete def callWebHookOf(owner: String, repository: String, event: WebHook.Event)(makePayload: => Option[WebHookPayload]) (implicit s: Session, c: JsonFormat.Context): Unit = { diff --git a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala index 8d55a813b..e29bea9e8 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.service.{ActivityService, SystemSettingsService} 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 bad06e1a9..e3fff33ee 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.scalatra.ScalatraBase 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 @@ class TransactionFilter extends Filter { // 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 a2f18e752..3abfb2273 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 8ed2cfb99..6b9a60e14 100644 --- a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala +++ b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala @@ -2,9 +2,9 @@ package gitbucket.core.ssh 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 ec68d0bb6..073e516c9 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -2,9 +2,11 @@ package gitbucket.core.util import com.typesafe.config.ConfigFactory import java.io.File + import Directory._ +import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, SlickBlockingAPI} 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 { @@ -32,14 +34,14 @@ object DatabaseConfig { 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 slickDriver: SlickBlockingAPI = DatabaseType(url).slickDriver lazy val liquiDriver: AbstractJdbcDatabase = DatabaseType(url).liquiDriver } sealed trait DatabaseType { val jdbcDriver: String - val slickDriver: slick.driver.JdbcProfile + val slickDriver: SlickBlockingAPI val liquiDriver: AbstractJdbcDatabase } @@ -59,13 +61,13 @@ object DatabaseType { 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() } diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 36ec89d9d..3270bb0ef 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 From bfbf90158b60080f5a478d45f6b05bfa132f4845 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 12 Aug 2016 20:51:59 +0900 Subject: [PATCH 02/27] Replace returning with returningId which is provided by blocking-slick --- .../scala/gitbucket/core/model/Comment.scala | 10 +-- .../gitbucket/core/plugin/Sessions.scala | 2 +- .../core/service/CommitStatusService.scala | 2 +- .../core/service/CommitsService.scala | 2 +- .../core/service/IssuesService.scala | 79 ++++++++++--------- .../gitbucket/core/util/StringUtil.scala | 15 ++++ 6 files changed, 60 insertions(+), 50 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index 5e3c110c1..5a6eb7506 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -7,11 +7,8 @@ trait Comment { trait IssueCommentComponent extends TemplateComponent { self: Profile => 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) @@ -40,11 +37,8 @@ case class IssueComment ( trait CommitCommentComponent extends TemplateComponent { self: Profile => 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/plugin/Sessions.scala b/src/main/scala/gitbucket/core/plugin/Sessions.scala index dc3870211..e3304859b 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/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 90a2d6b41..f7d730c81 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -24,7 +24,7 @@ trait CommitStatusService { }.update((state, targetUrl, now, creator.userName, description)) id } - case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus( + case None => (CommitStatuses returningId CommitStatuses.map(_.commitStatusId)) unsafeInsert CommitStatus( userName = userName, repositoryName = repositoryName, commitId = sha, diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 68a2a5332..fae4f7cfe 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -30,7 +30,7 @@ trait CommitsService { 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 returningId CommitComments.map(_.commentId) unsafeInsert CommitComment( userName = owner, repositoryName = repository, commitId = commitId, diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index be758220f..27ea0e018 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -2,18 +2,16 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil.CommitInfo -import gitbucket.core.util.StringUtil import profile._ import profile.api._ import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.model.{Account, CommitState, Issue, IssueComment, IssueLabel, Label, PullRequest, Repository} -import slick.profile.SqlUtilsComponent //import scala.slick.jdbc.{StaticQuery => Q} -trait IssuesService extends SqlUtilsComponent { +trait IssuesService { self: AccountService => import IssuesService._ @@ -192,6 +190,7 @@ trait IssuesService extends SqlUtilsComponent { } /** for api + * * @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner) */ def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*) @@ -272,30 +271,31 @@ trait IssuesService extends SqlUtilsComponent { def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String], assignedUserName: Option[String], milestoneId: Option[Int], - isPullRequest: Boolean = false)(implicit s: Session) = - // next id number - sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] - .firstOption.filter { id => - Issues unsafeInsert Issue( - owner, - repository, - id, - loginUser, - milestoneId, - assignedUserName, - title, - content, - false, - currentDate, - currentDate, - isPullRequest) - - // increment issue id - IssueId - .filter (_.byPrimaryKey(owner, repository)) - .map (_.issueId) - .unsafeUpdate (id) > 0 - } get + isPullRequest: Boolean = false)(implicit s: Session) = 0 +// TODO [Slick3] +// // next id number +// sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] +// .firstOption.filter { id => +// Issues unsafeInsert Issue( +// owner, +// repository, +// id, +// loginUser, +// milestoneId, +// assignedUserName, +// title, +// content, +// false, +// currentDate, +// currentDate, +// isPullRequest) +// +// // increment issue id +// IssueId +// .filter (_.byPrimaryKey(owner, repository)) +// .map (_.issueId) +// .unsafeUpdate (id) > 0 +// } get def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = IssueLabels unsafeInsert IssueLabel(owner, repository, issueId, labelId) @@ -304,16 +304,17 @@ trait IssuesService extends SqlUtilsComponent { IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) unsafeDelete 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 returningId IssueComments.map(_.commentId) unsafeInsert 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) = @@ -418,7 +419,7 @@ trait IssuesService extends SqlUtilsComponent { } 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. @@ -430,7 +431,7 @@ trait IssuesService extends SqlUtilsComponent { } 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/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index f6e4bc040..aef8e623e 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -98,4 +98,19 @@ object StringUtil { def extractCloseId(message: String): Iterator[String] = "(?i)(? b append '^' append c + case _ => b append c + } + b.toString + } + + } From 4f78a3615c1fdb13697a23f9794b185c711882cb Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 03:35:44 +0900 Subject: [PATCH 03/27] Fix for date columns --- .../scala/gitbucket/core/model/Comment.scala | 2 + .../core/service/CommitsService.scala | 11 +- .../core/service/IssuesService.scala | 175 +++++++----------- .../core/service/RepositoryService.scala | 18 +- 4 files changed, 86 insertions(+), 120 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index 5a6eb7506..310be7e25 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -7,6 +7,7 @@ trait Comment { trait IssueCommentComponent extends TemplateComponent { self: Profile => import profile.api._ + import self._ lazy val IssueComments = TableQuery[IssueComments] @@ -37,6 +38,7 @@ case class IssueComment ( trait CommitCommentComponent extends TemplateComponent { self: Profile => import profile.api._ + import self._ lazy val CommitComments = TableQuery[CommitComments] diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index fae4f7cfe..89467cb38 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -43,13 +43,14 @@ trait CommitsService { updatedDate = currentDate, issueId = issueId) - def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = + def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = { + import gitbucket.core.model.Profile.dateColumnType CommitComments .filter (_.byPrimaryKey(commentId)) - .map { t => - t.content -> t.updatedDate - }.update (content, currentDate) + .map { t => (t.content, t.updatedDate) } + .unsafeUpdate (content, currentDate) + } def deleteCommitComment(commentId: Int)(implicit s: Session) = - CommitComments filter (_.byPrimaryKey(commentId)) delete + CommitComments filter (_.byPrimaryKey(commentId)) unsafeDelete } diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 27ea0e018..273295943 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -90,63 +90,25 @@ trait IssuesService { .list.toMap } - def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] = { - Map.empty -// TODO [Slick3] -// if(issueList.isEmpty){ -// Map.empty -// } 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 -// } + 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 { + None + } } /** @@ -175,18 +137,17 @@ trait IssuesService { 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))) 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)) - }} toList + 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, + getCommitStatues(issue.userName, issue.repositoryName, issue.issueId)) + }} toList } /** for api @@ -271,31 +232,30 @@ trait IssuesService { def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String], assignedUserName: Option[String], milestoneId: Option[Int], - isPullRequest: Boolean = false)(implicit s: Session) = 0 -// TODO [Slick3] -// // next id number -// sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] -// .firstOption.filter { id => -// Issues unsafeInsert Issue( -// owner, -// repository, -// id, -// loginUser, -// milestoneId, -// assignedUserName, -// title, -// content, -// false, -// currentDate, -// currentDate, -// isPullRequest) -// -// // increment issue id -// IssueId -// .filter (_.byPrimaryKey(owner, repository)) -// .map (_.issueId) -// .unsafeUpdate (id) > 0 -// } get + isPullRequest: Boolean = false)(implicit s: Session) = + // next id number + sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] + .firstOption.filter { id => + Issues unsafeInsert Issue( + owner, + repository, + id, + loginUser, + milestoneId, + assignedUserName, + title, + content, + false, + currentDate, + currentDate, + isPullRequest) + + // increment issue id + IssueId + .filter (_.byPrimaryKey(owner, repository)) + .map (_.issueId) + .unsafeUpdate (id) > 0 + } get def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = IssueLabels unsafeInsert IssueLabel(owner, repository, issueId, labelId) @@ -316,14 +276,13 @@ trait IssuesService { 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) = { + import gitbucket.core.model.Profile.dateColumnType Issues .filter (_.byPrimaryKey(owner, repository, issueId)) - .map { t => - (t.title, t.content.?, t.updatedDate) - } + .map { t => (t.title, t.content.?, t.updatedDate) } .unsafeUpdate (title, content, currentDate) + } def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session) = @@ -333,24 +292,18 @@ trait IssuesService { milestoneId: Option[Int])(implicit s: Session) = Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).unsafeUpdate (milestoneId) - def updateComment(commentId: Int, content: String)(implicit s: Session) = - IssueComments - .filter (_.byPrimaryKey(commentId)) - .map { t => - t.content -> t.updatedDate - } - .unsafeUpdate (content, currentDate) + def updateComment(commentId: Int, content: String)(implicit s: Session) = { + import gitbucket.core.model.Profile.dateColumnType + IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).unsafeUpdate(content, currentDate) + } def deleteComment(commentId: Int)(implicit s: Session) = IssueComments filter (_.byPrimaryKey(commentId)) unsafeDelete - 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 - } - .usnafeUpdate (closed, currentDate) + def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = { + import gitbucket.core.model.Profile.dateColumnType + (Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).unsafeUpdate((closed, currentDate)) + } /** * Search issues by keyword. diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 568a3e3cf..539c19efa 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -232,6 +232,8 @@ trait RepositoryService { self: AccountService => * @return the repository information list */ def getAllRepositories(userName: String)(implicit s: Session): List[(String, String)] = { + import gitbucket.core.model.Profile.dateColumnType + Repositories.filter { t1 => (t1.isPrivate === false.bind) || (t1.userName === userName.bind) || @@ -241,8 +243,9 @@ trait RepositoryService { self: AccountService => }.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] = { + import gitbucket.core.model.Profile.dateColumnType + Repositories.filter { t1 => (t1.userName === userName.bind) || (Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName === userName.bind)} exists) @@ -275,6 +278,8 @@ trait RepositoryService { self: AccountService => def getVisibleRepositories(loginAccount: Option[Account], repositoryUserName: Option[String] = None, withoutPhysicalInfo: Boolean = false) (implicit s: Session): List[RepositoryInfo] = { + import gitbucket.core.model.Profile.dateColumnType + (loginAccount match { // for Administrators case Some(x) if(x.isAdmin) => Repositories @@ -313,8 +318,10 @@ trait RepositoryService { self: AccountService => /** * 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 = { + import gitbucket.core.model.Profile.dateColumnType Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).unsafeUpdate(currentDate) + } /** * Save repository options. @@ -322,10 +329,13 @@ trait RepositoryService { self: AccountService => def saveRepositoryOptions(userName: String, repositoryName: String, description: Option[String], isPrivate: Boolean, enableIssues: Boolean, externalIssuesUrl: Option[String], - enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit = + enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit = { + import gitbucket.core.model.Profile.dateColumnType + Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => (r.description.?, r.isPrivate, r.enableIssues, r.externalIssuesUrl.?, r.enableWiki, r.allowWikiEditing, r.externalWikiUrl.?, r.updatedDate) } .unsafeUpdate (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) + } def saveRepositoryDefaultBranch(userName: String, repositoryName: String, defaultBranch: String)(implicit s: Session): Unit = From 77641185af9284173d06d13aa6feabce5557a230 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 04:21:59 +0900 Subject: [PATCH 04/27] Fix all compilation error and it works! --- .../core/service/AccessTokenService.scala | 7 +- .../core/service/PullRequestService.scala | 2 +- .../core/service/RepositoryService.scala | 75 ++++++++++--------- .../gitbucket/core/util/DatabaseConfig.scala | 16 ++-- 4 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 61df80a69..ca20af309 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -26,15 +26,16 @@ trait AccessTokenService { 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 (Query(AccessTokens.filter(_.tokenHash === hash.bind).exists).first) val newToken = AccessToken( userName = userName, note = note, tokenHash = hash) - val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) += newToken + val tokenId = (AccessTokens returningId AccessTokens.map(_.accessTokenId)) unsafeInsert newToken (tokenId, token) } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index 71175789d..b6912a94a 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -111,7 +111,7 @@ trait PullRequestService { self: IssuesService => */ 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(Query(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists).first){ val (commitIdTo, commitIdFrom) = JGitUtil.updatePullRequest( pullreq.userName, pullreq.repositoryName, pullreq.branch, pullreq.issueId, pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch) diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 539c19efa..38f4c7bb8 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -86,47 +86,52 @@ trait RepositoryService { self: AccountService => deleteRepository(oldUserName, oldRepositoryName) -// WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*) -// -// val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list -// Issues.insertAll(issues.map { x => x.copy( -// userName = newUserName, -// repositoryName = newRepositoryName, -// milestoneId = x.milestoneId.map { id => -// newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId -// } -// )} :_*) -// -// PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*) + + val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list + Issues.insertAll(issues.map { x => x.copy( + userName = newUserName, + repositoryName = newRepositoryName, + milestoneId = x.milestoneId.map { id => + newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId + } + )} :_*) + + PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) // Update source repository of pull requests PullRequests.filter { t => (t.requestUserName === oldUserName.bind) && (t.requestRepositoryName === oldRepositoryName.bind) }.map { t => t.requestUserName -> t.requestRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) -// // Convert labelId -// val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap -// val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap -// IssueLabels.insertAll(issueLabels.map(x => x.copy( -// labelId = newLabelMap(oldLabelMap(x.labelId)), -// userName = newUserName, -// repositoryName = newRepositoryName -// )) :_*) -// -// if(account.isGroupAccount){ -// Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*) -// } else { -// Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) -// } + // Convert labelId + val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap + val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap + IssueLabels.insertAll(issueLabels.map(x => x.copy( + labelId = newLabelMap(oldLabelMap(x.labelId)), + userName = newUserName, + repositoryName = newRepositoryName + )) :_*) + IssueLabels.insertAll(issueLabels.map(x => x.copy( + labelId = newLabelMap(oldLabelMap(x.labelId)), + userName = newUserName, + repositoryName = newRepositoryName + )) :_*) + + if(account.isGroupAccount){ + Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*) + } else { + Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*) + } // Update activity messages Activities.filter { t => diff --git a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala index 073e516c9..63790660d 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -73,13 +73,15 @@ object DatabaseType { 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 SlickBlockingAPI { + 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 + } + } } From 89dfaeeb93fb6d19fa3ab9411e9727e6e13a27d9 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 04:31:22 +0900 Subject: [PATCH 05/27] Turn to use returning instead of returningId --- .../scala/gitbucket/core/service/AccessTokenService.scala | 2 +- .../gitbucket/core/service/CommitStatusService.scala | 2 +- .../scala/gitbucket/core/service/CommitsService.scala | 8 +------- src/main/scala/gitbucket/core/service/IssuesService.scala | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index ca20af309..822456c54 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -35,7 +35,7 @@ trait AccessTokenService { userName = userName, note = note, tokenHash = hash) - val tokenId = (AccessTokens returningId AccessTokens.map(_.accessTokenId)) unsafeInsert newToken + val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) unsafeInsert newToken (tokenId, token) } diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index f7d730c81..45b5bb706 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -24,7 +24,7 @@ trait CommitStatusService { }.update((state, targetUrl, now, creator.userName, description)) id } - case None => (CommitStatuses returningId CommitStatuses.map(_.commitStatusId)) unsafeInsert CommitStatus( + case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) unsafeInsert CommitStatus( userName = userName, repositoryName = repositoryName, commitId = sha, diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 89467cb38..f2f37b308 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -1,15 +1,9 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment -import gitbucket.core.util.{StringUtil, Implicits} - -//import slick.jdbc.{StaticQuery => Q} -//import Q.interpolation import gitbucket.core.model.Profile._ import profile._ import profile.api._ -//import Implicits._ -//import StringUtil._ trait CommitsService { @@ -30,7 +24,7 @@ trait CommitsService { 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 returningId CommitComments.map(_.commentId) unsafeInsert CommitComment( + CommitComments returning CommitComments.map(_.commentId) unsafeInsert CommitComment( userName = owner, repositoryName = repository, commitId = commitId, diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 273295943..ddad69c45 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -265,7 +265,7 @@ trait IssuesService { def createComment(owner: String, repository: String, loginUser: String, issueId: Int, content: String, action: String)(implicit s: Session): Int = { - IssueComments returningId IssueComments.map(_.commentId) unsafeInsert IssueComment( + IssueComments returning IssueComments.map(_.commentId) unsafeInsert IssueComment( userName = owner, repositoryName = repository, issueId = issueId, From 7937944c107e2cf969770bf7ce972c3c6a8fedc0 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 11:05:40 +0900 Subject: [PATCH 06/27] Move dataColumnType import statement to the top --- .../gitbucket/core/service/AccountService.scala | 5 ++--- .../gitbucket/core/service/CommitStatusService.scala | 7 +------ .../gitbucket/core/service/CommitsService.scala | 3 +-- .../scala/gitbucket/core/service/IssuesService.scala | 12 ++++-------- .../gitbucket/core/service/MilestonesService.scala | 1 - .../gitbucket/core/service/RepositoryService.scala | 12 ++---------- 6 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index d6344cb96..cfeeefc51 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 StringUtil._ import gitbucket.core.service.SystemSettingsService.SystemSettings import profile._ import profile.api._ -import StringUtil._ -import org.slf4j.LoggerFactory -// TODO Why is direct import required? import gitbucket.core.model.Profile.dateColumnType trait AccountService { diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 45b5bb706..a290d86e5 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -3,13 +3,8 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ import profile._ import profile.api._ - -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 gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.model.{CommitState, CommitStatus, Account} trait CommitStatusService { /** insert or update */ diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index f2f37b308..38584ad6b 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -4,7 +4,7 @@ import gitbucket.core.model.CommitComment import gitbucket.core.model.Profile._ import profile._ import profile.api._ - +import gitbucket.core.model.Profile.dateColumnType trait CommitsService { @@ -38,7 +38,6 @@ trait CommitsService { issueId = issueId) def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = { - import gitbucket.core.model.Profile.dateColumnType CommitComments .filter (_.byPrimaryKey(commentId)) .map { t => (t.content, t.updatedDate) } diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index ddad69c45..a69b3cbcc 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -1,14 +1,13 @@ package gitbucket.core.service -import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil.CommitInfo -import profile._ -import profile.api._ import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.model.{Account, CommitState, Issue, IssueComment, IssueLabel, Label, PullRequest, Repository} - -//import scala.slick.jdbc.{StaticQuery => Q} +import gitbucket.core.model.Profile._ +import profile._ +import profile.api._ +import gitbucket.core.model.Profile.dateColumnType trait IssuesService { @@ -277,7 +276,6 @@ trait IssuesService { } def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session) = { - import gitbucket.core.model.Profile.dateColumnType Issues .filter (_.byPrimaryKey(owner, repository, issueId)) .map { t => (t.title, t.content.?, t.updatedDate) } @@ -293,7 +291,6 @@ trait IssuesService { Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).unsafeUpdate (milestoneId) def updateComment(commentId: Int, content: String)(implicit s: Session) = { - import gitbucket.core.model.Profile.dateColumnType IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).unsafeUpdate(content, currentDate) } @@ -301,7 +298,6 @@ trait IssuesService { IssueComments filter (_.byPrimaryKey(commentId)) unsafeDelete def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = { - import gitbucket.core.model.Profile.dateColumnType (Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).unsafeUpdate((closed, currentDate)) } diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index 9187bae41..bb6b88044 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -4,7 +4,6 @@ import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ import profile._ import profile.api._ -// TODO Why is direct import required? import gitbucket.core.model.Profile.dateColumnType trait MilestonesService { diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 38f4c7bb8..486faa792 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -1,11 +1,12 @@ package gitbucket.core.service import gitbucket.core.controller.Context +import gitbucket.core.util.JGitUtil import gitbucket.core.model.{Collaborator, Repository, Account} import gitbucket.core.model.Profile._ -import gitbucket.core.util.JGitUtil import profile._ import profile.api._ +import gitbucket.core.model.Profile.dateColumnType trait RepositoryService { self: AccountService => import RepositoryService._ @@ -237,8 +238,6 @@ trait RepositoryService { self: AccountService => * @return the repository information list */ def getAllRepositories(userName: String)(implicit s: Session): List[(String, String)] = { - import gitbucket.core.model.Profile.dateColumnType - Repositories.filter { t1 => (t1.isPrivate === false.bind) || (t1.userName === userName.bind) || @@ -249,8 +248,6 @@ trait RepositoryService { self: AccountService => } def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false)(implicit s: Session): List[RepositoryInfo] = { - import gitbucket.core.model.Profile.dateColumnType - Repositories.filter { t1 => (t1.userName === userName.bind) || (Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName === userName.bind)} exists) @@ -283,8 +280,6 @@ trait RepositoryService { self: AccountService => def getVisibleRepositories(loginAccount: Option[Account], repositoryUserName: Option[String] = None, withoutPhysicalInfo: Boolean = false) (implicit s: Session): List[RepositoryInfo] = { - import gitbucket.core.model.Profile.dateColumnType - (loginAccount match { // for Administrators case Some(x) if(x.isAdmin) => Repositories @@ -324,7 +319,6 @@ trait RepositoryService { self: AccountService => * Updates the last activity date of the repository. */ def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit = { - import gitbucket.core.model.Profile.dateColumnType Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).unsafeUpdate(currentDate) } @@ -335,8 +329,6 @@ trait RepositoryService { self: AccountService => description: Option[String], isPrivate: Boolean, enableIssues: Boolean, externalIssuesUrl: Option[String], enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit = { - import gitbucket.core.model.Profile.dateColumnType - Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => (r.description.?, r.isPrivate, r.enableIssues, r.externalIssuesUrl.?, r.enableWiki, r.allowWikiEditing, r.externalWikiUrl.?, r.updatedDate) } .unsafeUpdate (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) From 161e6dc8092ad9b652b182a17b69645c859eb525 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 11:46:41 +0900 Subject: [PATCH 07/27] Use Slick2 compatible API --- .../scala/gitbucket/core/model/Profile.scala | 6 +- .../core/service/AccessTokenService.scala | 6 +- .../core/service/AccountService.scala | 22 +++---- .../core/service/ActivityService.scala | 40 ++++++------- .../core/service/CommitStatusService.scala | 4 +- .../core/service/CommitsService.scala | 8 +-- .../core/service/HandleCommentService.scala | 2 +- .../core/service/IssuesService.scala | 24 ++++---- .../core/service/LabelsService.scala | 23 +++---- .../gitbucket/core/service/MergeService.scala | 2 - .../core/service/MilestonesService.scala | 4 +- .../core/service/ProtectedBranchService.scala | 6 +- .../core/service/PullRequestService.scala | 4 +- .../service/RepositoryCreationService.scala | 2 +- .../service/RepositorySearchService.scala | 2 +- .../core/service/RepositoryService.scala | 60 +++++++++---------- .../core/service/SshKeyService.scala | 4 +- .../core/service/WebHookService.scala | 14 ++--- .../gitbucket/core/util/DatabaseConfig.scala | 8 +-- 19 files changed, 116 insertions(+), 125 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/Profile.scala b/src/main/scala/gitbucket/core/model/Profile.scala index fb5e63387..ad01a4c34 100644 --- a/src/main/scala/gitbucket/core/model/Profile.scala +++ b/src/main/scala/gitbucket/core/model/Profile.scala @@ -1,11 +1,11 @@ package gitbucket.core.model import gitbucket.core.util.DatabaseConfig -import com.github.takezoe.slick.blocking.SlickBlockingAPI +import com.github.takezoe.slick.blocking.BlockingJdbcProfile trait Profile { - val profile: SlickBlockingAPI - import profile.api._ + val profile: BlockingJdbcProfile + import profile.blockingApi._ /** * java.util.Date Mapped Column Types diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 822456c54..84524a91d 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -2,7 +2,7 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil @@ -35,7 +35,7 @@ trait AccessTokenService { userName = userName, note = note, tokenHash = hash) - val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) unsafeInsert newToken + val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) insert newToken (tokenId, token) } @@ -50,7 +50,7 @@ trait AccessTokenService { AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit = - AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) unsafeDelete + AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete } diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index cfeeefc51..d6ab131b7 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -7,7 +7,7 @@ import gitbucket.core.util.{StringUtil, LDAPUtil} import StringUtil._ import gitbucket.core.service.SystemSettingsService.SystemSettings import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait AccountService { @@ -105,7 +105,7 @@ trait AccountService { def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String]) (implicit s: Session): Unit = - Accounts unsafeInsert Account( + Accounts insert Account( userName = userName, password = password, fullName = fullName, @@ -123,7 +123,7 @@ trait AccountService { Accounts .filter { a => a.userName === account.userName.bind } .map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed) } - .unsafeUpdate ( + .update ( account.password, account.fullName, account.mailAddress, @@ -135,13 +135,13 @@ trait AccountService { account.isRemoved) def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit = - Accounts.filter(_.userName === userName.bind).map(_.image.?).unsafeUpdate(image) + Accounts.filter(_.userName === userName.bind).map(_.image.?).update(image) def updateLastLoginDate(userName: String)(implicit s: Session): Unit = - Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).unsafeUpdate(currentDate) + Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).update(currentDate) def createGroup(groupName: String, url: Option[String])(implicit s: Session): Unit = - Accounts unsafeInsert Account( + Accounts insert Account( userName = groupName, password = "", fullName = groupName, @@ -156,12 +156,12 @@ trait AccountService { isRemoved = false) def updateGroup(groupName: String, url: Option[String], removed: Boolean)(implicit s: Session): Unit = - Accounts.filter(_.userName === groupName.bind).map(t => t.url.? -> t.removed).unsafeUpdate(url, removed) + Accounts.filter(_.userName === groupName.bind).map(t => t.url.? -> t.removed).update(url, removed) def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = { GroupMembers.filter(_.groupName === groupName.bind).delete members.foreach { case (userName, isManager) => - GroupMembers unsafeInsert GroupMember (groupName, userName, isManager) + GroupMembers insert GroupMember (groupName, userName, isManager) } } @@ -179,9 +179,9 @@ trait AccountService { .list def removeUserRelatedData(userName: String)(implicit s: Session): Unit = { - GroupMembers.filter(_.userName === userName.bind).unsafeDelete - Collaborators.filter(_.collaboratorName === userName.bind).unsafeDelete - Repositories.filter(_.userName === userName.bind).unsafeDelete + GroupMembers.filter(_.userName === userName.bind).delete + Collaborators.filter(_.collaboratorName === userName.bind).delete + Repositories.filter(_.userName === userName.bind).delete } def getGroupNames(userName: String)(implicit s: Session): List[String] = { diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 25de82896..a7e61cd97 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -4,13 +4,13 @@ import gitbucket.core.model.Activity import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil import profile._ -import profile.api._ +import profile.blockingApi._ trait ActivityService { def deleteOldActivities(limit: Int)(implicit s: Session): Int = { Activities.map(_.activityId).sortBy(_ desc).drop(limit).firstOption.map { id => - Activities.filter(_.activityId <= id.bind).unsafeDelete + Activities.filter(_.activityId <= id.bind).delete } getOrElse 0 } @@ -49,7 +49,7 @@ trait ActivityService { def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "create_repository", s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]", None, @@ -57,7 +57,7 @@ trait ActivityService { def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "open_issue", s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -65,7 +65,7 @@ trait ActivityService { def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "close_issue", s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -73,7 +73,7 @@ trait ActivityService { def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "close_issue", s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -81,7 +81,7 @@ trait ActivityService { def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "reopen_issue", s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -89,7 +89,7 @@ trait ActivityService { def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "comment_issue", s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]", Some(cut(comment, 200)), @@ -97,7 +97,7 @@ trait ActivityService { def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "comment_issue", s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(cut(comment, 200)), @@ -105,7 +105,7 @@ trait ActivityService { def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "comment_commit", s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]", Some(cut(comment, 200)), @@ -114,7 +114,7 @@ trait ActivityService { def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "create_wiki", s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki", Some(pageName), @@ -122,7 +122,7 @@ trait ActivityService { def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "edit_wiki", s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki", Some(pageName + ":" + commitId), @@ -130,7 +130,7 @@ trait ActivityService { def recordPushActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "push", s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]", Some(commits.map { commit => commit.id + ":" + commit.shortMessage }.mkString("\n")), @@ -138,7 +138,7 @@ trait ActivityService { def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String, tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "create_tag", s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]", None, @@ -146,7 +146,7 @@ trait ActivityService { def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String, tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "delete_tag", s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]", None, @@ -154,7 +154,7 @@ trait ActivityService { def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "create_branch", s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]", None, @@ -162,14 +162,14 @@ trait ActivityService { def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "delete_branch", s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]", None, currentDate) def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "fork", s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]", None, @@ -177,7 +177,7 @@ trait ActivityService { def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "open_pullreq", s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(title), @@ -185,7 +185,7 @@ trait ActivityService { def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String) (implicit s: Session): Unit = - Activities unsafeInsert Activity(userName, repositoryName, activityUserName, + Activities insert Activity(userName, repositoryName, activityUserName, "merge_pullreq", s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]", Some(message), diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index a290d86e5..07fe47f7d 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -2,7 +2,7 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType import gitbucket.core.model.{CommitState, CommitStatus, Account} @@ -19,7 +19,7 @@ trait CommitStatusService { }.update((state, targetUrl, now, creator.userName, description)) id } - case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) unsafeInsert CommitStatus( + case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) insert CommitStatus( userName = userName, repositoryName = repositoryName, commitId = sha, diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 38584ad6b..a7a8fc47e 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -3,7 +3,7 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait CommitsService { @@ -24,7 +24,7 @@ trait CommitsService { 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 returning CommitComments.map(_.commentId) unsafeInsert CommitComment( + CommitComments returning CommitComments.map(_.commentId) insert CommitComment( userName = owner, repositoryName = repository, commitId = commitId, @@ -41,9 +41,9 @@ trait CommitsService { CommitComments .filter (_.byPrimaryKey(commentId)) .map { t => (t.content, t.updatedDate) } - .unsafeUpdate (content, currentDate) + .update (content, currentDate) } def deleteCommitComment(commentId: Int)(implicit s: Session) = - CommitComments filter (_.byPrimaryKey(commentId)) unsafeDelete + 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 92bdb459c..0d73d423d 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.model.Profile._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Notifier -import profile.api._ +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 a69b3cbcc..8395f2f48 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -6,7 +6,7 @@ import gitbucket.core.util.Implicits._ import gitbucket.core.model.{Account, CommitState, Issue, IssueComment, IssueLabel, Label, PullRequest, Repository} import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType @@ -235,7 +235,7 @@ trait IssuesService { // next id number sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] .firstOption.filter { id => - Issues unsafeInsert Issue( + Issues insert Issue( owner, repository, id, @@ -253,18 +253,18 @@ trait IssuesService { IssueId .filter (_.byPrimaryKey(owner, repository)) .map (_.issueId) - .unsafeUpdate (id) > 0 + .update (id) > 0 } get def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = - IssueLabels unsafeInsert IssueLabel(owner, repository, issueId, labelId) + IssueLabels insert IssueLabel(owner, repository, issueId, labelId) def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = - IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) unsafeDelete + 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 returning IssueComments.map(_.commentId) unsafeInsert IssueComment( + IssueComments returning IssueComments.map(_.commentId) insert IssueComment( userName = owner, repositoryName = repository, issueId = issueId, @@ -279,26 +279,26 @@ trait IssuesService { Issues .filter (_.byPrimaryKey(owner, repository, issueId)) .map { t => (t.title, t.content.?, t.updatedDate) } - .unsafeUpdate (title, content, currentDate) + .update (title, content, currentDate) } def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session) = - Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).unsafeUpdate (assignedUserName) + Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).update (assignedUserName) def updateMilestoneId(owner: String, repository: String, issueId: Int, milestoneId: Option[Int])(implicit s: Session) = - Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).unsafeUpdate (milestoneId) + 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)).unsafeUpdate(content, currentDate) + IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate) } def deleteComment(commentId: Int)(implicit s: Session) = - IssueComments filter (_.byPrimaryKey(commentId)) unsafeDelete + 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))).unsafeUpdate((closed, currentDate)) + (Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).update((closed, currentDate)) } /** diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index f7267016a..716ae3203 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -3,10 +3,7 @@ package gitbucket.core.service import gitbucket.core.model.Label import gitbucket.core.model.Profile._ import profile._ -import profile.api._ - -import scala.concurrent.Await -import scala.concurrent.duration.Duration +import profile.blockingApi._ trait LabelsService { @@ -20,16 +17,12 @@ trait LabelsService { Labels.filter(_.byLabel(owner, repository, labelName)).firstOption def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Int = { - // TODO [Slick3]Provide blocking method for returning - val f = s.database.run( - Labels returning Labels.map(_.labelId) += Label( - userName = owner, - repositoryName = repository, - labelName = labelName, - color = color - ) + Labels returning Labels.map(_.labelId) insert Label( + userName = owner, + repositoryName = repository, + labelName = labelName, + color = color ) - Await.result(f, Duration.Inf) } def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String) @@ -39,8 +32,8 @@ trait LabelsService { .update(labelName, color) def deleteLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Unit = { - IssueLabels.filter(_.byLabel(owner, repository, labelId)).unsafeDelete - Labels.filter(_.byPrimaryKey(owner, repository, labelId)).unsafeDelete + IssueLabels.filter(_.byLabel(owner, repository, labelId)).delete + Labels.filter(_.byPrimaryKey(owner, repository, labelId)).delete } } diff --git a/src/main/scala/gitbucket/core/service/MergeService.scala b/src/main/scala/gitbucket/core/service/MergeService.scala index d427d1714..74a329dbe 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 bb6b88044..b94ca392c 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -3,14 +3,14 @@ package gitbucket.core.service import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait MilestonesService { def createMilestone(owner: String, repository: String, title: String, description: Option[String], dueDate: Option[java.util.Date])(implicit s: Session): Unit = - Milestones unsafeInsert Milestone( + Milestones insert Milestone( userName = owner, repositoryName = repository, title = title, diff --git a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala index 849398be9..9cd63b696 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -4,7 +4,7 @@ import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitStat import gitbucket.core.model.Profile._ import gitbucket.core.plugin.ReceiveHook import profile._ -import profile.api._ +import profile.blockingApi._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} @@ -33,9 +33,9 @@ trait ProtectedBranchService { def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String]) (implicit session: Session): Unit = { disableBranchProtection(owner, repository, branch) - ProtectedBranches.unsafeInsert(new ProtectedBranch(owner, repository, branch, includeAdministrators && contexts.nonEmpty)) + ProtectedBranches.insert(new ProtectedBranch(owner, repository, branch, includeAdministrators && contexts.nonEmpty)) contexts.map{ context => - ProtectedBranchContexts.unsafeInsert(new ProtectedBranchContext(owner, repository, branch, context)) + ProtectedBranchContexts.insert(new ProtectedBranchContext(owner, repository, branch, context)) } } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index b6912a94a..fe6326728 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -4,7 +4,7 @@ import gitbucket.core.model.{Account, Issue, PullRequest, WebHook, CommitStatus, import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil import profile._ -import profile.api._ +import profile.blockingApi._ trait PullRequestService { self: IssuesService => @@ -60,7 +60,7 @@ trait PullRequestService { self: IssuesService => def createPullRequest(originUserName: String, originRepositoryName: String, issueId: Int, originBranch: String, requestUserName: String, requestRepositoryName: String, requestBranch: String, commitIdFrom: String, commitIdTo: String)(implicit s: Session): Unit = - PullRequests unsafeInsert PullRequest( + PullRequests insert PullRequest( originUserName, originRepositoryName, issueId, diff --git a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala index 102c8d546..d27d268fd 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -8,7 +8,7 @@ import gitbucket.core.model.Account import org.eclipse.jgit.api.Git import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib.{FileMode, Constants} -import profile.api._ +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 da06a9cb2..09bd2764c 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.treewalk.TreeWalk import org.eclipse.jgit.lib.FileMode import org.eclipse.jgit.api.Git import gitbucket.core.model.Profile._ -import profile.api._ +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 486faa792..46f2fd401 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -5,7 +5,7 @@ import gitbucket.core.util.JGitUtil import gitbucket.core.model.{Collaborator, Repository, Account} import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait RepositoryService { self: AccountService => @@ -25,7 +25,7 @@ trait RepositoryService { self: AccountService => originRepositoryName: Option[String] = None, originUserName: Option[String] = None, parentRepositoryName: Option[String] = None, parentUserName: Option[String] = None) (implicit s: Session): Unit = { - Repositories unsafeInsert + Repositories insert Repository( userName = userName, repositoryName = repositoryName, @@ -46,14 +46,14 @@ trait RepositoryService { self: AccountService => externalWikiUrl = None ) - IssueId unsafeInsert (userName, repositoryName, 0) + IssueId insert (userName, repositoryName, 0) } def renameRepository(oldUserName: String, oldRepositoryName: String, newUserName: String, newRepositoryName: String) (implicit s: Session): Unit = { getAccountByUserName(newUserName).foreach { account => (Repositories filter { t => t.byRepository(oldUserName, oldRepositoryName) } firstOption).map { repository => - Repositories unsafeInsert repository.copy(userName = newUserName, repositoryName = newRepositoryName) + Repositories insert repository.copy(userName = newUserName, repositoryName = newRepositoryName) val webHooks = WebHooks .filter(_.byRepository(oldUserName, oldRepositoryName)).list val webHookEvents = WebHookEvents .filter(_.byRepository(oldUserName, oldRepositoryName)).list @@ -72,17 +72,17 @@ trait RepositoryService { self: AccountService => Repositories.filter { t => (t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind) - }.map { t => t.originUserName -> t.originRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) + }.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName) Repositories.filter { t => (t.parentUserName === oldUserName.bind) && (t.parentRepositoryName === oldRepositoryName.bind) - }.map { t => t.originUserName -> t.originRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) + }.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName) // Updates activity fk before deleting repository because activity is sorted by activityId // and it can't be changed by deleting-and-inserting record. Activities.filter(_.byRepository(oldUserName, oldRepositoryName)).list.foreach { activity => Activities.filter(_.activityId === activity.activityId.bind) - .map(x => (x.userName, x.repositoryName)).unsafeUpdate(newUserName, newRepositoryName) + .map(x => (x.userName, x.repositoryName)).update(newUserName, newRepositoryName) } deleteRepository(oldUserName, oldRepositoryName) @@ -112,7 +112,7 @@ trait RepositoryService { self: AccountService => // Update source repository of pull requests PullRequests.filter { t => (t.requestUserName === oldUserName.bind) && (t.requestRepositoryName === oldRepositoryName.bind) - }.map { t => t.requestUserName -> t.requestRepositoryName }.unsafeUpdate(newUserName, newRepositoryName) + }.map { t => t.requestUserName -> t.requestRepositoryName }.update(newUserName, newRepositoryName) // Convert labelId val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap @@ -140,7 +140,7 @@ trait RepositoryService { self: AccountService => (t.message like s"%:${oldUserName}/${oldRepositoryName}#%") || (t.message like s"%:${oldUserName}/${oldRepositoryName}@%") }.map { t => t.activityId -> t.message }.list.foreach { case (activityId, message) => - Activities.filter(_.activityId === activityId.bind).map(_.message).unsafeUpdate( + Activities.filter(_.activityId === activityId.bind).map(_.message).update( message .replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]") .replace(s"[branch:${oldUserName}/${oldRepositoryName}#" ,s"[branch:${newUserName}/${newRepositoryName}#") @@ -155,19 +155,19 @@ trait RepositoryService { self: AccountService => } def deleteRepository(userName: String, repositoryName: String)(implicit s: Session): Unit = { - Activities .filter(_.byRepository(userName, repositoryName)).unsafeDelete - Collaborators .filter(_.byRepository(userName, repositoryName)).unsafeDelete - CommitComments.filter(_.byRepository(userName, repositoryName)).unsafeDelete - IssueLabels .filter(_.byRepository(userName, repositoryName)).unsafeDelete - Labels .filter(_.byRepository(userName, repositoryName)).unsafeDelete - IssueComments .filter(_.byRepository(userName, repositoryName)).unsafeDelete - PullRequests .filter(_.byRepository(userName, repositoryName)).unsafeDelete - Issues .filter(_.byRepository(userName, repositoryName)).unsafeDelete - IssueId .filter(_.byRepository(userName, repositoryName)).unsafeDelete - Milestones .filter(_.byRepository(userName, repositoryName)).unsafeDelete - WebHooks .filter(_.byRepository(userName, repositoryName)).unsafeDelete - WebHookEvents .filter(_.byRepository(userName, repositoryName)).unsafeDelete - Repositories .filter(_.byRepository(userName, repositoryName)).unsafeDelete + Activities .filter(_.byRepository(userName, repositoryName)).delete + Collaborators .filter(_.byRepository(userName, repositoryName)).delete + CommitComments.filter(_.byRepository(userName, repositoryName)).delete + IssueLabels .filter(_.byRepository(userName, repositoryName)).delete + Labels .filter(_.byRepository(userName, repositoryName)).delete + IssueComments .filter(_.byRepository(userName, repositoryName)).delete + PullRequests .filter(_.byRepository(userName, repositoryName)).delete + Issues .filter(_.byRepository(userName, repositoryName)).delete + IssueId .filter(_.byRepository(userName, repositoryName)).delete + Milestones .filter(_.byRepository(userName, repositoryName)).delete + WebHooks .filter(_.byRepository(userName, repositoryName)).delete + WebHookEvents .filter(_.byRepository(userName, repositoryName)).delete + Repositories .filter(_.byRepository(userName, repositoryName)).delete // Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME Repositories @@ -178,7 +178,7 @@ trait RepositoryService { self: AccountService => Repositories .filter(_.byRepository(userName, repositoryName)) .map(x => (x.originUserName?, x.originRepositoryName?)) - .unsafeUpdate(None, None) + .update(None, None) } // Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME @@ -190,7 +190,7 @@ trait RepositoryService { self: AccountService => Repositories .filter(_.byRepository(userName, repositoryName)) .map(x => (x.parentUserName?, x.parentRepositoryName?)) - .unsafeUpdate(None, None) + .update(None, None) } } @@ -319,7 +319,7 @@ trait RepositoryService { self: AccountService => * Updates the last activity date of the repository. */ def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit = { - Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).unsafeUpdate(currentDate) + Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate) } /** @@ -331,14 +331,14 @@ trait RepositoryService { self: AccountService => enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit = { Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => (r.description.?, r.isPrivate, r.enableIssues, r.externalIssuesUrl.?, r.enableWiki, r.allowWikiEditing, r.externalWikiUrl.?, r.updatedDate) } - .unsafeUpdate (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) + .update (description, isPrivate, enableIssues, externalIssuesUrl, enableWiki, allowWikiEditing, externalWikiUrl, currentDate) } def saveRepositoryDefaultBranch(userName: String, repositoryName: String, defaultBranch: String)(implicit s: Session): Unit = Repositories.filter(_.byRepository(userName, repositoryName)) .map { r => r.defaultBranch } - .unsafeUpdate (defaultBranch) + .update (defaultBranch) /** * Add collaborator to the repository. @@ -348,7 +348,7 @@ trait RepositoryService { self: AccountService => * @param collaboratorName the collaborator name */ def addCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit = - Collaborators unsafeInsert Collaborator(userName, repositoryName, collaboratorName) + Collaborators insert Collaborator(userName, repositoryName, collaboratorName) /** * Remove collaborator from the repository. @@ -358,7 +358,7 @@ trait RepositoryService { self: AccountService => * @param collaboratorName the collaborator name */ def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit = - Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).unsafeDelete + Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete /** * Remove all collaborators from the repository. @@ -367,7 +367,7 @@ trait RepositoryService { self: AccountService => * @param repositoryName the repository name */ def removeCollaborators(userName: String, repositoryName: String)(implicit s: Session): Unit = - Collaborators.filter(_.byRepository(userName, repositoryName)).unsafeDelete + Collaborators.filter(_.byRepository(userName, repositoryName)).delete /** * Returns the list of collaborators name which is sorted with ascending order. diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index 357fb3660..a0e142c42 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -3,12 +3,12 @@ package gitbucket.core.service import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ import profile._ -import profile.api._ +import profile.blockingApi._ trait SshKeyService { def addPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit = - SshKeys unsafeInsert SshKey(userName = userName, title = title, publicKey = publicKey) + SshKeys insert SshKey(userName = userName, title = title, publicKey = publicKey) def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] = SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 94fc512b3..9d6477902 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -7,7 +7,7 @@ import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, import gitbucket.core.model.Profile._ import org.apache.http.client.utils.URLEncodedUtils import profile._ -import profile.api._ +import profile.blockingApi._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.RepositoryName import gitbucket.core.service.RepositoryService.RepositoryInfo @@ -54,22 +54,22 @@ trait WebHookService { .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 unsafeInsert WebHook(owner, repository, url, ctype, token) + WebHooks insert WebHook(owner, repository, url, ctype, token) events.toSet.map { event: WebHook.Event => - WebHookEvents unsafeInsert WebHookEvent(owner, repository, url, event) + WebHookEvents insert WebHookEvent(owner, repository, url, event) } } 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)).unsafeUpdate((ctype, token)) - WebHookEvents.filter(_.byWebHook(owner, repository, url)).unsafeDelete + 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 => - WebHookEvents unsafeInsert WebHookEvent(owner, repository, url, event) + WebHookEvents insert WebHookEvent(owner, repository, url, event) } } def deleteWebHook(owner: String, repository: String, url :String)(implicit s: Session): Unit = - WebHooks.filter(_.byPrimaryKey(owner, repository, url)).unsafeDelete + WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete def callWebHookOf(owner: String, repository: String, event: WebHook.Event)(makePayload: => Option[WebHookPayload]) (implicit s: Session, c: JsonFormat.Context): Unit = { diff --git a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala index 63790660d..9047991fc 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -4,7 +4,7 @@ import com.typesafe.config.ConfigFactory import java.io.File import Directory._ -import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, SlickBlockingAPI} +import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, BlockingJdbcProfile} import liquibase.database.AbstractJdbcDatabase import liquibase.database.core.{H2Database, MySQLDatabase, PostgresDatabase} import org.apache.commons.io.FileUtils @@ -34,14 +34,14 @@ object DatabaseConfig { 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: SlickBlockingAPI = DatabaseType(url).slickDriver + lazy val slickDriver: BlockingJdbcProfile = DatabaseType(url).slickDriver lazy val liquiDriver: AbstractJdbcDatabase = DatabaseType(url).liquiDriver } sealed trait DatabaseType { val jdbcDriver: String - val slickDriver: SlickBlockingAPI + val slickDriver: BlockingJdbcProfile val liquiDriver: AbstractJdbcDatabase } @@ -77,7 +77,7 @@ object DatabaseType { val liquiDriver = new PostgresDatabase() } - object BlockingPostgresDriver extends slick.driver.PostgresDriver with SlickBlockingAPI { + 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 From 4eba7070da4af6f2110616f5d91cd651e6dc6339 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 13:05:08 +0900 Subject: [PATCH 08/27] Use Rep[U].run method --- src/main/scala/gitbucket/core/service/AccessTokenService.scala | 2 +- src/main/scala/gitbucket/core/service/PullRequestService.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 84524a91d..e751cbc80 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -30,7 +30,7 @@ trait AccessTokenService { do { token = makeAccessTokenString hash = tokenToHash(token) - } while (Query(AccessTokens.filter(_.tokenHash === hash.bind).exists).first) + } while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) val newToken = AccessToken( userName = userName, note = note, diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index fe6326728..6fad39264 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -111,7 +111,7 @@ trait PullRequestService { self: IssuesService => */ def updatePullRequests(owner: String, repository: String, branch: String)(implicit s: Session): Unit = getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq => - if(Query(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists).first){ + 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) From 4bef6a4eeb0f7278155807b4186c85c44066fdab Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 13:32:49 +0900 Subject: [PATCH 09/27] Remove unused code --- src/main/scala/gitbucket/core/model/ProtectedBranch.scala | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala b/src/main/scala/gitbucket/core/model/ProtectedBranch.scala index e37caa964..b143b4fcc 100644 --- a/src/main/scala/gitbucket/core/model/ProtectedBranch.scala +++ b/src/main/scala/gitbucket/core/model/ProtectedBranch.scala @@ -1,8 +1,5 @@ package gitbucket.core.model -//import scala.slick.lifted.MappedTo -//import scala.slick.jdbc._ - trait ProtectedBranchComponent extends TemplateComponent { self: Profile => import profile.api._ import self._ From e612991424eea11578261e7d6b32ebc9ca16393b Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 13:40:13 +0900 Subject: [PATCH 10/27] Remove unused code --- src/main/scala/gitbucket/core/model/CommitStatus.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/CommitStatus.scala b/src/main/scala/gitbucket/core/model/CommitStatus.scala index dd82f8384..f6f773b12 100644 --- a/src/main/scala/gitbucket/core/model/CommitStatus.scala +++ b/src/main/scala/gitbucket/core/model/CommitStatus.scala @@ -90,7 +90,5 @@ object CommitState { } } -// implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<)) -// implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.< Date: Sat, 13 Aug 2016 13:58:09 +0900 Subject: [PATCH 11/27] Fix test case --- .../gitbucket/core/service/AccessTokenServiceSpec.scala | 7 ++++--- .../gitbucket/core/service/CommitStatusServiceSpec.scala | 3 ++- .../scala/gitbucket/core/service/IssuesServiceSpec.scala | 5 ++++- .../scala/gitbucket/core/service/ServiceSpecBase.scala | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala index 2df482227..7202b7cb3 100644 --- a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala @@ -2,7 +2,9 @@ package gitbucket.core.service 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 @@ class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase { 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 8c3d36b7b..54cc67023 100644 --- a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala @@ -2,7 +2,8 @@ package gitbucket.core.service 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 ec4e5fccf..5be477cff 100644 --- a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala @@ -9,7 +9,10 @@ class IssuesServiceSpec extends FunSuite with ServiceSpecBase { test("getCommitStatues") { withTestDB { implicit session => val user1 = generateNewUserWithDBRepository("user1","repo1") - def getCommitStatues = dummyService.getCommitStatues(List(("user1","repo1",1),("user1","repo1",2))) + def getCommitStatues = List( + dummyService.getCommitStatues("user1","repo1",1), + dummyService.getCommitStatues("user1","repo1",2) + ) assert(getCommitStatues == Map.empty) diff --git a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala index 87eb29a7c..921901cf7 100644 --- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala +++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala @@ -8,7 +8,8 @@ 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 profile._ +import profile.blockingApi._ import scalaz._ import Scalaz._ From f4a489f4e6673b14c596ec455818258d4b1e2468 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 17:19:38 +0900 Subject: [PATCH 12/27] Bump blocking-slick to 0.0.2 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 49dbf6b84..68aad5f57 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "org.apache.sshd" % "apache-sshd" % "1.2.0", "org.apache.tika" % "tika-core" % "1.13", "com.typesafe.slick" %% "slick" % "3.1.1", - "com.github.takezoe" %% "blocking-slick" % "0.0.2-SNAPSHOT", + "com.github.takezoe" %% "blocking-slick" % "0.0.2", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", "mysql" % "mysql-connector-java" % "5.1.39", From c2538e772f9a192f3ec9b460137549dd387764f1 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 17:34:08 +0900 Subject: [PATCH 13/27] Fix runtime error in issue sorting --- .../core/service/IssuesService.scala | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 8395f2f48..cc41c21de 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -172,14 +172,18 @@ trait IssuesService { searchIssueQuery(repos, condition, pullRequest) .join(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } .sortBy { case (t1, t2) => - (condition.sort match { - case "created" => t1.registeredDate - case "comments" => t2.commentCount - case "updated" => t1.updatedDate - }) match { - case sort: slick.lifted.ColumnOrdered[_] => 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 } } } From 2b5f74b9f31fbf7357f0482ab226d83314a3d1c7 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 13 Aug 2016 17:55:44 +0900 Subject: [PATCH 14/27] Fix test case --- .../core/service/AccessTokenService.scala | 3 +- .../core/service/PullRequestService.scala | 3 +- .../core/service/IssuesServiceSpec.scala | 55 +++++++++---------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index e751cbc80..7ce535f42 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -30,7 +30,8 @@ trait AccessTokenService { do { token = makeAccessTokenString hash = tokenToHash(token) - } while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + //} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + } while (Query(AccessTokens.filter(_.tokenHash === hash.bind).exists).first) val newToken = AccessToken( userName = userName, note = note, diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index 6fad39264..271b9461c 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -111,7 +111,8 @@ trait PullRequestService { self: IssuesService => */ 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(Query(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists).first){ + //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) diff --git a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala index 5be477cff..0238fee9c 100644 --- a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala @@ -6,43 +6,42 @@ import org.scalatest.FunSuite 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 = List( - dummyService.getCommitStatues("user1","repo1",1), - dummyService.getCommitStatues("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 From 34bcc85dcc37ec41d797c5db36df7572c49af93e Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 15 Aug 2016 00:19:01 +0900 Subject: [PATCH 15/27] Revert to Rep[U].run --- build.sbt | 2 +- src/main/scala/gitbucket/core/service/AccessTokenService.scala | 2 +- src/main/scala/gitbucket/core/service/PullRequestService.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 68aad5f57..1e2a8a997 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "org.apache.sshd" % "apache-sshd" % "1.2.0", "org.apache.tika" % "tika-core" % "1.13", "com.typesafe.slick" %% "slick" % "3.1.1", - "com.github.takezoe" %% "blocking-slick" % "0.0.2", + "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/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 7ce535f42..c04fccc24 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -31,7 +31,7 @@ trait AccessTokenService { token = makeAccessTokenString hash = tokenToHash(token) //} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) - } while (Query(AccessTokens.filter(_.tokenHash === hash.bind).exists).first) + } while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run) val newToken = AccessToken( userName = userName, note = note, diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index 271b9461c..fbdee92b6 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -111,7 +111,7 @@ trait PullRequestService { self: IssuesService => */ def updatePullRequests(owner: String, repository: String, branch: String)(implicit s: Session): Unit = getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq => - if(Query(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists).first){ + 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, From 47a55354fe8aac02a1b4090b1698cbc5f10f69fd Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 11 Nov 2016 11:52:40 +0900 Subject: [PATCH 16/27] (refs #1346) Update libraries for Scala 2.12 --- build.sbt | 68 ++++++++++++++++++++-------------------- project/build.properties | 2 +- project/plugins.sbt | 6 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/build.sbt b/build.sbt index ab09c788b..41ef043cc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ val Organization = "io.github.gitbucket" val Name = "gitbucket" val GitBucketVersion = "4.6.0" -val ScalatraVersion = "2.4.1" +val ScalatraVersion = "2.5.0-RC1" val JettyVersion = "9.3.9.v20160517" lazy val root = (project in file(".")).enablePlugins(SbtTwirl, JettyPlugin) @@ -10,7 +10,7 @@ sourcesInBase := false organization := Organization name := Name version := GitBucketVersion -scalaVersion := "2.11.8" +scalaVersion := "2.12.0" // dependency settings resolvers ++= Seq( @@ -20,38 +20,38 @@ resolvers ++= Seq( "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.1.2.201602141800-r", - "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.1.2.201602141800-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.enragedginger" %% "akka-quartz-scheduler" % "1.4.0-akka-2.3.x" exclude("c3p0","c3p0"), - "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" % "1.0.3" % "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.1.2.201602141800-r", + "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.1.2.201602141800-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-SNAPSHOT", + "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" % "3.2.0-M1", + "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.enragedginger" % "akka-quartz-scheduler_2.11" % "1.5.0-akka-2.4.x" exclude("c3p0","c3p0"), // TODO Scala 2.12 + "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" % "1.0.3" % "test", + "ru.yandex.qatools.embed" % "postgresql-embedded" % "1.14" % "test" ) // Compiler settings diff --git a/project/build.properties b/project/build.properties index 35c88bab7..27e88aa11 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 181fe4809..21a6329fe 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ 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.1.1") +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") From 1d03e83d9531f1126c47e91a11fa61bc0e8d65ca Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 14 Dec 2016 12:36:27 +0900 Subject: [PATCH 17/27] (refs #1346)Update to use blocking-slick for Scala 2.12 support --- build.sbt | 5 ++-- project/plugins.sbt | 2 +- .../core/service/AccessTokenService.scala | 11 ++++----- .../core/service/AccountService.scala | 6 ++--- .../core/service/ActivityService.scala | 6 ++--- .../core/service/CommitStatusService.scala | 6 ++--- .../core/service/CommitsService.scala | 4 ++-- .../core/service/IssuesService.scala | 4 ++-- .../core/service/LabelsService.scala | 4 ++-- .../core/service/MilestonesService.scala | 4 ++-- .../core/service/ProtectedBranchService.scala | 6 ++--- .../core/service/PullRequestService.scala | 9 ++++--- .../core/service/RepositoryService.scala | 4 ++-- .../core/service/SshKeyService.scala | 4 ++-- .../core/service/WebHookService.scala | 4 ++-- .../gitbucket/core/util/StringUtil.scala | 24 +++++++++---------- 16 files changed, 51 insertions(+), 52 deletions(-) diff --git a/build.sbt b/build.sbt index ce788a5cb..e8424b069 100644 --- a/build.sbt +++ b/build.sbt @@ -37,6 +37,7 @@ libraryDependencies ++= Seq( "org.apache.tika" % "tika-core" % "1.13", //"com.typesafe.slick" %% "slick" % "3.2.0-M1", "com.github.takezoe" %% "blocking-slick" % "0.0.3-SNAPSHOT", + "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", @@ -46,7 +47,7 @@ libraryDependencies ++= Seq( "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.enragedginger" % "akka-quartz-scheduler_2.11" % "1.5.0-akka-2.4.x" exclude("c3p0","c3p0"), // TODO Scala 2.12 + "com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x" exclude("c3p0","c3p0"), "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided", "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided", "junit" % "junit" % "4.12" % "test", @@ -56,7 +57,7 @@ libraryDependencies ++= Seq( ) // 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/plugins.sbt b/project/plugins.sbt index 21a6329fe..fb3bace06 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature") -addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.1.1") +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") diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index c04fccc24..f7daddbb5 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -1,9 +1,8 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ - +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil @@ -21,7 +20,7 @@ trait AccessTokenService { def tokenToHash(token: String): String = StringUtil.sha1(token) /** - * @retuen (TokenId, Token) + * @return (TokenId, Token) */ def generateAccessToken(userName: String, note: String)(implicit s: Session): (Int, String) = { var token: String = null @@ -43,8 +42,8 @@ trait AccessTokenService { def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] = Accounts .join(AccessTokens) - .filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } - .map{ case (ac, t) => ac } + .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 5a6c7489f..941a587e1 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -3,12 +3,12 @@ package gitbucket.core.service import org.slf4j.LoggerFactory import gitbucket.core.model.{GroupMember, Account} import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +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 -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 a7e61cd97..09ebb0b22 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -1,10 +1,10 @@ package gitbucket.core.service import gitbucket.core.model.Activity -import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait ActivityService { diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 07fe47f7d..9c01e2a77 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -1,8 +1,8 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType import gitbucket.core.model.{CommitState, CommitStatus, Account} @@ -50,4 +50,4 @@ trait CommitStatusService { protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) = CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha)).sortBy(_.updatedDate desc) -} \ No newline at end of file +} diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index a7a8fc47e..b9aaea073 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -2,8 +2,8 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait CommitsService { diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index e43f399cd..69d6f2374 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -5,8 +5,8 @@ import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.model._ import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index 716ae3203..8accddc98 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -2,8 +2,8 @@ package gitbucket.core.service import gitbucket.core.model.Label import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait LabelsService { diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index b94ca392c..879638a6e 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -2,8 +2,8 @@ package gitbucket.core.service import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait MilestonesService { diff --git a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala index 9cd63b696..3552762f1 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -1,10 +1,10 @@ package gitbucket.core.service import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitState} -import gitbucket.core.model.Profile._ import gitbucket.core.plugin.ReceiveHook -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index fbdee92b6..e5b3e23f3 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -1,11 +1,10 @@ package gitbucket.core.service -import gitbucket.core.model.{Account, Issue, PullRequest, WebHook, CommitStatus, CommitState} -import gitbucket.core.model.Profile._ +import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState} import gitbucket.core.util.JGitUtil -import profile._ -import profile.blockingApi._ - +import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ trait PullRequestService { self: IssuesService => import PullRequestService._ diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 6ecc93a09..1b1fcada8 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -4,8 +4,8 @@ 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 profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType trait RepositoryService { self: AccountService => diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index a0e142c42..82a8e93c0 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -2,8 +2,8 @@ package gitbucket.core.service import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +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 9d6477902..346c8ccd4 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -5,9 +5,9 @@ import fr.brouillard.oss.security.xhub.XHub.{XHubDigest, XHubConverter} import gitbucket.core.api._ import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent, CommitComment} import gitbucket.core.model.Profile._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ import org.apache.http.client.utils.URLEncodedUtils -import profile._ -import profile.blockingApi._ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.RepositoryName import gitbucket.core.service.RepositoryService.RepositoryInfo diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index 9710b5039..768c407ee 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -101,18 +101,18 @@ object StringUtil { .findAllIn(message).matchData.map(_.group(1)).toSeq.distinct - /** - * Encode search string for LIKE condition. - * This method has been copied from Slick's SqlUtilsComponent. - */ - def likeEncode(s: String) = { - val b = new StringBuilder - for(c <- s) c match { - case '%' | '_' | '^' => b append '^' append c - case _ => b append c - } - b.toString - } +// /** +// * Encode search string for LIKE condition. +// * This method has been copied from Slick's SqlUtilsComponent. +// */ +// def likeEncode(s: String) = { +// val b = new StringBuilder +// for(c <- s) c match { +// case '%' | '_' | '^' => b append '^' append c +// case _ => b append c +// } +// b.toString +// } } From e93e32b34966d039206bd3fb9103ed7bf09d7d23 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 28 Dec 2016 01:23:02 +0900 Subject: [PATCH 18/27] (refs #1346)Update libraries --- build.sbt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index e8424b069..4accb94d6 100644 --- a/build.sbt +++ b/build.sbt @@ -26,7 +26,7 @@ libraryDependencies ++= Seq( "org.scalatra" %% "scalatra" % ScalatraVersion, "org.scalatra" %% "scalatra-json" % ScalatraVersion, "org.json4s" %% "json4s-jackson" % "3.5.0", - "io.github.gitbucket" %% "scalatra-forms" % "1.1.0-SNAPSHOT", + "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", @@ -35,8 +35,7 @@ libraryDependencies ++= Seq( "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.github.takezoe" %% "blocking-slick" % "0.0.3-SNAPSHOT", + "com.github.takezoe" %% "blocking-slick" % "0.0.3", "joda-time" % "joda-time" % "2.9.6", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", From 1e3bd9ebc044147f925b0e3a4ad133223285b83c Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 28 Dec 2016 01:41:36 +0900 Subject: [PATCH 19/27] (refs #1346)Fix warnings --- .../scala/gitbucket/core/service/WebHookService.scala | 11 +++++------ .../scala/gitbucket/core/util/DatabaseConfig.scala | 2 +- src/main/scala/gitbucket/core/util/Notifier.scala | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 346c8ccd4..d8ca928a1 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -18,6 +18,7 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib.ObjectId 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 @@ -130,7 +131,7 @@ trait WebHookService { httpPost.releaseConnection() logger.debug(s"end web hook invocation for ${webHook}") res - }catch{ + } catch { case e:Throwable => { if(!reqPromise.isCompleted){ reqPromise.failure(e) @@ -139,11 +140,9 @@ trait WebHookService { } } } - 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/util/DatabaseConfig.scala b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala index 681cebc50..644c3f25a 100644 --- a/src/main/scala/gitbucket/core/util/DatabaseConfig.scala +++ b/src/main/scala/gitbucket/core/util/DatabaseConfig.scala @@ -91,7 +91,7 @@ object DatabaseType { val liquiDriver = new PostgresDatabase() } - object BlockingPostgresDriver extends slick.driver.PostgresDriver with BlockingJdbcProfile { + 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 diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 41d5b6bc1..398002950 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -7,6 +7,7 @@ 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 @@ -93,11 +94,9 @@ class Mailer(private val smtp: Smtp) extends Notifier { } "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) } } From 892f2d5f415d177dc4d99392e4c0907ffaa4f24b Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 28 Dec 2016 01:45:23 +0900 Subject: [PATCH 20/27] (refs #1346)Fix tests --- .../core/service/AccessTokenServiceSpec.scala | 4 ++-- .../core/service/CommitStatusServiceSpec.scala | 4 ++-- .../scala/gitbucket/core/service/ServiceSpecBase.scala | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala index 7202b7cb3..45ab3ffbe 100644 --- a/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/AccessTokenServiceSpec.scala @@ -3,8 +3,8 @@ package gitbucket.core.service import gitbucket.core.model._ import org.scalatest.FunSuite import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase { diff --git a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala index 54cc67023..56a29fb0e 100644 --- a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala @@ -2,8 +2,8 @@ package gitbucket.core.service import gitbucket.core.model._ import gitbucket.core.model.Profile._ -import profile._ -import profile.blockingApi._ +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/ServiceSpecBase.scala b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala index d564a991a..8c5bd3f19 100644 --- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala +++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala @@ -1,15 +1,15 @@ package gitbucket.core.service import gitbucket.core.GitBucketCoreModule -import gitbucket.core.util.{ControlUtil, DatabaseConfig, FileUtil} +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._ -import profile.blockingApi._ +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 From 202f56b6a0ded1fce4b72f197325a5806ac6d55d Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 6 Feb 2017 14:25:25 +0900 Subject: [PATCH 21/27] Bump blocking-slick --- build.sbt | 2 +- .../gitbucket/core/service/AccessTokenService.scala | 1 - .../gitbucket/core/service/AccountService.scala | 1 - .../gitbucket/core/service/ActivityService.scala | 1 - .../gitbucket/core/service/CommitStatusService.scala | 1 - .../gitbucket/core/service/CommitsService.scala | 1 - .../core/service/HandleCommentService.scala | 2 +- .../scala/gitbucket/core/service/LabelsService.scala | 1 - .../gitbucket/core/service/MilestonesService.scala | 1 - .../core/service/ProtectedBranchService.scala | 1 - .../gitbucket/core/service/PullRequestService.scala | 1 - .../core/service/RepositoryCreationService.scala | 3 +-- .../core/service/RepositorySearchService.scala | 3 +-- .../gitbucket/core/service/RepositoryService.scala | 1 - .../scala/gitbucket/core/service/SshKeyService.scala | 1 - .../gitbucket/core/service/WebHookService.scala | 1 - .../core/servlet/GitAuthenticationFilter.scala | 2 +- .../core/servlet/GitRepositoryServlet.scala | 2 +- .../gitbucket/core/servlet/InitializeListener.scala | 2 +- .../gitbucket/core/servlet/TransactionFilter.scala | 2 +- src/main/scala/gitbucket/core/ssh/GitCommand.scala | 12 ++++++------ .../gitbucket/core/ssh/PublicKeyAuthenticator.scala | 2 +- src/main/scala/gitbucket/core/util/Notifier.scala | 2 +- 23 files changed, 16 insertions(+), 30 deletions(-) diff --git a/build.sbt b/build.sbt index 21be63d88..bf10d4dc9 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "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" % "0.0.3", + "com.github.takezoe" %% "blocking-slick-32" % "0.0.6-SNAPSHOT", "joda-time" % "joda-time" % "2.9.6", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index f7daddbb5..d9a9411d6 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -1,7 +1,6 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.{Account, AccessToken} import gitbucket.core.util.StringUtil diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index eb136457c..6a4b599ee 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -3,7 +3,6 @@ package gitbucket.core.service import org.slf4j.LoggerFactory import gitbucket.core.model.{GroupMember, Account} import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType import gitbucket.core.util.{StringUtil, LDAPUtil} diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 09ebb0b22..433909d77 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -3,7 +3,6 @@ package gitbucket.core.service import gitbucket.core.model.Activity import gitbucket.core.util.JGitUtil import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ trait ActivityService { diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 9c01e2a77..ca24ff947 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -1,7 +1,6 @@ package gitbucket.core.service import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType import gitbucket.core.model.{CommitState, CommitStatus, Account} diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 747f3d204..3e28f4567 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -2,7 +2,6 @@ package gitbucket.core.service import gitbucket.core.model.CommitComment import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType diff --git a/src/main/scala/gitbucket/core/service/HandleCommentService.scala b/src/main/scala/gitbucket/core/service/HandleCommentService.scala index 8c9604268..fe94605ee 100644 --- a/src/main/scala/gitbucket/core/service/HandleCommentService.scala +++ b/src/main/scala/gitbucket/core/service/HandleCommentService.scala @@ -3,10 +3,10 @@ package gitbucket.core.service 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.blockingApi._ trait HandleCommentService { self: RepositoryService with IssuesService with ActivityService diff --git a/src/main/scala/gitbucket/core/service/LabelsService.scala b/src/main/scala/gitbucket/core/service/LabelsService.scala index 8accddc98..e95fa062c 100644 --- a/src/main/scala/gitbucket/core/service/LabelsService.scala +++ b/src/main/scala/gitbucket/core/service/LabelsService.scala @@ -2,7 +2,6 @@ package gitbucket.core.service import gitbucket.core.model.Label import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ trait LabelsService { diff --git a/src/main/scala/gitbucket/core/service/MilestonesService.scala b/src/main/scala/gitbucket/core/service/MilestonesService.scala index 879638a6e..1e9585687 100644 --- a/src/main/scala/gitbucket/core/service/MilestonesService.scala +++ b/src/main/scala/gitbucket/core/service/MilestonesService.scala @@ -2,7 +2,6 @@ package gitbucket.core.service import gitbucket.core.model.Milestone import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType diff --git a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala index 6b9e98d0a..577b84384 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -3,7 +3,6 @@ package gitbucket.core.service import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitState} import gitbucket.core.plugin.ReceiveHook import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index d9acb3cf5..f8aecff6a 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -2,7 +2,6 @@ package gitbucket.core.service import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState} import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import difflib.{Delta, DiffUtils} import gitbucket.core.model.{Session => _, _} diff --git a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala index 85962f333..c04085110 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 gitbucket.core.model.Account import org.eclipse.jgit.api.Git import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib.{FileMode, Constants} -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 09bd2764c..a104414cb 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.revwalk.RevWalk 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.blockingApi._ +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 79f08523c..85d683203 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -5,7 +5,6 @@ import gitbucket.core.util._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.model.{Account, Collaborator, Repository, RepositoryOptions, 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 import gitbucket.core.util.JGitUtil.FileInfo diff --git a/src/main/scala/gitbucket/core/service/SshKeyService.scala b/src/main/scala/gitbucket/core/service/SshKeyService.scala index 82a8e93c0..477413fc9 100644 --- a/src/main/scala/gitbucket/core/service/SshKeyService.scala +++ b/src/main/scala/gitbucket/core/service/SshKeyService.scala @@ -2,7 +2,6 @@ package gitbucket.core.service import gitbucket.core.model.SshKey import gitbucket.core.model.Profile._ -import gitbucket.core.model.Profile.profile._ 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 b83257a33..2f060de6f 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -5,7 +5,6 @@ import fr.brouillard.oss.security.xhub.XHub.{XHubConverter, XHubDigest} 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._ import gitbucket.core.model.Profile.profile.blockingApi._ import org.apache.http.client.utils.URLEncodedUtils import gitbucket.core.util.JGitUtil.CommitInfo diff --git a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala index d474488a5..11367877d 100644 --- a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala @@ -6,7 +6,7 @@ import gitbucket.core.plugin.{GitRepositoryFilter, GitRepositoryRouting, PluginR 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._ +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 8adb1cfbb..f2632a68f 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -5,7 +5,7 @@ import java.util.Date import gitbucket.core.api import gitbucket.core.model.WebHook -import gitbucket.core.model.Profile.profile._ +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 e29bea9e8..5307ed48e 100644 --- a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala +++ b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala @@ -10,7 +10,7 @@ import gitbucket.core.service.{ActivityService, SystemSettingsService} import gitbucket.core.util.DatabaseConfig import gitbucket.core.util.Directory._ import gitbucket.core.util.JDBCUtil._ -import gitbucket.core.model.Profile.profile._ +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 f77d3eea6..0ab5c063c 100644 --- a/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala @@ -8,7 +8,7 @@ import org.scalatra.ScalatraBase import org.slf4j.LoggerFactory import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session} import gitbucket.core.util.Keys -import gitbucket.core.model.Profile.profile._ +import gitbucket.core.model.Profile.profile.blockingApi._ /** * Controls the transaction with the open session in view pattern. diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index a28a150b1..9620dbd01 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -1,15 +1,15 @@ package gitbucket.core.ssh -import gitbucket.core.model.Session -import gitbucket.core.model.Profile.profile._ +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 6b9a60e14..fa8d1ce8b 100644 --- a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala +++ b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala @@ -4,7 +4,7 @@ import java.security.PublicKey import gitbucket.core.service.SshKeyService import gitbucket.core.servlet.Database -import gitbucket.core.model.Profile.profile._ +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/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 86a2c887a..a7a21e1be 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -1,7 +1,7 @@ package gitbucket.core.util import gitbucket.core.model.{Session, Issue, Account} -import gitbucket.core.model.Profile.profile._ +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 From afad27ee01f4d28f9ef2412a01995ca4651e7795 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 8 Feb 2017 02:12:26 +0900 Subject: [PATCH 22/27] Bump to blocking-slick 0.0.6 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index bf10d4dc9..b123f264c 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "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.6-SNAPSHOT", + "com.github.takezoe" %% "blocking-slick-32" % "0.0.6", "joda-time" % "joda-time" % "2.9.6", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", From e8888ac1913a365ef0cb724af73241ee06996451 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 8 Feb 2017 14:23:19 +0900 Subject: [PATCH 23/27] Fix import statements --- src/main/scala/gitbucket/core/service/IssuesService.scala | 2 +- .../scala/gitbucket/core/service/PullRequestService.scala | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 5543e9bb9..ef3418556 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -3,7 +3,7 @@ package gitbucket.core.service import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ -import gitbucket.core.model._ +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._ diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index f8aecff6a..a512d2cbf 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -1,11 +1,9 @@ package gitbucket.core.service -import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState} +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.model.{Session => _, _} -import gitbucket.core.model.Profile._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ From 7d9f30849289c45a35595fa264907986634c2c77 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 8 Feb 2017 14:51:20 +0900 Subject: [PATCH 24/27] Cleaned up code around webhook --- .../scala/gitbucket/core/model/WebHook.scala | 31 ++++++++++++++++--- .../core/service/IssuesService.scala | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/scala/gitbucket/core/model/WebHook.scala b/src/main/scala/gitbucket/core/model/WebHook.scala index 6f89b0ec8..48de21bbe 100644 --- a/src/main/scala/gitbucket/core/model/WebHook.scala +++ b/src/main/scala/gitbucket/core/model/WebHook.scala @@ -17,11 +17,10 @@ trait WebHookComponent extends TemplateComponent { self: Profile => } } -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 @@ case class WebHook( ) 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 @@ object WebHook { 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/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index ef3418556..0d729edf3 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -455,6 +455,7 @@ object IssuesService { 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 ++ From 7a6a2471b1daf9972930d5607d7ea094ba1e0bd4 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 10 Feb 2017 01:55:34 +0900 Subject: [PATCH 25/27] Fix issues sorting --- src/main/scala/gitbucket/core/service/IssuesService.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 0d729edf3..d9c589810 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -132,6 +132,7 @@ trait IssuesService { .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)) } From 79d41ba57b0969460fc643c02c1d24895823b827 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 12 Feb 2017 11:37:04 +0900 Subject: [PATCH 26/27] Bump blocking-slick --- build.sbt | 2 +- src/main/scala/gitbucket/core/servlet/TransactionFilter.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index b123f264c..7ea6e5dbc 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "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.6", + "com.github.takezoe" %% "blocking-slick-32" % "0.0.7-SNAPSHOT", "joda-time" % "joda-time" % "2.9.6", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.4.192", diff --git a/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala b/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala index 0ab5c063c..d6677d195 100644 --- a/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/TransactionFilter.scala @@ -66,7 +66,7 @@ object Database { } private val db: SlickDatabase = { - SlickDatabase.forDataSource(dataSource) + SlickDatabase.forDataSource(dataSource, Some(dataSource.getMaximumPoolSize)) } def apply(): SlickDatabase = db From ea4414f1a53c66148ab60118691f3c9e103680d3 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 12 Feb 2017 23:12:27 +0900 Subject: [PATCH 27/27] Bump blocking-slick to 0.0.7 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 7ea6e5dbc..dadafbdb5 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "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-SNAPSHOT", + "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",