From f1533cb168cbac371336a583e5df1b382d6e1cc5 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 8 Nov 2015 04:06:14 +0900 Subject: [PATCH 1/2] Count COMMIT_COMMENT as issue comment --- src/main/resources/update/3_9.sql | 21 +++++++++++++++++++ .../RepositoryViewerController.scala | 4 ++-- .../scala/gitbucket/core/model/Comment.scala | 6 ++++-- .../core/service/CommitsService.scala | 6 ++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/resources/update/3_9.sql b/src/main/resources/update/3_9.sql index 546a46d31..ec2ecf1b6 100644 --- a/src/main/resources/update/3_9.sql +++ b/src/main/resources/update/3_9.sql @@ -20,3 +20,24 @@ INSERT INTO WEB_HOOK_EVENT (USER_NAME, REPOSITORY_NAME, URL, EVENT) FROM WEB_HOOK, TMP_EVENTS; DROP TABLE TMP_EVENTS; + +ALTER TABLE COMMIT_COMMENT ADD COLUMN ISSUE_ID INT; + +CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS + SELECT + A.USER_NAME, + A.REPOSITORY_NAME, + A.ISSUE_ID, + NVL(B.COMMENT_COUNT, 0) + NVL(C.COMMENT_COUNT, 0) AS COMMENT_COUNT + FROM ISSUE A + LEFT OUTER JOIN ( + SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT + WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment') + GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID + ) B + ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID) + LEFT OUTER JOIN ( + SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT + GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID + ) C + ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID); diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index c6bcad7e7..02a785081 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -370,7 +370,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) => val id = params("id") createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName, form.content, - form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId.isDefined) + form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId) form.issueId match { case Some(issueId) => recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content) case None => recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content) @@ -395,7 +395,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) => val id = params("id") val commentId = createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName, - form.content, form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId.isDefined) + form.content, form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId) form.issueId match { case Some(issueId) => recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content) case None => recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content) diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index 5a1144092..ffe2c0187 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -56,7 +56,8 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile => val registeredDate = column[java.util.Date]("REGISTERED_DATE") val updatedDate = column[java.util.Date]("UPDATED_DATE") val pullRequest = column[Boolean]("PULL_REQUEST") - def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, pullRequest) <> (CommitComment.tupled, CommitComment.unapply) + val issueId = column[Option[Int]]("ISSUE_ID") + def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, pullRequest, issueId) <> (CommitComment.tupled, CommitComment.unapply) def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind } @@ -74,5 +75,6 @@ case class CommitComment( newLine: Option[Int], registeredDate: java.util.Date, updatedDate: java.util.Date, - pullRequest: Boolean + pullRequest: Boolean, + issueId: Option[Int] ) extends Comment diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index fbef7cd69..45219f112 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -27,7 +27,8 @@ trait CommitsService { None def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String, - content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], pullRequest: Boolean)(implicit s: Session): Int = + content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], + issueId: Option[Int])(implicit s: Session): Int = CommitComments.autoInc insert CommitComment( userName = owner, repositoryName = repository, @@ -39,7 +40,8 @@ trait CommitsService { newLine = newLine, registeredDate = currentDate, updatedDate = currentDate, - pullRequest = pullRequest) + pullRequest = issueId.isDefined, + issueId = issueId) def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = CommitComments From d3b21a4e394618432ea04f119875b83395cd1e5d Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 10 Nov 2015 11:35:59 +0900 Subject: [PATCH 2/2] Drop PULL_REQUEST column from COMMIT_COMMENT table --- src/main/resources/update/3_9.sql | 12 ++++++++++++ src/main/scala/gitbucket/core/model/Comment.scala | 4 +--- .../gitbucket/core/service/CommitsService.scala | 5 ++--- .../gitbucket/core/helper/commitcomment.scala.html | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/resources/update/3_9.sql b/src/main/resources/update/3_9.sql index ec2ecf1b6..b2f5c56c8 100644 --- a/src/main/resources/update/3_9.sql +++ b/src/main/resources/update/3_9.sql @@ -41,3 +41,15 @@ CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID ) C ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID); + + +UPDATE COMMIT_COMMENT C SET (ISSUE_ID) = ( + SELECT MAX(P.ISSUE_ID) + FROM PULL_REQUEST P + WHERE + C.USER_NAME = P.USER_NAME AND + C.REPOSITORY_NAME = P.REPOSITORY_NAME AND + C.COMMIT_ID = P.COMMIT_ID_TO +); + +ALTER TABLE COMMIT_COMMENT DROP COLUMN PULL_REQUEST; \ No newline at end of file diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index ffe2c0187..cab001c32 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -55,9 +55,8 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile => val newLine = column[Option[Int]]("NEW_LINE_NUMBER") val registeredDate = column[java.util.Date]("REGISTERED_DATE") val updatedDate = column[java.util.Date]("UPDATED_DATE") - val pullRequest = column[Boolean]("PULL_REQUEST") val issueId = column[Option[Int]]("ISSUE_ID") - def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, pullRequest, issueId) <> (CommitComment.tupled, CommitComment.unapply) + def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, issueId) <> (CommitComment.tupled, CommitComment.unapply) def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind } @@ -75,6 +74,5 @@ case class CommitComment( newLine: Option[Int], registeredDate: java.util.Date, updatedDate: java.util.Date, - pullRequest: Boolean, issueId: Option[Int] ) extends Comment diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index 45219f112..5ccffd530 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -13,9 +13,9 @@ import StringUtil._ trait CommitsService { - def getCommitComments(owner: String, repository: String, commitId: String, pullRequest: Boolean)(implicit s: Session) = + def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean)(implicit s: Session) = CommitComments filter { - t => t.byCommit(owner, repository, commitId) && (t.pullRequest === pullRequest || pullRequest) + t => t.byCommit(owner, repository, commitId) && (t.issueId.isEmpty || includePullRequest) } list def getCommitComment(owner: String, repository: String, commentId: String)(implicit s: Session) = @@ -40,7 +40,6 @@ trait CommitsService { newLine = newLine, registeredDate = currentDate, updatedDate = currentDate, - pullRequest = issueId.isDefined, issueId = issueId) def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = diff --git a/src/main/twirl/gitbucket/core/helper/commitcomment.scala.html b/src/main/twirl/gitbucket/core/helper/commitcomment.scala.html index bc5c53138..b35c6d36e 100644 --- a/src/main/twirl/gitbucket/core/helper/commitcomment.scala.html +++ b/src/main/twirl/gitbucket/core/helper/commitcomment.scala.html @@ -15,9 +15,9 @@ @user(comment.commentedUserName, styleClass="username strong") commented - @if(comment.pullRequest){ + @if(comment.issueId.isDefined){ on this Pull Request - }else{ + } else { @if(comment.fileName.isDefined){ on @comment.fileName.get }