diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index 5e3c110..5a6eb75 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -7,11 +7,8 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile => import profile.api._ - import self._ - lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){ - def autoInc = this returning this.map(_.commentId) - } + lazy val IssueComments = TableQuery[IssueComments] class IssueComments(tag: Tag) extends Table[IssueComment](tag, "ISSUE_COMMENT") with IssueTemplate { val commentId = column[Int]("COMMENT_ID", O AutoInc) @@ -40,11 +37,8 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile => import profile.api._ - import self._ - lazy val CommitComments = new TableQuery(tag => new CommitComments(tag)){ - def autoInc = this returning this.map(_.commentId) - } + lazy val CommitComments = TableQuery[CommitComments] class CommitComments(tag: Tag) extends Table[CommitComment](tag, "COMMIT_COMMENT") with CommitTemplate { val commentId = column[Int]("COMMENT_ID", O AutoInc) diff --git a/src/main/scala/gitbucket/core/plugin/Sessions.scala b/src/main/scala/gitbucket/core/plugin/Sessions.scala index dc38702..e330485 100644 --- a/src/main/scala/gitbucket/core/plugin/Sessions.scala +++ b/src/main/scala/gitbucket/core/plugin/Sessions.scala @@ -1,6 +1,6 @@ package gitbucket.core.plugin -import scala.slick.jdbc.JdbcBackend.Session +import slick.jdbc.JdbcBackend.Session /** * Provides Slick Session to Plug-ins. diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 90a2d6b..f7d730c 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -24,7 +24,7 @@ }.update((state, targetUrl, now, creator.userName, description)) id } - case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus( + case None => (CommitStatuses returningId CommitStatuses.map(_.commitStatusId)) unsafeInsert CommitStatus( userName = userName, repositoryName = repositoryName, commitId = sha, diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 68a2a53..fae4f7c 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -30,7 +30,7 @@ def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String, content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], issueId: Option[Int])(implicit s: Session): Int = - CommitComments.autoInc insert CommitComment( + CommitComments returningId CommitComments.map(_.commentId) unsafeInsert CommitComment( userName = owner, repositoryName = repository, commitId = commitId, diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index be75822..27ea0e0 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -2,18 +2,16 @@ import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil.CommitInfo -import gitbucket.core.util.StringUtil import profile._ import profile.api._ import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ import gitbucket.core.model.{Account, CommitState, Issue, IssueComment, IssueLabel, Label, PullRequest, Repository} -import slick.profile.SqlUtilsComponent //import scala.slick.jdbc.{StaticQuery => Q} -trait IssuesService extends SqlUtilsComponent { +trait IssuesService { self: AccountService => import IssuesService._ @@ -192,6 +190,7 @@ } /** for api + * * @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner) */ def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*) @@ -272,30 +271,31 @@ def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String], assignedUserName: Option[String], milestoneId: Option[Int], - isPullRequest: Boolean = false)(implicit s: Session) = - // next id number - sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] - .firstOption.filter { id => - Issues unsafeInsert Issue( - owner, - repository, - id, - loginUser, - milestoneId, - assignedUserName, - title, - content, - false, - currentDate, - currentDate, - isPullRequest) - - // increment issue id - IssueId - .filter (_.byPrimaryKey(owner, repository)) - .map (_.issueId) - .unsafeUpdate (id) > 0 - } get + isPullRequest: Boolean = false)(implicit s: Session) = 0 +// TODO [Slick3] +// // next id number +// sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] +// .firstOption.filter { id => +// Issues unsafeInsert Issue( +// owner, +// repository, +// id, +// loginUser, +// milestoneId, +// assignedUserName, +// title, +// content, +// false, +// currentDate, +// currentDate, +// isPullRequest) +// +// // increment issue id +// IssueId +// .filter (_.byPrimaryKey(owner, repository)) +// .map (_.issueId) +// .unsafeUpdate (id) > 0 +// } get def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = IssueLabels unsafeInsert IssueLabel(owner, repository, issueId, labelId) @@ -304,16 +304,17 @@ IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) unsafeDelete def createComment(owner: String, repository: String, loginUser: String, - issueId: Int, content: String, action: String)(implicit s: Session): Int = - IssueComments.autoInc insert IssueComment( - userName = owner, - repositoryName = repository, - issueId = issueId, - action = action, - commentedUserName = loginUser, - content = content, - registeredDate = currentDate, - updatedDate = currentDate) + issueId: Int, content: String, action: String)(implicit s: Session): Int = { + IssueComments returningId IssueComments.map(_.commentId) unsafeInsert IssueComment( + userName = owner, + repositoryName = repository, + issueId = issueId, + action = action, + commentedUserName = loginUser, + content = content, + registeredDate = currentDate, + updatedDate = currentDate) + } def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session) = @@ -418,7 +419,7 @@ } def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session) = { - StringUtil.extractIssueId(message).foreach { issueId => + extractIssueId(message).foreach { issueId => val content = fromIssue.issueId + ":" + fromIssue.title if(getIssue(owner, repository, issueId).isDefined){ // Not add if refer comment already exist. @@ -430,7 +431,7 @@ } def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session) = { - StringUtil.extractIssueId(commit.fullMessage).foreach { issueId => + extractIssueId(commit.fullMessage).foreach { issueId => if(getIssue(owner, repository, issueId).isDefined){ getAccountByMailAddress(commit.committerEmailAddress).foreach { account => createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit") diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index f6e4bc0..aef8e62 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -98,4 +98,19 @@ def extractCloseId(message: String): Iterator[String] = "(?i)(? b append '^' append c + case _ => b append c + } + b.toString + } + + }