diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index a10ec81..7c49a6a 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -113,52 +113,91 @@ val name = repository.name getPullRequest(owner, name, issueId) map { case (issue, pullreq) => - using(Git.open(getRepositoryDir(owner, name))) { - git => - val (commits, diffs) = - getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo) + val (commits, _) = + getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo) - val comments = (commits.flatten - .map(commit => getCommitComments(owner, name, commit.id, true)) - .flatten - .toList ::: getComments(owner, name, issueId)) - .groupBy { - case x: IssueComment => (Some(x.commentId), None, None, None) - case x: CommitComment => (None, x.fileName, x.oldLine, x.newLine) - } - .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.conversation( + issue, + pullreq, + commits.flatten, + getPullRequestComments(owner, name, issue.issueId, commits.flatten), + getIssueLabels(owner, name, issueId), + getAssignableUserNames(owner, name), + getMilestonesWithIssueCount(owner, name), + getPriorities(owner, name), + getLabels(owner, name), + //commits, + //diffs, + isEditable(repository), + isManageable(repository), + hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount), + repository, + getRepository(pullreq.requestUserName, pullreq.requestRepositoryName) + //flash.toMap.map(f => f._1 -> f._2.toString) + ) - html.pullreq( - issue, - pullreq, - comments, - getIssueLabels(owner, name, issueId), - getAssignableUserNames(owner, name), - getMilestonesWithIssueCount(owner, name), - getPriorities(owner, name), - getLabels(owner, name), - commits, - diffs, - isEditable(repository), - isManageable(repository), - hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount), - repository, - getRepository(pullreq.requestUserName, pullreq.requestRepositoryName), - flash.toMap.map(f => f._1 -> f._2.toString) - ) - } +// html.pullreq( +// issue, +// pullreq, +// comments, +// getIssueLabels(owner, name, issueId), +// getAssignableUserNames(owner, name), +// getMilestonesWithIssueCount(owner, name), +// getPriorities(owner, name), +// getLabels(owner, name), +// commits, +// diffs, +// isEditable(repository), +// isManageable(repository), +// hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount), +// repository, +// getRepository(pullreq.requestUserName, pullreq.requestRepositoryName), +// flash.toMap.map(f => f._1 -> f._2.toString) +// ) + } + } getOrElse NotFound() + }) + + get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository => + params("id").toIntOpt.flatMap { issueId => + val owner = repository.owner + val name = repository.name + getPullRequest(owner, name, issueId) map { + case (issue, pullreq) => + val (commits, _) = + getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo) + + html.commits( + issue, + pullreq, + commits, + getPullRequestComments(owner, name, issue.issueId, commits.flatten), + isManageable(repository), + repository + ) + } + } getOrElse NotFound() + }) + + get("/:owner/:repository/pull/:id/files")(referrersOnly { repository => + params("id").toIntOpt.flatMap { + issueId => + val owner = repository.owner + val name = repository.name + getPullRequest(owner, name, issueId) map { + case (issue, pullreq) => + val (commits, diffs) = + getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo) + + html.files( + issue, + pullreq, + diffs, + commits.flatten, + getPullRequestComments(owner, name, issue.issueId, commits.flatten), + isManageable(repository), + repository + ) } } getOrElse NotFound() }) diff --git a/src/main/scala/gitbucket/core/model/Comment.scala b/src/main/scala/gitbucket/core/model/Comment.scala index b356a1e..328d645 100644 --- a/src/main/scala/gitbucket/core/model/Comment.scala +++ b/src/main/scala/gitbucket/core/model/Comment.scala @@ -1,7 +1,7 @@ package gitbucket.core.model import java.util.Date -trait Comment { +sealed trait Comment { val commentedUserName: String val registeredDate: java.util.Date } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index ddcb345..0f33989 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -1,6 +1,6 @@ package gitbucket.core.service -import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState, CommitComment} +import gitbucket.core.model.{CommitComments => _, Session => _, _} import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import difflib.{Delta, DiffUtils} @@ -12,6 +12,7 @@ import gitbucket.core.view import gitbucket.core.view.helpers import org.eclipse.jgit.api.Git + import scala.collection.JavaConverters._ trait PullRequestService { self: IssuesService with CommitsService => @@ -314,11 +315,38 @@ helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime) } + // TODO Isolate to an another method? val diffs = JGitUtil.getDiffs(newGit, Some(oldId.getName), newId.getName, true, false) (commits, diffs) } + def getPullRequestComments(userName: String, repositoryName: String, issueId: Int, commits: Seq[CommitInfo])( + implicit s: Session + ): Seq[Comment] = { + (commits + .map(commit => getCommitComments(userName, repositoryName, commit.id, true)) + .flatten ++ getComments(userName, repositoryName, issueId)) + .groupBy { + case x: IssueComment => (Some(x.commentId), None, None, None) + case x: CommitComment => (None, x.fileName, x.oldLine, x.newLine) + case x => throw new MatchError(x) + } + .toSeq + .map { + case ((Some(_), _, _, _), comments) => + comments.head + case ((None, Some(fileName), _, _), comments) => + gitbucket.core.model.CommitComments( + fileName = fileName, + commentedUserName = comments.head.commentedUserName, + registeredDate = comments.head.registeredDate, + comments = comments.map(_.asInstanceOf[CommitComment]) + ) + } + .sortWith(_.registeredDate before _.registeredDate) + } + } object PullRequestService { diff --git a/src/main/twirl/gitbucket/core/issues/commentlist.scala.html b/src/main/twirl/gitbucket/core/issues/commentlist.scala.html index 442bade..684efdf 100644 --- a/src/main/twirl/gitbucket/core/issues/commentlist.scala.html +++ b/src/main/twirl/gitbucket/core/issues/commentlist.scala.html @@ -4,7 +4,6 @@ repository: gitbucket.core.service.RepositoryService.RepositoryInfo, pullreq: Option[gitbucket.core.model.PullRequest] = None)(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers -@import gitbucket.core.model.CommitComments @issueOrPullRequest()={ @if(issue.exists(_.isPullRequest))( "pull request" )else( "issue" ) } @showFormattedComment(comment: gitbucket.core.model.IssueComment)={
+ + @issue.title + #@issue.issueId + + + + + +
+@pullreq.userName:@pullreq.branch
from@pullreq.requestUserName + :@pullreq.requestBranch
+ @gitbucket.core.helper.html.datetimeago(comment.registeredDate) + + }.getOrElse { + Closed + + @helpers.user(issue.openedUserName, styleClass = "username strong") + wants to merge @commits.size @helpers.plural(commits.size, "commit") + into@pullreq.userName:@pullreq.branch
from@pullreq.requestUserName + :@pullreq.requestBranch
+ + } + } else { + Open + + @helpers.user(issue.openedUserName, styleClass = "username strong") + wants to merge @commits.size @helpers.plural(commits.size, "commit") + into@pullreq.userName:@pullreq.branch
from@pullreq.requestUserName + :@pullreq.requestBranch
+ + } ++- Conversation
+ - Commits
+ - Files Changed
+
+