diff --git a/src/main/resources/update/2_7.sql b/src/main/resources/update/2_7.sql index 0b2c86c..89a7df9 100644 --- a/src/main/resources/update/2_7.sql +++ b/src/main/resources/update/2_7.sql @@ -9,7 +9,8 @@ OLD_LINE_NUMBER INT, NEW_LINE_NUMBER INT, REGISTERED_DATE TIMESTAMP NOT NULL, - UPDATED_DATE TIMESTAMP NOT NULL + UPDATED_DATE TIMESTAMP NOT NULL, + IS_IN_PR BOOLEAN NOT NULL ); ALTER TABLE COMMIT_COMMENT ADD CONSTRAINT IDX_COMMIT_COMMENT_PK PRIMARY KEY (COMMENT_ID); diff --git a/src/main/scala/app/PullRequestsController.scala b/src/main/scala/app/PullRequestsController.scala index 78307e7..23ed289 100644 --- a/src/main/scala/app/PullRequestsController.scala +++ b/src/main/scala/app/PullRequestsController.scala @@ -79,7 +79,7 @@ pulls.html.pullreq( issue, pullreq, - (commits.flatten.map(commit => getCommitComments(owner, name, commit.id)).flatten.toList ::: getComments(owner, name, issueId)) + (commits.flatten.map(commit => getCommitComments(owner, name, commit.id, true)).flatten.toList ::: getComments(owner, name, issueId)) .sortWith((a, b) => a.registeredDate before b.registeredDate), getIssueLabels(owner, name, issueId), (getCollaborators(owner, name) ::: (if(getAccountByUserName(owner).get.isGroupAccount) Nil else List(owner))).sorted, @@ -280,7 +280,7 @@ case (Some(userName), Some(repositoryName)) => (userName, repositoryName) :: getForkedRepositories(userName, repositoryName) case _ => (forkedRepository.owner, forkedRepository.name) :: getForkedRepositories(forkedRepository.owner, forkedRepository.name) }, - commits.flatten.map(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id)).flatten.toList, + commits.flatten.map(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false)).flatten.toList, originBranch, forkedBranch, oldId.getName, diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 02c2240..b4dab83 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -56,7 +56,8 @@ fileName: Option[String], oldLineNumber: Option[Int], newLineNumber: Option[Int], - content: String + content: String, + isInPR: Boolean ) val editorForm = mapping( @@ -81,7 +82,8 @@ "fileName" -> trim(label("Filename", optional(text()))), "oldLineNumber" -> trim(label("Old line number", optional(number()))), "newLineNumber" -> trim(label("New line number", optional(number()))), - "content" -> trim(label("Content", text(required))) + "content" -> trim(label("Content", text(required))), + "isInPR" -> trim(label("Is in PR", boolean())) )(CommentForm.apply) /** @@ -235,7 +237,7 @@ repo.html.commit(id, new JGitUtil.CommitInfo(revCommit), JGitUtil.getBranchesOfCommit(git, revCommit.getName), JGitUtil.getTagsOfCommit(git, revCommit.getName), - getCommitComments(repository.owner, repository.name, id), + getCommitComments(repository.owner, repository.name, id, false), repository, diffs, oldCommitId, hasWritePermission(repository.owner, repository.name, context.loginAccount)) } } @@ -245,7 +247,7 @@ 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.fileName, form.oldLineNumber, form.newLineNumber, form.isInPR) recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content) redirect(s"/${repository.owner}/${repository.name}/commit/${id}") }) @@ -255,9 +257,10 @@ val fileName = params.get("fileName") val oldLineNumber = params.get("oldLineNumber") flatMap {b => Some(b.toInt)} val newLineNumber = params.get("newLineNumber") flatMap {b => Some(b.toInt)} + val isInPR = params.get("isInPR") repo.html.commentform( commitId = id, - fileName, oldLineNumber, newLineNumber, + fileName, oldLineNumber, newLineNumber, isInPR.map(_.toBoolean).getOrElse(false), hasWritePermission = hasWritePermission(repository.owner, repository.name, context.loginAccount), repository = repository ) @@ -266,7 +269,7 @@ 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.content, form.fileName, form.oldLineNumber, form.newLineNumber, form.isInPR) recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content) helper.html.commitcomment(getCommitComment(repository.owner, repository.name, commentId.toString).get, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository) diff --git a/src/main/scala/model/Comment.scala b/src/main/scala/model/Comment.scala index 51be46d..66146d0 100644 --- a/src/main/scala/model/Comment.scala +++ b/src/main/scala/model/Comment.scala @@ -55,7 +55,8 @@ val newLine = column[Option[Int]]("NEW_LINE_NUMBER") val registeredDate = column[java.util.Date]("REGISTERED_DATE") val updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate) <> (CommitComment.tupled, CommitComment.unapply) + val isInPR = column[Boolean]("IS_IN_PR") + def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, isInPR) <> (CommitComment.tupled, CommitComment.unapply) def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind } @@ -72,5 +73,6 @@ oldLine: Option[Int], newLine: Option[Int], registeredDate: java.util.Date, - updatedDate: java.util.Date + updatedDate: java.util.Date, + isInPR: Boolean ) extends Comment diff --git a/src/main/scala/service/CommitsService.scala b/src/main/scala/service/CommitsService.scala index c80d8c0..60d8645 100644 --- a/src/main/scala/service/CommitsService.scala +++ b/src/main/scala/service/CommitsService.scala @@ -12,8 +12,10 @@ trait CommitsService { - def getCommitComments(owner: String, repository: String, commitId: String)(implicit s: Session) = - CommitComments filter (_.byCommit(owner, repository, commitId)) list + def getCommitComments(owner: String, repository: String, commitId: String, isInPR: Boolean)(implicit s: Session) = + CommitComments filter { + t => t.byCommit(owner, repository, commitId) && (t.isInPR === isInPR || isInPR) + } list def getCommitComment(owner: String, repository: String, commentId: String)(implicit s: Session) = if (commentId forall (_.isDigit)) @@ -24,7 +26,7 @@ None def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String, - content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int])(implicit s: Session): Int = + content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], isInPR: Boolean)(implicit s: Session): Int = CommitComments.autoInc insert CommitComment( userName = owner, repositoryName = repository, @@ -35,7 +37,8 @@ oldLine = oldLine, newLine = newLine, registeredDate = currentDate, - updatedDate = currentDate) + updatedDate = currentDate, + isInPR = isInPR) def updateCommitComment(commentId: Int, content: String)(implicit s: Session) = CommitComments diff --git a/src/main/twirl/helper/commitcomment.scala.html b/src/main/twirl/helper/commitcomment.scala.html index 519b10d..81c5b82 100644 --- a/src/main/twirl/helper/commitcomment.scala.html +++ b/src/main/twirl/helper/commitcomment.scala.html @@ -1,19 +1,24 @@ @(comment: model.CommitComment, hasWritePermission: Boolean, -repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) +repository: service.RepositoryService.RepositoryInfo, +latestCommitId: Option[String] = None)(implicit context: app.Context) @import context._ @import view.helpers._ -