Experiment of blocking-slick

This commit is contained in:
Naoki Takezoe
2016-08-12 15:31:38 +09:00
parent 56e7168461
commit 825b2f9ebf
43 changed files with 328 additions and 296 deletions

View File

@@ -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",

View File

@@ -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") {

View File

@@ -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]

View File

@@ -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]

View File

@@ -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)
}
}

View File

@@ -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]

View File

@@ -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)){

View File

@@ -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.<<?[String].map(CommitState(_)))
// implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<))
// implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.<<?[String].map(CommitState(_)))
}

View File

@@ -1,7 +1,7 @@
package gitbucket.core.model
trait GroupMemberComponent { self: Profile =>
import profile.simple._
import profile.api._
lazy val GroupMembers = TableQuery[GroupMembers]

View File

@@ -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]

View File

@@ -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]

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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
}
/**

View File

@@ -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]

View File

@@ -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)
}
}

View File

@@ -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]

View File

@@ -1,7 +1,7 @@
package gitbucket.core.model
trait SshKeyComponent { self: Profile =>
import profile.simple._
import profile.api._
lazy val SshKeys = TableQuery[SshKeys]

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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] = {

View File

@@ -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),

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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

View File

@@ -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){
def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] = {
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
}
// 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) =>

View File

@@ -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 =
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
}
}

View File

@@ -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 =>

View File

@@ -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))
}
}

View File

@@ -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) &&

View File

@@ -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 =>

View File

@@ -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._

View File

@@ -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.

View File

@@ -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

View File

@@ -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 = {

View File

@@ -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}

View File

@@ -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")

View File

@@ -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}

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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