diff --git a/src/main/scala/gitbucket/core/view/helpers.scala b/src/main/scala/gitbucket/core/view/helpers.scala index c5f1a40..848981a 100644 --- a/src/main/scala/gitbucket/core/view/helpers.scala +++ b/src/main/scala/gitbucket/core/view/helpers.scala @@ -3,6 +3,7 @@ import java.text.SimpleDateFormat import java.util.{Date, Locale, TimeZone} +import com.nimbusds.jose.util.JSONObjectUtils import gitbucket.core.controller.Context import gitbucket.core.model.CommitState import gitbucket.core.plugin.{PluginRegistry, RenderRequest} @@ -462,4 +463,44 @@ */ def readableSize(size: Option[Long]): String = FileUtil.readableSize(size.getOrElse(0)) + /** + * Make HTML fragment of the partial diff for a comment on a line of diff. + * + * @param jsonString JSON string which is stored in COMMIT_COMMENT table. + * @return HTML fragment of diff + */ + def diff(jsonString: String): Html = { + import org.json4s._ + import org.json4s.jackson.JsonMethods._ + implicit val formats = DefaultFormats + + val diff = parse(jsonString).extract[Seq[CommentDiffLine]] + + val sb = new StringBuilder() + sb.append("") + diff.foreach { line => + sb.append("") + sb.append(s"""") + sb.append(s"""") + + sb.append(s"""") + sb.append("") + } + sb.append("
""") + line.oldLine.foreach { oldLine => + sb.append(oldLine) + } + sb.append("""") + line.newLine.foreach { newLine => + sb.append(newLine) + } + sb.append("""") + sb.append(StringUtil.escapeHtml(line.text)) + sb.append("
") + + Html(sb.toString()) + } + + case class CommentDiffLine(newLine: Option[String], oldLine: Option[String], `type`: String, text: String) + } diff --git a/src/main/twirl/gitbucket/core/helper/commitcomments.scala.html b/src/main/twirl/gitbucket/core/helper/commitcomments.scala.html index 41e9aff..60f7b81 100644 --- a/src/main/twirl/gitbucket/core/helper/commitcomments.scala.html +++ b/src/main/twirl/gitbucket/core/helper/commitcomments.scala.html @@ -10,6 +10,11 @@ @comments.comments.head.commitId.substring(0, 7) + @comments.comments.headOption.map { comment => + @comment.diff.map { diff => + @helpers.diff(diff) + } + }
@comments.comments.map { comment => @gitbucket.core.helper.html.commitcomment(comment, hasWritePermission, repository, latestCommitId) diff --git a/src/main/twirl/gitbucket/core/pulls/conversation.scala.html b/src/main/twirl/gitbucket/core/pulls/conversation.scala.html index 254a5f3..a30834c 100644 --- a/src/main/twirl/gitbucket/core/pulls/conversation.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/conversation.scala.html @@ -15,6 +15,7 @@ flash: Map[String, String])(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers @gitbucket.core.pulls.html.menu("conversation", issue, pullreq, commits, comments, isManageable, repository, flash){ +
@gitbucket.core.issues.html.commentlist(Some(issue), comments.toList, isManageable, repository, Some(pullreq))