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)={
@@ -233,9 +232,14 @@ } } } - case comments: CommitComments => { + case comments: gitbucket.core.model.CommitComments => { @gitbucket.core.helper.html.commitcomments(comments, isManageable, repository, pullreq.map(_.commitIdTo)) } + case comment: gitbucket.core.model.CommitComment => { + @gitbucket.core.helper.html.commitcomments(gitbucket.core.model.CommitComments( + comment.fileName.getOrElse(""), comment.commentedUserName, comment.registeredDate, Seq(comment) + ), isManageable, repository, pullreq.map(_.commitIdTo)) + } } + +} diff --git a/src/main/twirl/gitbucket/core/pulls/files.scala.html b/src/main/twirl/gitbucket/core/pulls/files.scala.html new file mode 100644 index 0000000..f895c20 --- /dev/null +++ b/src/main/twirl/gitbucket/core/pulls/files.scala.html @@ -0,0 +1,19 @@ +@(issue: gitbucket.core.model.Issue, + pullreq: gitbucket.core.model.PullRequest, + diffs: Seq[gitbucket.core.util.JGitUtil.DiffInfo], + commits: Seq[gitbucket.core.util.JGitUtil.CommitInfo], + comments: Seq[gitbucket.core.model.Comment], + isManageable: Boolean, + repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context) +@gitbucket.core.pulls.html.menu("files", issue, pullreq, commits, comments, isManageable, repository) { + @gitbucket.core.helper.html.diff( + diffs, + repository, + commits.headOption.map(_.id), + commits.lastOption.map(_.id), + true, + Some(pullreq.issueId), + isManageable, + true + ) +} diff --git a/src/main/twirl/gitbucket/core/pulls/menu.scala.html b/src/main/twirl/gitbucket/core/pulls/menu.scala.html new file mode 100644 index 0000000..9d475d9 --- /dev/null +++ b/src/main/twirl/gitbucket/core/pulls/menu.scala.html @@ -0,0 +1,99 @@ +@(active: String, + issue: gitbucket.core.model.Issue, + pullreq: gitbucket.core.model.PullRequest, + commits: Seq[gitbucket.core.util.JGitUtil.CommitInfo], + comments: Seq[gitbucket.core.model.Comment], + isManageable: Boolean, + repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(body: => Html)(implicit context: gitbucket.core.controller.Context) +@import gitbucket.core.view.helpers +@import gitbucket.core.model.IssueComment +@gitbucket.core.html.main(s"${issue.title} - Pull request #${issue.issueId} - ${repository.owner}/${repository.name}", Some(repository)) { + @gitbucket.core.html.menu("pulls", repository) { +
+
+ @if(isManageable || context.loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)) { + Edit + } + @if(context.loginAccount.isDefined) { + New pull request + } +
+ +

+ + @issue.title + #@issue.issueId + + +

+
+
+ @if(issue.closed) { + @comments.flatMap @{ + case comment: IssueComment => Some(comment) + case _ => None + }.find(_.action == "merge").map { comment => + Merged + + @helpers.user(comment.commentedUserName, styleClass = "username strong") + merged @commits.size @helpers.plural(commits.size, "commit") + into @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 + + } +
+ +
+ @body + @* +
+ @flash.get("error").map { error => +
@error
+ } + @flash.get("info").map { info => +
@info
+ } + @gitbucket.core.pulls.html.conversation(issue, pullreq, commits, comments, issueLabels, collaborators, milestones, priorities, labels, isEditable, isManageable, isManageableForkedRepository, repository, forkedRepository) +
+
+ @if(commits.nonEmpty) { + @gitbucket.core.pulls.html.commits(dayByDayCommits, repository) + } +
+
+ @if(commits.nonEmpty) { + @gitbucket.core.helper.html.diff(diffs, repository, commits.headOption.map(_.id), commits.lastOption.map(_.id), true, Some(pullreq.issueId), isManageable, true) + } +
+ *@ +
+ } +} diff --git a/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html b/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html index ca54ed8..93f9fbf 100644 --- a/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/pullreq.scala.html @@ -17,6 +17,7 @@ @import gitbucket.core.view.helpers @import gitbucket.core.model.IssueComment @import gitbucket.core.model.CommitComment +@* @gitbucket.core.html.main(s"${issue.title} - Pull request #${issue.issueId} - ${repository.owner}/${repository.name}", Some(repository)){ @gitbucket.core.html.menu("pulls", repository){ @defining(dayByDayCommits.flatten){ commits => @@ -157,3 +158,4 @@ }); }); +*@ diff --git a/src/main/twirl/gitbucket/core/repo/commentform.scala.html b/src/main/twirl/gitbucket/core/repo/commentform.scala.html index a681862..d8e69e7 100644 --- a/src/main/twirl/gitbucket/core/repo/commentform.scala.html +++ b/src/main/twirl/gitbucket/core/repo/commentform.scala.html @@ -85,10 +85,10 @@ $tr.after(tmp); } - $('#comment-list').append(data); - if (typeof $('#show-notes')[0] !== 'undefined' && !$('#show-notes')[0].checked) { - $('#comment-list').children('.inline-comment').hide(); - } + // $('#comment-list').append(data); + // if (typeof $('#show-notes')[0] !== 'undefined' && !$('#show-notes')[0].checked) { + // $('#comment-list').children('.inline-comment').hide(); + // } }).fail(function(req) { $('.btn-inline-comment').removeAttr('disabled'); $('#error-content', $form).html($.parseJSON(req.responseText).content);