From f1db6e3c7c3e31c83f3630a072adfcad64a40cc3 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Thu, 19 Apr 2018 13:05:25 +0900 Subject: [PATCH] Grouping commit comments --- .../controller/PullRequestsController.scala | 22 +++++++++++++------ .../scala/gitbucket/core/model/Comment.scala | 8 +++++++ .../gitbucket/core/pulls/commits.scala.html | 1 - .../gitbucket/core/pulls/pullreq.scala.html | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index 936982af6..a10ec81d6 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -1,6 +1,6 @@ package gitbucket.core.controller -import gitbucket.core.model.{CommitComment, IssueComment, WebHook} +import gitbucket.core.model.{CommitComment, CommitComments, IssueComment, WebHook} import gitbucket.core.plugin.PluginRegistry import gitbucket.core.pulls.html import gitbucket.core.service.CommitStatusService @@ -123,14 +123,22 @@ trait PullRequestsControllerBase extends ControllerBase { .flatten .toList ::: getComments(owner, name, issueId)) .groupBy { - case x: IssueComment => (None, None, None) - case x: CommitComment => (x.fileName, x.oldLine, x.newLine) + case x: IssueComment => (Some(x.commentId), None, None, None) + case x: CommitComment => (None, x.fileName, x.oldLine, x.newLine) } - .toSeq - .sortWith { - case ((key1, comments1), (key2, comments2)) => - comments1.head.registeredDate before comments2.head.registeredDate + .toList + .map { + case ((Some(_), _, _, _), comments) => + comments.head + case ((None, Some(fileName), _, _), comments) => + CommitComments( + fileName = fileName, + commentedUserName = comments.head.commentedUserName, + registeredDate = comments.head.registeredDate, + comments = comments.map(_.asInstanceOf[CommitComment]) + ) } + .sortWith(_.registeredDate before _.registeredDate) html.pullreq( issue, diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index 8f79a5217..b356a1e06 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -1,4 +1,5 @@ package gitbucket.core.model +import java.util.Date trait Comment { val commentedUserName: String @@ -87,3 +88,10 @@ case class CommitComment( updatedDate: java.util.Date, issueId: Option[Int] ) extends Comment + +case class CommitComments( + fileName: String, + commentedUserName: String, + registeredDate: Date, + comments: Seq[CommitComment] +) extends Comment diff --git a/src/main/twirl/gitbucket/core/pulls/commits.scala.html b/src/main/twirl/gitbucket/core/pulls/commits.scala.html index 7138fc84d..bb6532380 100644 --- a/src/main/twirl/gitbucket/core/pulls/commits.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/commits.scala.html @@ -1,5 +1,4 @@ @(commits: Seq[Seq[gitbucket.core.util.JGitUtil.CommitInfo]], - comments: Option[List[gitbucket.core.model.Comment]] = None, repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers diff --git a/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html b/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html index 604b0d2d5..d1a2203df 100644 --- a/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html @@ -90,7 +90,7 @@
@if(commits.nonEmpty){ - @gitbucket.core.pulls.html.commits(dayByDayCommits, Some(comments), repository) + @gitbucket.core.pulls.html.commits(dayByDayCommits, repository) }