mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 07:25:50 +01:00
Experiment of blocking-slick
This commit is contained in:
@@ -35,7 +35,8 @@ libraryDependencies ++= Seq(
|
|||||||
"org.apache.httpcomponents" % "httpclient" % "4.5.1",
|
"org.apache.httpcomponents" % "httpclient" % "4.5.1",
|
||||||
"org.apache.sshd" % "apache-sshd" % "1.2.0",
|
"org.apache.sshd" % "apache-sshd" % "1.2.0",
|
||||||
"org.apache.tika" % "tika-core" % "1.13",
|
"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.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
"com.h2database" % "h2" % "1.4.192",
|
"com.h2database" % "h2" % "1.4.192",
|
||||||
"mysql" % "mysql-connector-java" % "5.1.39",
|
"mysql" % "mysql-connector-java" % "5.1.39",
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package gitbucket.core.model
|
|||||||
|
|
||||||
|
|
||||||
trait AccessTokenComponent { self: Profile =>
|
trait AccessTokenComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val AccessTokens = TableQuery[AccessTokens]
|
lazy val AccessTokens = TableQuery[AccessTokens]
|
||||||
|
|
||||||
class AccessTokens(tag: Tag) extends Table[AccessToken](tag, "ACCESS_TOKEN") {
|
class AccessTokens(tag: Tag) extends Table[AccessToken](tag, "ACCESS_TOKEN") {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait AccountComponent { self: Profile =>
|
trait AccountComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val Accounts = TableQuery[Accounts]
|
lazy val Accounts = TableQuery[Accounts]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val Activities = TableQuery[Activities]
|
lazy val Activities = TableQuery[Activities]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
protected[model] trait TemplateComponent { self: Profile =>
|
protected[model] trait TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
trait BasicTemplate { self: Table[_] =>
|
trait BasicTemplate { self: Table[_] =>
|
||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
@@ -10,7 +10,7 @@ protected[model] trait TemplateComponent { self: Profile =>
|
|||||||
def byRepository(owner: String, repository: String) =
|
def byRepository(owner: String, repository: String) =
|
||||||
(userName === owner.bind) && (repositoryName === repository.bind)
|
(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)
|
(this.userName === userName) && (this.repositoryName === repositoryName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ protected[model] trait TemplateComponent { self: Profile =>
|
|||||||
def byIssue(owner: String, repository: String, issueId: Int) =
|
def byIssue(owner: String, repository: String, issueId: Int) =
|
||||||
byRepository(owner, repository) && (this.issueId === issueId.bind)
|
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)
|
byRepository(userName, repositoryName) && (this.issueId === issueId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ protected[model] trait TemplateComponent { self: Profile =>
|
|||||||
def byLabel(owner: String, repository: String, labelId: Int) =
|
def byLabel(owner: String, repository: String, labelId: Int) =
|
||||||
byRepository(owner, repository) && (this.labelId === labelId.bind)
|
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)
|
byRepository(userName, repositoryName) && (this.labelId === labelId)
|
||||||
|
|
||||||
def byLabel(owner: String, repository: String, labelName: String) =
|
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) =
|
def byMilestone(owner: String, repository: String, milestoneId: Int) =
|
||||||
byRepository(owner, repository) && (this.milestoneId === milestoneId.bind)
|
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)
|
byRepository(userName, repositoryName) && (this.milestoneId === milestoneId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,13 +54,13 @@ protected[model] trait TemplateComponent { self: Profile =>
|
|||||||
def byCommit(owner: String, repository: String, commitId: String) =
|
def byCommit(owner: String, repository: String, commitId: String) =
|
||||||
byRepository(owner, repository) && (this.commitId === commitId)
|
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)
|
byRepository(userName, repositoryName) && (this.commitId === commitId)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait BranchTemplate extends BasicTemplate{ self: Table[_] =>
|
trait BranchTemplate extends BasicTemplate{ self: Table[_] =>
|
||||||
val branch = column[String]("BRANCH")
|
val branch = column[String]("BRANCH")
|
||||||
def byBranch(owner: String, repository: String, branchName: String) = byRepository(owner, repository) && (branch === branchName.bind)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val Collaborators = TableQuery[Collaborators]
|
lazy val Collaborators = TableQuery[Collaborators]
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trait Comment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){
|
lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){
|
||||||
@@ -39,7 +39,7 @@ case class IssueComment (
|
|||||||
) extends Comment
|
) extends Comment
|
||||||
|
|
||||||
trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val CommitComments = new TableQuery(tag => new CommitComments(tag)){
|
lazy val CommitComments = new TableQuery(tag => new CommitComments(tag)){
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
import scala.slick.lifted.MappedTo
|
//import scala.slick.lifted.MappedTo
|
||||||
import scala.slick.jdbc._
|
//import scala.slick.jdbc._
|
||||||
|
|
||||||
trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name , i => CommitState(i))
|
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 getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<))
|
||||||
implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.<<?[String].map(CommitState(_)))
|
// implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.<<?[String].map(CommitState(_)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait GroupMemberComponent { self: Profile =>
|
trait GroupMemberComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val GroupMembers = TableQuery[GroupMembers]
|
lazy val GroupMembers = TableQuery[GroupMembers]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait IssueComponent extends TemplateComponent { self: Profile =>
|
trait IssueComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val IssueId = TableQuery[IssueId]
|
lazy val IssueId = TableQuery[IssueId]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val IssueLabels = TableQuery[IssueLabels]
|
lazy val IssueLabels = TableQuery[IssueLabels]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait LabelComponent extends TemplateComponent { self: Profile =>
|
trait LabelComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val Labels = TableQuery[Labels]
|
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 * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val Milestones = TableQuery[Milestones]
|
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 * = (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(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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
import gitbucket.core.util.DatabaseConfig
|
import gitbucket.core.util.DatabaseConfig
|
||||||
|
import com.github.takezoe.slick.blocking.SlickBlockingAPI
|
||||||
|
|
||||||
trait Profile {
|
trait Profile {
|
||||||
val profile: slick.driver.JdbcProfile
|
val profile: SlickBlockingAPI
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java.util.Date Mapped Column Types
|
* java.util.Date Mapped Column Types
|
||||||
@@ -17,8 +18,8 @@ trait Profile {
|
|||||||
/**
|
/**
|
||||||
* Extends Column to add conditional condition
|
* Extends Column to add conditional condition
|
||||||
*/
|
*/
|
||||||
implicit class RichColumn(c1: Column[Boolean]){
|
implicit class RichColumn(c1: Rep[Boolean]){
|
||||||
def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1
|
def &&(c2: => Rep[Boolean], guard: => Boolean): Rep[Boolean] = if(guard) c1 && c2 else c1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
import scala.slick.lifted.MappedTo
|
//import scala.slick.lifted.MappedTo
|
||||||
import scala.slick.jdbc._
|
//import scala.slick.jdbc._
|
||||||
|
|
||||||
trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
||||||
@@ -12,7 +12,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
||||||
def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply)
|
def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply)
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, branch: String) = byBranch(userName, repositoryName, branch)
|
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]
|
lazy val ProtectedBranchContexts = TableQuery[ProtectedBranchContexts]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val PullRequests = TableQuery[PullRequests]
|
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 * = (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: 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
lazy val Repositories = TableQuery[Repositories]
|
lazy val Repositories = TableQuery[Repositories]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait SshKeyComponent { self: Profile =>
|
trait SshKeyComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
lazy val SshKeys = TableQuery[SshKeys]
|
lazy val SshKeys = TableQuery[SshKeys]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait WebHookComponent extends TemplateComponent { self: Profile =>
|
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))
|
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 {
|
class WebHooks(tag: Tag) extends Table[WebHook](tag, "WEB_HOOK") with BasicTemplate {
|
||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val token = column[Option[String]]("TOKEN", O.Nullable)
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE", O.NotNull)
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
def * = (userName, repositoryName, url, ctype, token) <> ((WebHook.apply _).tupled, WebHook.unapply)
|
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)
|
def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait WebHookEventComponent extends TemplateComponent { self: Profile =>
|
trait WebHookEventComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
import gitbucket.core.model.Profile.WebHooks
|
import gitbucket.core.model.Profile.WebHooks
|
||||||
|
|
||||||
lazy val WebHookEvents = TableQuery[WebHookEvents]
|
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 * = (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: 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)
|
byRepository(userName, repositoryName) && (this.url === url)
|
||||||
def byWebHook(webhook: WebHooks) =
|
def byWebHook(webhook: WebHooks) =
|
||||||
byRepository(webhook.userName, webhook.repositoryName) && (this.url === webhook.url)
|
byRepository(webhook.userName, webhook.repositoryName) && (this.url === webhook.url)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gitbucket.core.plugin
|
|||||||
|
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand}
|
import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand}
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
trait ReceiveHook {
|
trait ReceiveHook {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package gitbucket.core.service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
import gitbucket.core.model.{Account, AccessToken}
|
import gitbucket.core.model.{Account, AccessToken}
|
||||||
import gitbucket.core.util.StringUtil
|
import gitbucket.core.util.StringUtil
|
||||||
@@ -28,7 +29,7 @@ trait AccessTokenService {
|
|||||||
do{
|
do{
|
||||||
token = makeAccessTokenString
|
token = makeAccessTokenString
|
||||||
hash = tokenToHash(token)
|
hash = tokenToHash(token)
|
||||||
}while(AccessTokens.filter(_.tokenHash === hash.bind).exists.run)
|
} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run)
|
||||||
val newToken = AccessToken(
|
val newToken = AccessToken(
|
||||||
userName = userName,
|
userName = userName,
|
||||||
note = note,
|
note = note,
|
||||||
@@ -39,7 +40,7 @@ trait AccessTokenService {
|
|||||||
|
|
||||||
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
||||||
Accounts
|
Accounts
|
||||||
.innerJoin(AccessTokens)
|
.join(AccessTokens)
|
||||||
.filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) }
|
.filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) }
|
||||||
.map{ case (ac, t) => ac }
|
.map{ case (ac, t) => ac }
|
||||||
.firstOption
|
.firstOption
|
||||||
@@ -48,7 +49,7 @@ trait AccessTokenService {
|
|||||||
AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list
|
AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list
|
||||||
|
|
||||||
def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit =
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import gitbucket.core.model.{GroupMember, Account}
|
|||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.util.{StringUtil, LDAPUtil}
|
import gitbucket.core.util.{StringUtil, LDAPUtil}
|
||||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
import StringUtil._
|
import StringUtil._
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
// TODO Why is direct import required?
|
// 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])
|
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Accounts insert Account(
|
Accounts unsafeInsert Account(
|
||||||
userName = userName,
|
userName = userName,
|
||||||
password = password,
|
password = password,
|
||||||
fullName = fullName,
|
fullName = fullName,
|
||||||
@@ -123,7 +124,7 @@ trait AccountService {
|
|||||||
Accounts
|
Accounts
|
||||||
.filter { a => a.userName === account.userName.bind }
|
.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) }
|
.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.password,
|
||||||
account.fullName,
|
account.fullName,
|
||||||
account.mailAddress,
|
account.mailAddress,
|
||||||
@@ -135,13 +136,13 @@ trait AccountService {
|
|||||||
account.isRemoved)
|
account.isRemoved)
|
||||||
|
|
||||||
def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit =
|
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 =
|
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 =
|
def createGroup(groupName: String, url: Option[String])(implicit s: Session): Unit =
|
||||||
Accounts insert Account(
|
Accounts unsafeInsert Account(
|
||||||
userName = groupName,
|
userName = groupName,
|
||||||
password = "",
|
password = "",
|
||||||
fullName = groupName,
|
fullName = groupName,
|
||||||
@@ -156,12 +157,12 @@ trait AccountService {
|
|||||||
isRemoved = false)
|
isRemoved = false)
|
||||||
|
|
||||||
def updateGroup(groupName: String, url: Option[String], removed: Boolean)(implicit s: Session): Unit =
|
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 = {
|
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
||||||
GroupMembers.filter(_.groupName === groupName.bind).delete
|
GroupMembers.filter(_.groupName === groupName.bind).delete
|
||||||
members.foreach { case (userName, isManager) =>
|
members.foreach { case (userName, isManager) =>
|
||||||
GroupMembers insert GroupMember (groupName, userName, isManager)
|
GroupMembers unsafeInsert GroupMember (groupName, userName, isManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,9 +180,9 @@ trait AccountService {
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
def removeUserRelatedData(userName: String)(implicit s: Session): Unit = {
|
def removeUserRelatedData(userName: String)(implicit s: Session): Unit = {
|
||||||
GroupMembers.filter(_.userName === userName.bind).delete
|
GroupMembers.filter(_.userName === userName.bind).unsafeDelete
|
||||||
Collaborators.filter(_.collaboratorName === userName.bind).delete
|
Collaborators.filter(_.collaboratorName === userName.bind).unsafeDelete
|
||||||
Repositories.filter(_.userName === userName.bind).delete
|
Repositories.filter(_.userName === userName.bind).unsafeDelete
|
||||||
}
|
}
|
||||||
|
|
||||||
def getGroupNames(userName: String)(implicit s: Session): List[String] = {
|
def getGroupNames(userName: String)(implicit s: Session): List[String] = {
|
||||||
|
|||||||
@@ -3,19 +3,20 @@ package gitbucket.core.service
|
|||||||
import gitbucket.core.model.Activity
|
import gitbucket.core.model.Activity
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.util.JGitUtil
|
import gitbucket.core.util.JGitUtil
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
trait ActivityService {
|
trait ActivityService {
|
||||||
|
|
||||||
def deleteOldActivities(limit: Int)(implicit s: Session): Int = {
|
def deleteOldActivities(limit: Int)(implicit s: Session): Int = {
|
||||||
Activities.map(_.activityId).sortBy(_ desc).drop(limit).firstOption.map { id =>
|
Activities.map(_.activityId).sortBy(_ desc).drop(limit).firstOption.map { id =>
|
||||||
Activities.filter(_.activityId <= id.bind).delete
|
Activities.filter(_.activityId <= id.bind).unsafeDelete
|
||||||
} getOrElse 0
|
} getOrElse 0
|
||||||
}
|
}
|
||||||
|
|
||||||
def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] =
|
def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] =
|
||||||
Activities
|
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) =>
|
.filter { case (t1, t2) =>
|
||||||
if(isPublic){
|
if(isPublic){
|
||||||
(t1.activityUserName === activityUserName.bind) && (t2.isPrivate === false.bind)
|
(t1.activityUserName === activityUserName.bind) && (t2.isPrivate === false.bind)
|
||||||
@@ -30,7 +31,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def getRecentActivities()(implicit s: Session): List[Activity] =
|
def getRecentActivities()(implicit s: Session): List[Activity] =
|
||||||
Activities
|
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 }
|
.filter { case (t1, t2) => t2.isPrivate === false.bind }
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
.map { case (t1, t2) => t1 }
|
.map { case (t1, t2) => t1 }
|
||||||
@@ -39,7 +40,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def getRecentActivitiesByOwners(owners : Set[String])(implicit s: Session): List[Activity] =
|
def getRecentActivitiesByOwners(owners : Set[String])(implicit s: Session): List[Activity] =
|
||||||
Activities
|
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) }
|
.filter { case (t1, t2) => (t2.isPrivate === false.bind) || (t2.userName inSetBind owners) }
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
.map { case (t1, t2) => t1 }
|
.map { case (t1, t2) => t1 }
|
||||||
@@ -48,7 +49,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String)
|
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"create_repository",
|
"create_repository",
|
||||||
s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
@@ -56,7 +57,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"open_issue",
|
"open_issue",
|
||||||
s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(title),
|
Some(title),
|
||||||
@@ -64,7 +65,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"close_issue",
|
"close_issue",
|
||||||
s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(title),
|
Some(title),
|
||||||
@@ -72,7 +73,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"close_issue",
|
"close_issue",
|
||||||
s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(title),
|
Some(title),
|
||||||
@@ -80,7 +81,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"reopen_issue",
|
"reopen_issue",
|
||||||
s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(title),
|
Some(title),
|
||||||
@@ -88,7 +89,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"comment_issue",
|
"comment_issue",
|
||||||
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(cut(comment, 200)),
|
Some(cut(comment, 200)),
|
||||||
@@ -96,7 +97,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"comment_issue",
|
"comment_issue",
|
||||||
s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(cut(comment, 200)),
|
Some(cut(comment, 200)),
|
||||||
@@ -104,7 +105,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String)
|
def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"comment_commit",
|
"comment_commit",
|
||||||
s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]",
|
s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]",
|
||||||
Some(cut(comment, 200)),
|
Some(cut(comment, 200)),
|
||||||
@@ -113,7 +114,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String)
|
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"create_wiki",
|
"create_wiki",
|
||||||
s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki",
|
s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki",
|
||||||
Some(pageName),
|
Some(pageName),
|
||||||
@@ -121,7 +122,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String)
|
def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"edit_wiki",
|
"edit_wiki",
|
||||||
s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki",
|
s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki",
|
||||||
Some(pageName + ":" + commitId),
|
Some(pageName + ":" + commitId),
|
||||||
@@ -129,7 +130,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordPushActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordPushActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"push",
|
"push",
|
||||||
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||||
Some(commits.map { commit => commit.id + ":" + commit.shortMessage }.mkString("\n")),
|
Some(commits.map { commit => commit.id + ":" + commit.shortMessage }.mkString("\n")),
|
||||||
@@ -137,7 +138,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"create_tag",
|
"create_tag",
|
||||||
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
@@ -145,7 +146,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"delete_tag",
|
"delete_tag",
|
||||||
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
@@ -153,7 +154,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"create_branch",
|
"create_branch",
|
||||||
s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
@@ -161,14 +162,14 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"delete_branch",
|
"delete_branch",
|
||||||
s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit =
|
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",
|
"fork",
|
||||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
@@ -176,7 +177,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"open_pullreq",
|
"open_pullreq",
|
||||||
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(title),
|
Some(title),
|
||||||
@@ -184,7 +185,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String)
|
def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities unsafeInsert Activity(userName, repositoryName, activityUserName,
|
||||||
"merge_pullreq",
|
"merge_pullreq",
|
||||||
s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||||
Some(message),
|
Some(message),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package gitbucket.core.service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
import gitbucket.core.model.{CommitState, CommitStatus, Account}
|
import gitbucket.core.model.{CommitState, CommitStatus, Account}
|
||||||
import gitbucket.core.util.Implicits._
|
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
|
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)] =
|
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) =
|
protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) =
|
||||||
CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha)).sortBy(_.updatedDate desc)
|
CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha)).sortBy(_.updatedDate desc)
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package gitbucket.core.service
|
|||||||
import gitbucket.core.model.CommitComment
|
import gitbucket.core.model.CommitComment
|
||||||
import gitbucket.core.util.{StringUtil, Implicits}
|
import gitbucket.core.util.{StringUtil, Implicits}
|
||||||
|
|
||||||
import scala.slick.jdbc.{StaticQuery => Q}
|
//import slick.jdbc.{StaticQuery => Q}
|
||||||
import Q.interpolation
|
//import Q.interpolation
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
import Implicits._
|
import profile.api._
|
||||||
import StringUtil._
|
//import Implicits._
|
||||||
|
//import StringUtil._
|
||||||
|
|
||||||
|
|
||||||
trait CommitsService {
|
trait CommitsService {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import gitbucket.core.model.Profile._
|
|||||||
import gitbucket.core.util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Notifier
|
import gitbucket.core.util.Notifier
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
trait HandleCommentService {
|
trait HandleCommentService {
|
||||||
self: RepositoryService with IssuesService with ActivityService
|
self: RepositoryService with IssuesService with ActivityService
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ package gitbucket.core.service
|
|||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util.StringUtil
|
import gitbucket.core.util.StringUtil
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
import gitbucket.core.util.Implicits._
|
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 scala.slick.jdbc.{StaticQuery => Q}
|
||||||
import Q.interpolation
|
|
||||||
|
|
||||||
|
|
||||||
trait IssuesService {
|
trait IssuesService extends SqlUtilsComponent {
|
||||||
self: AccountService =>
|
self: AccountService =>
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
|
|
||||||
@@ -29,8 +29,8 @@ trait IssuesService {
|
|||||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] =
|
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] =
|
||||||
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
||||||
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
||||||
.innerJoin(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
.join(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
||||||
.innerJoin(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) }
|
.join(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) }
|
||||||
.map{ case ((t1, t2), t3) => (t1, t2, t3) }
|
.map{ case ((t1, t2), t3) => (t1, t2, t3) }
|
||||||
.list
|
.list
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ trait IssuesService {
|
|||||||
|
|
||||||
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||||
IssueLabels
|
IssueLabels
|
||||||
.innerJoin(Labels).on { (t1, t2) =>
|
.join(Labels).on { (t1, t2) =>
|
||||||
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
|
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
|
||||||
}
|
}
|
||||||
.filter ( _._1.byIssue(owner, repository, issueId) )
|
.filter ( _._1.byIssue(owner, repository, issueId) )
|
||||||
@@ -77,10 +77,10 @@ trait IssuesService {
|
|||||||
filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = {
|
filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = {
|
||||||
|
|
||||||
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), false)
|
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)
|
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)
|
t2.byLabel(t3.userName, t3.repositoryName, t3.labelId)
|
||||||
}
|
}
|
||||||
.groupBy { case ((t1, t2), t3) =>
|
.groupBy { case ((t1, t2), t3) =>
|
||||||
@@ -89,64 +89,66 @@ trait IssuesService {
|
|||||||
.map { case (labelName, t) =>
|
.map { case (labelName, t) =>
|
||||||
labelName -> t.length
|
labelName -> t.length
|
||||||
}
|
}
|
||||||
.toMap
|
.list.toMap
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] ={
|
def getCommitStatues(issueList:Seq[(String, String, Int)])(implicit s: Session) :Map[(String, String, Int), CommitStatusInfo] = {
|
||||||
if(issueList.isEmpty){
|
Map.empty
|
||||||
Map.empty
|
// TODO [Slick3]
|
||||||
} else {
|
// if(issueList.isEmpty){
|
||||||
import scala.slick.jdbc._
|
// Map.empty
|
||||||
val issueIdQuery = issueList.map(i => "(PR.USER_NAME=? AND PR.REPOSITORY_NAME=? AND PR.ISSUE_ID=?)").mkString(" OR ")
|
// } else {
|
||||||
implicit val qset = SetParameter[Seq[(String, String, Int)]] {
|
// import scala.slick.jdbc._
|
||||||
case (seq, pp) =>
|
// val issueIdQuery = issueList.map(i => "(PR.USER_NAME=? AND PR.REPOSITORY_NAME=? AND PR.ISSUE_ID=?)").mkString(" OR ")
|
||||||
for (a <- seq) {
|
// implicit val qset = SetParameter[Seq[(String, String, Int)]] {
|
||||||
pp.setString(a._1)
|
// case (seq, pp) =>
|
||||||
pp.setString(a._2)
|
// for (a <- seq) {
|
||||||
pp.setInt(a._3)
|
// 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
|
// import gitbucket.core.model.Profile.commitStateColumnType
|
||||||
SUMM.USER_NAME,
|
// val query = Q.query[Seq[(String, String, Int)], (String, String, Int, Int, Int, Option[String], Option[CommitState], Option[String], Option[String])](s"""
|
||||||
SUMM.REPOSITORY_NAME,
|
// SELECT
|
||||||
SUMM.ISSUE_ID,
|
// SUMM.USER_NAME,
|
||||||
CS_ALL,
|
// SUMM.REPOSITORY_NAME,
|
||||||
CS_SUCCESS,
|
// SUMM.ISSUE_ID,
|
||||||
CSD.CONTEXT,
|
// CS_ALL,
|
||||||
CSD.STATE,
|
// CS_SUCCESS,
|
||||||
CSD.TARGET_URL,
|
// CSD.CONTEXT,
|
||||||
CSD.DESCRIPTION
|
// CSD.STATE,
|
||||||
FROM (
|
// CSD.TARGET_URL,
|
||||||
SELECT
|
// CSD.DESCRIPTION
|
||||||
PR.USER_NAME,
|
// FROM (
|
||||||
PR.REPOSITORY_NAME,
|
// SELECT
|
||||||
PR.ISSUE_ID,
|
// PR.USER_NAME,
|
||||||
COUNT(CS.STATE) AS CS_ALL,
|
// PR.REPOSITORY_NAME,
|
||||||
CSS.CS_SUCCESS AS CS_SUCCESS,
|
// PR.ISSUE_ID,
|
||||||
PR.COMMIT_ID_TO AS COMMIT_ID
|
// COUNT(CS.STATE) AS CS_ALL,
|
||||||
FROM PULL_REQUEST PR
|
// CSS.CS_SUCCESS AS CS_SUCCESS,
|
||||||
JOIN COMMIT_STATUS CS
|
// PR.COMMIT_ID_TO AS COMMIT_ID
|
||||||
ON PR.USER_NAME = CS.USER_NAME AND PR.REPOSITORY_NAME = CS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CS.COMMIT_ID
|
// FROM PULL_REQUEST PR
|
||||||
JOIN (
|
// JOIN COMMIT_STATUS CS
|
||||||
SELECT
|
// ON PR.USER_NAME = CS.USER_NAME AND PR.REPOSITORY_NAME = CS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CS.COMMIT_ID
|
||||||
COUNT(*) AS CS_SUCCESS,
|
// JOIN (
|
||||||
USER_NAME,
|
// SELECT
|
||||||
REPOSITORY_NAME,
|
// COUNT(*) AS CS_SUCCESS,
|
||||||
COMMIT_ID
|
// USER_NAME,
|
||||||
FROM COMMIT_STATUS WHERE STATE = 'success' GROUP BY USER_NAME, REPOSITORY_NAME, COMMIT_ID
|
// REPOSITORY_NAME,
|
||||||
) CSS ON PR.USER_NAME = CSS.USER_NAME AND PR.REPOSITORY_NAME = CSS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CSS.COMMIT_ID
|
// COMMIT_ID
|
||||||
WHERE $issueIdQuery
|
// FROM COMMIT_STATUS WHERE STATE = 'success' GROUP BY USER_NAME, REPOSITORY_NAME, COMMIT_ID
|
||||||
GROUP BY PR.USER_NAME, PR.REPOSITORY_NAME, PR.ISSUE_ID, CSS.CS_SUCCESS
|
// ) CSS ON PR.USER_NAME = CSS.USER_NAME AND PR.REPOSITORY_NAME = CSS.REPOSITORY_NAME AND PR.COMMIT_ID_TO = CSS.COMMIT_ID
|
||||||
) as SUMM
|
// WHERE $issueIdQuery
|
||||||
LEFT OUTER JOIN COMMIT_STATUS CSD
|
// GROUP BY PR.USER_NAME, PR.REPOSITORY_NAME, PR.ISSUE_ID, CSS.CS_SUCCESS
|
||||||
ON SUMM.CS_ALL = 1 AND SUMM.COMMIT_ID = CSD.COMMIT_ID""");
|
// ) as SUMM
|
||||||
query(issueList).list.map {
|
// LEFT OUTER JOIN COMMIT_STATUS CSD
|
||||||
case(userName, repositoryName, issueId, count, successCount, context, state, targetUrl, description) =>
|
// ON SUMM.CS_ALL = 1 AND SUMM.COMMIT_ID = CSD.COMMIT_ID""");
|
||||||
(userName, repositoryName, issueId) -> CommitStatusInfo(count, successCount, context, state, targetUrl, description)
|
// query(issueList).list.map {
|
||||||
}.toMap
|
// 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] = {
|
(implicit s: Session): List[IssueInfo] = {
|
||||||
// get issues and comment count and labels
|
// get issues and comment count and labels
|
||||||
val result = searchIssueQueryBase(condition, pullRequest, offset, limit, repos)
|
val result = searchIssueQueryBase(condition, pullRequest, offset, limit, repos)
|
||||||
.leftJoin (IssueLabels) .on { case ((t1, t2), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
|
.joinLeft (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) }
|
.joinLeft (Labels) .on { case (((t1, t2), t3), t4) => t3.map(_.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 (Milestones) .on { case ((((t1, t2), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) }
|
||||||
.map { case ((((t1, t2), t3), t4), t5) =>
|
.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
|
.list
|
||||||
.splitWith { (c1, c2) =>
|
.splitWith { (c1, c2) =>
|
||||||
@@ -196,10 +198,10 @@ trait IssuesService {
|
|||||||
(implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = {
|
(implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = {
|
||||||
// get issues and comment count and labels
|
// get issues and comment count and labels
|
||||||
searchIssueQueryBase(condition, true, offset, limit, repos)
|
searchIssueQueryBase(condition, true, offset, limit, repos)
|
||||||
.innerJoin(PullRequests).on { case ((t1, t2), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) }
|
.join(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) }
|
.join(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 }
|
.join(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(Accounts).on { case (((((t1, t2), t3), t4), t5), t6) => t6.userName === t4.userName }
|
||||||
.map { case (((((t1, t2), t3), t4), t5), t6) =>
|
.map { case (((((t1, t2), t3), t4), t5), t6) =>
|
||||||
(t1, t5, t2.commentCount, t3, t4, 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)])
|
private def searchIssueQueryBase(condition: IssueSearchCondition, pullRequest: Boolean, offset: Int, limit: Int, repos: Seq[(String, String)])
|
||||||
(implicit s: Session) =
|
(implicit s: Session) =
|
||||||
searchIssueQuery(repos, condition, pullRequest)
|
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) =>
|
.sortBy { case (t1, t2) =>
|
||||||
(condition.sort match {
|
(condition.sort match {
|
||||||
case "created" => t1.registeredDate
|
case "created" => t1.registeredDate
|
||||||
case "comments" => t2.commentCount
|
case "comments" => t2.commentCount
|
||||||
case "updated" => t1.updatedDate
|
case "updated" => t1.updatedDate
|
||||||
}) match {
|
}) match {
|
||||||
case sort => condition.direction match {
|
case sort: slick.lifted.ColumnOrdered[_] => condition.direction match {
|
||||||
case "asc" => sort asc
|
case "asc" => sort asc
|
||||||
case "desc" => sort desc
|
case "desc" => sort desc
|
||||||
}
|
}
|
||||||
@@ -232,7 +234,7 @@ trait IssuesService {
|
|||||||
Issues filter { t1 =>
|
Issues filter { t1 =>
|
||||||
repos
|
repos
|
||||||
.map { case (owner, repository) => t1.byRepository(owner, repository) }
|
.map { case (owner, repository) => t1.byRepository(owner, repository) }
|
||||||
.foldLeft[Column[Boolean]](false) ( _ || _ ) &&
|
.foldLeft[Rep[Boolean]](false) ( _ || _ ) &&
|
||||||
(t1.closed === (condition.state == "closed").bind) &&
|
(t1.closed === (condition.state == "closed").bind) &&
|
||||||
(t1.milestoneId.? isEmpty, condition.milestone == Some(None)) &&
|
(t1.milestoneId.? isEmpty, condition.milestone == Some(None)) &&
|
||||||
(t1.assignedUserName.? isEmpty, condition.assigned == Some(None)) &&
|
(t1.assignedUserName.? isEmpty, condition.assigned == Some(None)) &&
|
||||||
@@ -274,7 +276,7 @@ trait IssuesService {
|
|||||||
// next id number
|
// next id number
|
||||||
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
|
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
|
||||||
.firstOption.filter { id =>
|
.firstOption.filter { id =>
|
||||||
Issues insert Issue(
|
Issues unsafeInsert Issue(
|
||||||
owner,
|
owner,
|
||||||
repository,
|
repository,
|
||||||
id,
|
id,
|
||||||
@@ -292,14 +294,14 @@ trait IssuesService {
|
|||||||
IssueId
|
IssueId
|
||||||
.filter (_.byPrimaryKey(owner, repository))
|
.filter (_.byPrimaryKey(owner, repository))
|
||||||
.map (_.issueId)
|
.map (_.issueId)
|
||||||
.update (id) > 0
|
.unsafeUpdate (id) > 0
|
||||||
} get
|
} get
|
||||||
|
|
||||||
def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) =
|
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) =
|
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,
|
def createComment(owner: String, repository: String, loginUser: String,
|
||||||
issueId: Int, content: String, action: String)(implicit s: Session): Int =
|
issueId: Int, content: String, action: String)(implicit s: Session): Int =
|
||||||
@@ -320,15 +322,15 @@ trait IssuesService {
|
|||||||
.map { t =>
|
.map { t =>
|
||||||
(t.title, t.content.?, t.updatedDate)
|
(t.title, t.content.?, t.updatedDate)
|
||||||
}
|
}
|
||||||
.update (title, content, currentDate)
|
.unsafeUpdate (title, content, currentDate)
|
||||||
|
|
||||||
def updateAssignedUserName(owner: String, repository: String, issueId: Int,
|
def updateAssignedUserName(owner: String, repository: String, issueId: Int,
|
||||||
assignedUserName: Option[String])(implicit s: Session) =
|
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,
|
def updateMilestoneId(owner: String, repository: String, issueId: Int,
|
||||||
milestoneId: Option[Int])(implicit s: Session) =
|
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) =
|
def updateComment(commentId: Int, content: String)(implicit s: Session) =
|
||||||
IssueComments
|
IssueComments
|
||||||
@@ -336,10 +338,10 @@ trait IssuesService {
|
|||||||
.map { t =>
|
.map { t =>
|
||||||
t.content -> t.updatedDate
|
t.content -> t.updatedDate
|
||||||
}
|
}
|
||||||
.update (content, currentDate)
|
.unsafeUpdate (content, currentDate)
|
||||||
|
|
||||||
def deleteComment(commentId: Int)(implicit s: Session) =
|
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) =
|
def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) =
|
||||||
Issues
|
Issues
|
||||||
@@ -347,7 +349,7 @@ trait IssuesService {
|
|||||||
.map { t =>
|
.map { t =>
|
||||||
t.closed -> t.updatedDate
|
t.closed -> t.updatedDate
|
||||||
}
|
}
|
||||||
.update (closed, currentDate)
|
.usnafeUpdate (closed, currentDate)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search issues by keyword.
|
* Search issues by keyword.
|
||||||
@@ -359,13 +361,13 @@ trait IssuesService {
|
|||||||
*/
|
*/
|
||||||
def searchIssuesByKeyword(owner: String, repository: String, query: String)
|
def searchIssuesByKeyword(owner: String, repository: String, query: String)
|
||||||
(implicit s: Session): List[(Issue, Int, String)] = {
|
(implicit s: Session): List[(Issue, Int, String)] = {
|
||||||
import slick.driver.JdbcDriver.likeEncode
|
//import slick.driver.JdbcDriver.likeEncode
|
||||||
val keywords = splitWords(query.toLowerCase)
|
val keywords = splitWords(query.toLowerCase)
|
||||||
|
|
||||||
// Search Issue
|
// Search Issue
|
||||||
val issues = Issues
|
val issues = Issues
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
.innerJoin(IssueOutline).on { case (t1, t2) =>
|
.join(IssueOutline).on { case (t1, t2) =>
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter { case (t1, t2) =>
|
.filter { case (t1, t2) =>
|
||||||
@@ -381,10 +383,10 @@ trait IssuesService {
|
|||||||
// Search IssueComment
|
// Search IssueComment
|
||||||
val comments = IssueComments
|
val comments = IssueComments
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
.innerJoin(Issues).on { case (t1, t2) =>
|
.join(Issues).on { case (t1, t2) =>
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
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)
|
t2.byIssue(t3.userName, t3.repositoryName, t3.issueId)
|
||||||
}
|
}
|
||||||
.filter { case ((t1, t2), t3) =>
|
.filter { case ((t1, t2), t3) =>
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ package gitbucket.core.service
|
|||||||
|
|
||||||
import gitbucket.core.model.Label
|
import gitbucket.core.model.Label
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
|
import scala.concurrent.Await
|
||||||
|
import scala.concurrent.duration.Duration
|
||||||
|
|
||||||
trait LabelsService {
|
trait LabelsService {
|
||||||
|
|
||||||
@@ -15,13 +19,18 @@ trait LabelsService {
|
|||||||
def getLabel(owner: String, repository: String, labelName: String)(implicit s: Session): Option[Label] =
|
def getLabel(owner: String, repository: String, labelName: String)(implicit s: Session): Option[Label] =
|
||||||
Labels.filter(_.byLabel(owner, repository, labelName)).firstOption
|
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 = {
|
||||||
Labels returning Labels.map(_.labelId) += Label(
|
// TODO [Slick3]Provide blocking method for returning
|
||||||
userName = owner,
|
val f = s.database.run(
|
||||||
repositoryName = repository,
|
Labels returning Labels.map(_.labelId) += Label(
|
||||||
labelName = labelName,
|
userName = owner,
|
||||||
color = color
|
repositoryName = repository,
|
||||||
|
labelName = labelName,
|
||||||
|
color = color
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
Await.result(f, Duration.Inf)
|
||||||
|
}
|
||||||
|
|
||||||
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String)
|
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
@@ -30,8 +39,8 @@ trait LabelsService {
|
|||||||
.update(labelName, color)
|
.update(labelName, color)
|
||||||
|
|
||||||
def deleteLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Unit = {
|
def deleteLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Unit = {
|
||||||
IssueLabels.filter(_.byLabel(owner, repository, labelId)).delete
|
IssueLabels.filter(_.byLabel(owner, repository, labelId)).unsafeDelete
|
||||||
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).delete
|
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).unsafeDelete
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package gitbucket.core.service
|
|||||||
|
|
||||||
import gitbucket.core.model.Milestone
|
import gitbucket.core.model.Milestone
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
// TODO Why is direct import required?
|
// TODO Why is direct import required?
|
||||||
import gitbucket.core.model.Profile.dateColumnType
|
import gitbucket.core.model.Profile.dateColumnType
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ trait MilestonesService {
|
|||||||
|
|
||||||
def createMilestone(owner: String, repository: String, title: String, description: Option[String],
|
def createMilestone(owner: String, repository: String, title: String, description: Option[String],
|
||||||
dueDate: Option[java.util.Date])(implicit s: Session): Unit =
|
dueDate: Option[java.util.Date])(implicit s: Session): Unit =
|
||||||
Milestones insert Milestone(
|
Milestones unsafeInsert Milestone(
|
||||||
userName = owner,
|
userName = owner,
|
||||||
repositoryName = repository,
|
repositoryName = repository,
|
||||||
title = title,
|
title = title,
|
||||||
@@ -44,6 +45,7 @@ trait MilestonesService {
|
|||||||
.filter { t => t.byRepository(owner, repository) && (t.milestoneId.? isDefined) }
|
.filter { t => t.byRepository(owner, repository) && (t.milestoneId.? isDefined) }
|
||||||
.groupBy { t => t.milestoneId -> t.closed }
|
.groupBy { t => t.milestoneId -> t.closed }
|
||||||
.map { case (t1, t2) => t1._1 -> t1._2 -> t2.length }
|
.map { case (t1, t2) => t1._1 -> t1._2 -> t2.length }
|
||||||
|
.list
|
||||||
.toMap
|
.toMap
|
||||||
|
|
||||||
getMilestones(owner, repository).map { milestone =>
|
getMilestones(owner, repository).map { milestone =>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package gitbucket.core.service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import gitbucket.core.model._
|
import gitbucket.core.model.{ProtectedBranch, ProtectedBranchContext, CommitState}
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.plugin.ReceiveHook
|
import gitbucket.core.plugin.ReceiveHook
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand}
|
import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand}
|
||||||
|
|
||||||
@@ -12,14 +13,14 @@ trait ProtectedBranchService {
|
|||||||
import ProtectedBranchService._
|
import ProtectedBranchService._
|
||||||
private def getProtectedBranchInfoOpt(owner: String, repository: String, branch: String)(implicit session: Session): Option[ProtectedBranchInfo] =
|
private def getProtectedBranchInfoOpt(owner: String, repository: String, branch: String)(implicit session: Session): Option[ProtectedBranchInfo] =
|
||||||
ProtectedBranches
|
ProtectedBranches
|
||||||
.leftJoin(ProtectedBranchContexts)
|
.joinLeft(ProtectedBranchContexts)
|
||||||
.on{ case (pb, c) => pb.byBranch(c.userName, c.repositoryName, c.branch) }
|
.on { case (pb, c) => pb.byBranch(c.userName, c.repositoryName, c.branch) }
|
||||||
.map{ case (pb, c) => pb -> c.context.? }
|
.map { case (pb, c) => pb -> c.map(_.context) }
|
||||||
.filter(_._1.byPrimaryKey(owner, repository, branch))
|
.filter(_._1.byPrimaryKey(owner, repository, branch))
|
||||||
.list
|
.list
|
||||||
.groupBy(_._1)
|
.groupBy(_._1)
|
||||||
.map(p => p._1 -> p._2.flatMap(_._2))
|
.map { p => p._1 -> p._2.flatMap(_._2) }
|
||||||
.map{ case (t1, contexts) =>
|
.map { case (t1, contexts) =>
|
||||||
new ProtectedBranchInfo(t1.userName, t1.repositoryName, true, contexts, t1.statusCheckAdmin)
|
new ProtectedBranchInfo(t1.userName, t1.repositoryName, true, contexts, t1.statusCheckAdmin)
|
||||||
}.headOption
|
}.headOption
|
||||||
|
|
||||||
@@ -32,9 +33,9 @@ trait ProtectedBranchService {
|
|||||||
def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String])
|
def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String])
|
||||||
(implicit session: Session): Unit = {
|
(implicit session: Session): Unit = {
|
||||||
disableBranchProtection(owner, repository, branch)
|
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 =>
|
contexts.map{ context =>
|
||||||
ProtectedBranchContexts.insert(new ProtectedBranchContext(owner, repository, branch, context))
|
ProtectedBranchContexts.unsafeInsert(new ProtectedBranchContext(owner, repository, branch, context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package gitbucket.core.service
|
|||||||
import gitbucket.core.model.{Account, Issue, PullRequest, WebHook, CommitStatus, CommitState}
|
import gitbucket.core.model.{Account, Issue, PullRequest, WebHook, CommitStatus, CommitState}
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.util.JGitUtil
|
import gitbucket.core.util.JGitUtil
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
|
|
||||||
trait PullRequestService { self: IssuesService =>
|
trait PullRequestService { self: IssuesService =>
|
||||||
@@ -26,7 +27,7 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String])
|
def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String])
|
||||||
(implicit s: Session): List[PullRequestCount] =
|
(implicit s: Session): List[PullRequestCount] =
|
||||||
PullRequests
|
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) =>
|
.filter { case (t1, t2) =>
|
||||||
(t2.closed === closed.bind) &&
|
(t2.closed === closed.bind) &&
|
||||||
(t1.userName === owner.get.bind, owner.isDefined) &&
|
(t1.userName === owner.get.bind, owner.isDefined) &&
|
||||||
@@ -59,7 +60,7 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
def createPullRequest(originUserName: String, originRepositoryName: String, issueId: Int,
|
def createPullRequest(originUserName: String, originRepositoryName: String, issueId: Int,
|
||||||
originBranch: String, requestUserName: String, requestRepositoryName: String, requestBranch: String,
|
originBranch: String, requestUserName: String, requestRepositoryName: String, requestBranch: String,
|
||||||
commitIdFrom: String, commitIdTo: String)(implicit s: Session): Unit =
|
commitIdFrom: String, commitIdTo: String)(implicit s: Session): Unit =
|
||||||
PullRequests insert PullRequest(
|
PullRequests unsafeInsert PullRequest(
|
||||||
originUserName,
|
originUserName,
|
||||||
originRepositoryName,
|
originRepositoryName,
|
||||||
issueId,
|
issueId,
|
||||||
@@ -73,7 +74,7 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Boolean)
|
def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Boolean)
|
||||||
(implicit s: Session): List[PullRequest] =
|
(implicit s: Session): List[PullRequest] =
|
||||||
PullRequests
|
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) =>
|
.filter { case (t1, t2) =>
|
||||||
(t1.requestUserName === userName.bind) &&
|
(t1.requestUserName === userName.bind) &&
|
||||||
(t1.requestRepositoryName === repositoryName.bind) &&
|
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||||
@@ -93,7 +94,7 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
def getPullRequestFromBranch(userName: String, repositoryName: String, branch: String, defaultBranch: String)
|
def getPullRequestFromBranch(userName: String, repositoryName: String, branch: String, defaultBranch: String)
|
||||||
(implicit s: Session): Option[(PullRequest, Issue)] =
|
(implicit s: Session): Option[(PullRequest, Issue)] =
|
||||||
PullRequests
|
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) =>
|
.filter { case (t1, t2) =>
|
||||||
(t1.requestUserName === userName.bind) &&
|
(t1.requestUserName === userName.bind) &&
|
||||||
(t1.requestRepositoryName === repositoryName.bind) &&
|
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||||
@@ -124,7 +125,7 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
PullRequests
|
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) =>
|
.filter { case (t1, t2) =>
|
||||||
(t1.userName === userName.bind) &&
|
(t1.userName === userName.bind) &&
|
||||||
(t1.repositoryName === repositoryName.bind) &&
|
(t1.repositoryName === repositoryName.bind) &&
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import gitbucket.core.model.Account
|
|||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.dircache.DirCache
|
import org.eclipse.jgit.dircache.DirCache
|
||||||
import org.eclipse.jgit.lib.{FileMode, Constants}
|
import org.eclipse.jgit.lib.{FileMode, Constants}
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
trait RepositoryCreationService {
|
trait RepositoryCreationService {
|
||||||
self: AccountService with RepositoryService with LabelsService with WikiService with ActivityService =>
|
self: AccountService with RepositoryService with LabelsService with WikiService with ActivityService =>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.eclipse.jgit.treewalk.TreeWalk
|
|||||||
import org.eclipse.jgit.lib.FileMode
|
import org.eclipse.jgit.lib.FileMode
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile.api._
|
||||||
|
|
||||||
trait RepositorySearchService { self: IssuesService =>
|
trait RepositorySearchService { self: IssuesService =>
|
||||||
import RepositorySearchService._
|
import RepositorySearchService._
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import gitbucket.core.controller.Context
|
|||||||
import gitbucket.core.model.{Collaborator, Repository, Account}
|
import gitbucket.core.model.{Collaborator, Repository, Account}
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import gitbucket.core.util.JGitUtil
|
import gitbucket.core.util.JGitUtil
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
trait RepositoryService { self: AccountService =>
|
trait RepositoryService { self: AccountService =>
|
||||||
import RepositoryService._
|
import RepositoryService._
|
||||||
@@ -23,7 +24,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
originRepositoryName: Option[String] = None, originUserName: Option[String] = None,
|
originRepositoryName: Option[String] = None, originUserName: Option[String] = None,
|
||||||
parentRepositoryName: Option[String] = None, parentUserName: Option[String] = None)
|
parentRepositoryName: Option[String] = None, parentUserName: Option[String] = None)
|
||||||
(implicit s: Session): Unit = {
|
(implicit s: Session): Unit = {
|
||||||
Repositories insert
|
Repositories unsafeInsert
|
||||||
Repository(
|
Repository(
|
||||||
userName = userName,
|
userName = userName,
|
||||||
repositoryName = repositoryName,
|
repositoryName = repositoryName,
|
||||||
@@ -44,14 +45,14 @@ trait RepositoryService { self: AccountService =>
|
|||||||
externalWikiUrl = None
|
externalWikiUrl = None
|
||||||
)
|
)
|
||||||
|
|
||||||
IssueId insert (userName, repositoryName, 0)
|
IssueId unsafeInsert (userName, repositoryName, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
def renameRepository(oldUserName: String, oldRepositoryName: String, newUserName: String, newRepositoryName: String)
|
def renameRepository(oldUserName: String, oldRepositoryName: String, newUserName: String, newRepositoryName: String)
|
||||||
(implicit s: Session): Unit = {
|
(implicit s: Session): Unit = {
|
||||||
getAccountByUserName(newUserName).foreach { account =>
|
getAccountByUserName(newUserName).foreach { account =>
|
||||||
(Repositories filter { t => t.byRepository(oldUserName, oldRepositoryName) } firstOption).map { repository =>
|
(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 webHooks = WebHooks .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val webHookEvents = WebHookEvents .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val webHookEvents = WebHookEvents .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
@@ -70,62 +71,62 @@ trait RepositoryService { self: AccountService =>
|
|||||||
|
|
||||||
Repositories.filter { t =>
|
Repositories.filter { t =>
|
||||||
(t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind)
|
(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 =>
|
Repositories.filter { t =>
|
||||||
(t.parentUserName === oldUserName.bind) && (t.parentRepositoryName === oldRepositoryName.bind)
|
(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
|
// Updates activity fk before deleting repository because activity is sorted by activityId
|
||||||
// and it can't be changed by deleting-and-inserting record.
|
// and it can't be changed by deleting-and-inserting record.
|
||||||
Activities.filter(_.byRepository(oldUserName, oldRepositoryName)).list.foreach { activity =>
|
Activities.filter(_.byRepository(oldUserName, oldRepositoryName)).list.foreach { activity =>
|
||||||
Activities.filter(_.activityId === activity.activityId.bind)
|
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)
|
deleteRepository(oldUserName, oldRepositoryName)
|
||||||
|
|
||||||
WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// WebHookEvents.insertAll(webHookEvents .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*)
|
// IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*)
|
||||||
|
//
|
||||||
val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list
|
// val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list
|
||||||
Issues.insertAll(issues.map { x => x.copy(
|
// Issues.insertAll(issues.map { x => x.copy(
|
||||||
userName = newUserName,
|
// userName = newUserName,
|
||||||
repositoryName = newRepositoryName,
|
// repositoryName = newRepositoryName,
|
||||||
milestoneId = x.milestoneId.map { id =>
|
// milestoneId = x.milestoneId.map { id =>
|
||||||
newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId
|
// newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId
|
||||||
}
|
// }
|
||||||
)} :_*)
|
// )} :_*)
|
||||||
|
//
|
||||||
PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// CommitComments .insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
|
|
||||||
// Update source repository of pull requests
|
// Update source repository of pull requests
|
||||||
PullRequests.filter { t =>
|
PullRequests.filter { t =>
|
||||||
(t.requestUserName === oldUserName.bind) && (t.requestRepositoryName === oldRepositoryName.bind)
|
(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
|
// // Convert labelId
|
||||||
val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap
|
// 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
|
// val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap
|
||||||
IssueLabels.insertAll(issueLabels.map(x => x.copy(
|
// IssueLabels.insertAll(issueLabels.map(x => x.copy(
|
||||||
labelId = newLabelMap(oldLabelMap(x.labelId)),
|
// labelId = newLabelMap(oldLabelMap(x.labelId)),
|
||||||
userName = newUserName,
|
// userName = newUserName,
|
||||||
repositoryName = newRepositoryName
|
// repositoryName = newRepositoryName
|
||||||
)) :_*)
|
// )) :_*)
|
||||||
|
//
|
||||||
if(account.isGroupAccount){
|
// if(account.isGroupAccount){
|
||||||
Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*)
|
// Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*)
|
||||||
} else {
|
// } else {
|
||||||
Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
// Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Update activity messages
|
// Update activity messages
|
||||||
Activities.filter { t =>
|
Activities.filter { t =>
|
||||||
@@ -133,7 +134,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
(t.message like s"%:${oldUserName}/${oldRepositoryName}#%") ||
|
(t.message like s"%:${oldUserName}/${oldRepositoryName}#%") ||
|
||||||
(t.message like s"%:${oldUserName}/${oldRepositoryName}@%")
|
(t.message like s"%:${oldUserName}/${oldRepositoryName}@%")
|
||||||
}.map { t => t.activityId -> t.message }.list.foreach { case (activityId, message) =>
|
}.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
|
message
|
||||||
.replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]")
|
.replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]")
|
||||||
.replace(s"[branch:${oldUserName}/${oldRepositoryName}#" ,s"[branch:${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 = {
|
def deleteRepository(userName: String, repositoryName: String)(implicit s: Session): Unit = {
|
||||||
Activities .filter(_.byRepository(userName, repositoryName)).delete
|
Activities .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
Collaborators .filter(_.byRepository(userName, repositoryName)).delete
|
Collaborators .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
CommitComments.filter(_.byRepository(userName, repositoryName)).delete
|
CommitComments.filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
IssueLabels .filter(_.byRepository(userName, repositoryName)).delete
|
IssueLabels .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
Labels .filter(_.byRepository(userName, repositoryName)).delete
|
Labels .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
IssueComments .filter(_.byRepository(userName, repositoryName)).delete
|
IssueComments .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
PullRequests .filter(_.byRepository(userName, repositoryName)).delete
|
PullRequests .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
Issues .filter(_.byRepository(userName, repositoryName)).delete
|
Issues .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
IssueId .filter(_.byRepository(userName, repositoryName)).delete
|
IssueId .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
Milestones .filter(_.byRepository(userName, repositoryName)).delete
|
Milestones .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
WebHooks .filter(_.byRepository(userName, repositoryName)).delete
|
WebHooks .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
WebHookEvents .filter(_.byRepository(userName, repositoryName)).delete
|
WebHookEvents .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
Repositories .filter(_.byRepository(userName, repositoryName)).delete
|
Repositories .filter(_.byRepository(userName, repositoryName)).unsafeDelete
|
||||||
|
|
||||||
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME
|
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME
|
||||||
Repositories
|
Repositories
|
||||||
@@ -171,7 +172,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
Repositories
|
Repositories
|
||||||
.filter(_.byRepository(userName, repositoryName))
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
.map(x => (x.originUserName?, x.originRepositoryName?))
|
.map(x => (x.originUserName?, x.originRepositoryName?))
|
||||||
.update(None, None)
|
.unsafeUpdate(None, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME
|
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME
|
||||||
@@ -183,7 +184,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
Repositories
|
Repositories
|
||||||
.filter(_.byRepository(userName, repositoryName))
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
.map(x => (x.parentUserName?, x.parentRepositoryName?))
|
.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.
|
* Updates the last activity date of the repository.
|
||||||
*/
|
*/
|
||||||
def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit =
|
def updateLastActivityDate(userName: String, repositoryName: String)(implicit s: Session): Unit =
|
||||||
Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate)
|
Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).unsafeUpdate(currentDate)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save repository options.
|
* Save repository options.
|
||||||
@@ -324,13 +325,13 @@ trait RepositoryService { self: AccountService =>
|
|||||||
enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit =
|
enableWiki: Boolean, allowWikiEditing: Boolean, externalWikiUrl: Option[String])(implicit s: Session): Unit =
|
||||||
Repositories.filter(_.byRepository(userName, repositoryName))
|
Repositories.filter(_.byRepository(userName, repositoryName))
|
||||||
.map { r => (r.description.?, r.isPrivate, r.enableIssues, r.externalIssuesUrl.?, r.enableWiki, r.allowWikiEditing, r.externalWikiUrl.?, r.updatedDate) }
|
.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,
|
def saveRepositoryDefaultBranch(userName: String, repositoryName: String,
|
||||||
defaultBranch: String)(implicit s: Session): Unit =
|
defaultBranch: String)(implicit s: Session): Unit =
|
||||||
Repositories.filter(_.byRepository(userName, repositoryName))
|
Repositories.filter(_.byRepository(userName, repositoryName))
|
||||||
.map { r => r.defaultBranch }
|
.map { r => r.defaultBranch }
|
||||||
.update (defaultBranch)
|
.unsafeUpdate (defaultBranch)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add collaborator to the repository.
|
* Add collaborator to the repository.
|
||||||
@@ -340,7 +341,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @param collaboratorName the collaborator name
|
* @param collaboratorName the collaborator name
|
||||||
*/
|
*/
|
||||||
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit =
|
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.
|
* Remove collaborator from the repository.
|
||||||
@@ -350,7 +351,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @param collaboratorName the collaborator name
|
* @param collaboratorName the collaborator name
|
||||||
*/
|
*/
|
||||||
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit =
|
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.
|
* Remove all collaborators from the repository.
|
||||||
@@ -359,7 +360,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @param repositoryName the repository name
|
* @param repositoryName the repository name
|
||||||
*/
|
*/
|
||||||
def removeCollaborators(userName: String, repositoryName: String)(implicit s: Session): Unit =
|
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.
|
* Returns the list of collaborators name which is sorted with ascending order.
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package gitbucket.core.service
|
|||||||
|
|
||||||
import gitbucket.core.model.SshKey
|
import gitbucket.core.model.SshKey
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import profile.simple._
|
import profile._
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
trait SshKeyService {
|
trait SshKeyService {
|
||||||
|
|
||||||
def addPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit =
|
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] =
|
def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] =
|
||||||
SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list
|
SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import gitbucket.core.api._
|
|||||||
import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent, CommitComment}
|
import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent, CommitComment}
|
||||||
import gitbucket.core.model.Profile._
|
import gitbucket.core.model.Profile._
|
||||||
import org.apache.http.client.utils.URLEncodedUtils
|
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.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util.RepositoryName
|
import gitbucket.core.util.RepositoryName
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
@@ -32,14 +33,14 @@ trait WebHookService {
|
|||||||
/** get All WebHook informations of repository */
|
/** get All WebHook informations of repository */
|
||||||
def getWebHooks(owner: String, repository: String)(implicit s: Session): List[(WebHook, Set[WebHook.Event])] =
|
def getWebHooks(owner: String, repository: String)(implicit s: Session): List[(WebHook, Set[WebHook.Event])] =
|
||||||
WebHooks.filter(_.byRepository(owner, repository))
|
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 }
|
.map{ case (w,t) => w -> t.event }
|
||||||
.list.groupBy(_._1).mapValues(_.map(_._2).toSet).toList.sortBy(_._1.url)
|
.list.groupBy(_._1).mapValues(_.map(_._2).toSet).toList.sortBy(_._1.url)
|
||||||
|
|
||||||
/** get All WebHook informations of repository event */
|
/** get All WebHook informations of repository event */
|
||||||
def getWebHooksByEvent(owner: String, repository: String, event: WebHook.Event)(implicit s: Session): List[WebHook] =
|
def getWebHooksByEvent(owner: String, repository: String, event: WebHook.Event)(implicit s: Session): List[WebHook] =
|
||||||
WebHooks.filter(_.byRepository(owner, repository))
|
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}
|
.filter{ case (wh, whe) => whe.event === event.bind}
|
||||||
.map{ case (wh, whe) => wh }
|
.map{ case (wh, whe) => wh }
|
||||||
.list.distinct
|
.list.distinct
|
||||||
@@ -48,27 +49,27 @@ trait WebHookService {
|
|||||||
def getWebHook(owner: String, repository: String, url: String)(implicit s: Session): Option[(WebHook, Set[WebHook.Event])] =
|
def getWebHook(owner: String, repository: String, url: String)(implicit s: Session): Option[(WebHook, Set[WebHook.Event])] =
|
||||||
WebHooks
|
WebHooks
|
||||||
.filter(_.byPrimaryKey(owner, repository, url))
|
.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 }
|
.map{ case (w,t) => w -> t.event }
|
||||||
.list.groupBy(_._1).mapValues(_.map(_._2).toSet).headOption
|
.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 = {
|
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)
|
WebHooks unsafeInsert WebHook(owner, repository, url, ctype, token)
|
||||||
events.toSet.map{ event: WebHook.Event =>
|
events.toSet.map { event: WebHook.Event =>
|
||||||
WebHookEvents insert WebHookEvent(owner, repository, url, event)
|
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 = {
|
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))
|
WebHooks.filter(_.byPrimaryKey(owner, repository, url)).map(w => (w.ctype, w.token)).unsafeUpdate((ctype, token))
|
||||||
WebHookEvents.filter(_.byWebHook(owner, repository, url)).delete
|
WebHookEvents.filter(_.byWebHook(owner, repository, url)).unsafeDelete
|
||||||
events.toSet.map{ event: WebHook.Event =>
|
events.toSet.map { event: WebHook.Event =>
|
||||||
WebHookEvents insert WebHookEvent(owner, repository, url, event)
|
WebHookEvents unsafeInsert WebHookEvent(owner, repository, url, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def deleteWebHook(owner: String, repository: String, url :String)(implicit s: Session): Unit =
|
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])
|
def callWebHookOf(owner: String, repository: String, event: WebHook.Event)(makePayload: => Option[WebHookPayload])
|
||||||
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import gitbucket.core.service.{ActivityService, SystemSettingsService}
|
|||||||
import gitbucket.core.util.DatabaseConfig
|
import gitbucket.core.util.DatabaseConfig
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.JDBCUtil._
|
import gitbucket.core.util.JDBCUtil._
|
||||||
|
import gitbucket.core.model.Profile.profile._
|
||||||
import io.github.gitbucket.solidbase.Solidbase
|
import io.github.gitbucket.solidbase.Solidbase
|
||||||
import io.github.gitbucket.solidbase.manager.JDBCVersionManager
|
import io.github.gitbucket.solidbase.manager.JDBCVersionManager
|
||||||
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.scalatra.ScalatraBase
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session}
|
import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session}
|
||||||
import gitbucket.core.util.Keys
|
import gitbucket.core.util.Keys
|
||||||
|
import gitbucket.core.model.Profile.profile._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the transaction with the open session in view pattern.
|
* 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
|
// Register Scalatra error callback to rollback transaction
|
||||||
ScalatraBase.onFailure { _ =>
|
ScalatraBase.onFailure { _ =>
|
||||||
logger.debug("Rolled back transaction")
|
logger.debug("Rolled back transaction")
|
||||||
session.rollback()
|
session.conn.rollback()
|
||||||
}(req.asInstanceOf[HttpServletRequest])
|
}(req.asInstanceOf[HttpServletRequest])
|
||||||
|
|
||||||
logger.debug("begin transaction")
|
logger.debug("begin transaction")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gitbucket.core.ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
import gitbucket.core.model.Session
|
import gitbucket.core.model.Session
|
||||||
|
import gitbucket.core.model.Profile.profile._
|
||||||
import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry}
|
import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry}
|
||||||
import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService}
|
import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService}
|
||||||
import gitbucket.core.servlet.{Database, CommitLogHook}
|
import gitbucket.core.servlet.{Database, CommitLogHook}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package gitbucket.core.ssh
|
|||||||
|
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
|
|
||||||
import gitbucket.core.model.SshKey
|
|
||||||
import gitbucket.core.service.SshKeyService
|
import gitbucket.core.service.SshKeyService
|
||||||
import gitbucket.core.servlet.Database
|
import gitbucket.core.servlet.Database
|
||||||
|
import gitbucket.core.model.Profile.profile._
|
||||||
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
|
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
|
||||||
import org.apache.sshd.server.session.ServerSession
|
import org.apache.sshd.server.session.ServerSession
|
||||||
import org.apache.sshd.common.AttributeStore
|
import org.apache.sshd.common.AttributeStore
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package gitbucket.core.util
|
|||||||
|
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import Directory._
|
import Directory._
|
||||||
|
import com.github.takezoe.slick.blocking.{BlockingH2Driver, BlockingMySQLDriver, SlickBlockingAPI}
|
||||||
import liquibase.database.AbstractJdbcDatabase
|
import liquibase.database.AbstractJdbcDatabase
|
||||||
import liquibase.database.core.{PostgresDatabase, MySQLDatabase, H2Database}
|
import liquibase.database.core.{H2Database, MySQLDatabase, PostgresDatabase}
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
|
||||||
object DatabaseConfig {
|
object DatabaseConfig {
|
||||||
@@ -32,14 +34,14 @@ object DatabaseConfig {
|
|||||||
lazy val user: String = config.getString("db.user")
|
lazy val user: String = config.getString("db.user")
|
||||||
lazy val password: String = config.getString("db.password")
|
lazy val password: String = config.getString("db.password")
|
||||||
lazy val jdbcDriver: String = DatabaseType(url).jdbcDriver
|
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
|
lazy val liquiDriver: AbstractJdbcDatabase = DatabaseType(url).liquiDriver
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait DatabaseType {
|
sealed trait DatabaseType {
|
||||||
val jdbcDriver: String
|
val jdbcDriver: String
|
||||||
val slickDriver: slick.driver.JdbcProfile
|
val slickDriver: SlickBlockingAPI
|
||||||
val liquiDriver: AbstractJdbcDatabase
|
val liquiDriver: AbstractJdbcDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +61,13 @@ object DatabaseType {
|
|||||||
|
|
||||||
object H2 extends DatabaseType {
|
object H2 extends DatabaseType {
|
||||||
val jdbcDriver = "org.h2.Driver"
|
val jdbcDriver = "org.h2.Driver"
|
||||||
val slickDriver = slick.driver.H2Driver
|
val slickDriver = BlockingH2Driver
|
||||||
val liquiDriver = new H2Database()
|
val liquiDriver = new H2Database()
|
||||||
}
|
}
|
||||||
|
|
||||||
object MySQL extends DatabaseType {
|
object MySQL extends DatabaseType {
|
||||||
val jdbcDriver = "com.mysql.jdbc.Driver"
|
val jdbcDriver = "com.mysql.jdbc.Driver"
|
||||||
val slickDriver = slick.driver.MySQLDriver
|
val slickDriver = BlockingMySQLDriver
|
||||||
val liquiDriver = new MySQLDatabase()
|
val liquiDriver = new MySQLDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gitbucket.core.util
|
package gitbucket.core.util
|
||||||
|
|
||||||
import gitbucket.core.model.{Session, Issue}
|
import gitbucket.core.model.{Session, Issue}
|
||||||
|
import gitbucket.core.model.Profile.profile._
|
||||||
import gitbucket.core.service.{RepositoryService, AccountService, IssuesService, SystemSettingsService}
|
import gitbucket.core.service.{RepositoryService, AccountService, IssuesService, SystemSettingsService}
|
||||||
import gitbucket.core.servlet.Database
|
import gitbucket.core.servlet.Database
|
||||||
import gitbucket.core.view.Markdown
|
import gitbucket.core.view.Markdown
|
||||||
|
|||||||
Reference in New Issue
Block a user