diff --git a/src/main/scala/gitbucket/core/controller/api/ApiIssueCommentControllerBase.scala b/src/main/scala/gitbucket/core/controller/api/ApiIssueCommentControllerBase.scala index 89d8033..574d16e 100644 --- a/src/main/scala/gitbucket/core/controller/api/ApiIssueCommentControllerBase.scala +++ b/src/main/scala/gitbucket/core/controller/api/ApiIssueCommentControllerBase.scala @@ -35,9 +35,19 @@ */ /* - * iii. Get a single comment - * https://developer.github.com/v3/issues/comments/#get-a-single-comment + * iii. Get an issue comment + * https://docs.github.com/en/rest/reference/issues#get-an-issue-comment */ + get("/api/v3/repos/:owner/:repository/issues/comments/:id")(referrersOnly { repository => + val commentId = params("id").toInt + getCommentForApi(repository.owner, repository.name, commentId) match { + case Some((issueComment, user, issue)) => + JsonFormat( + ApiComment(issueComment, RepositoryName(repository), issue.issueId, ApiUser(user), issue.isPullRequest) + ) + case _ => NotFound() + } + }) /* * iv. Create a comment diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index e38ad79..a728055 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -71,6 +71,20 @@ else None } + def getCommentForApi(owner: String, repository: String, commentId: Int)( + implicit s: Session + ): Option[(IssueComment, Account, Issue)] = + IssueComments + .filter(_.byRepository(owner, repository)) + .filter(_.commentId === commentId) + .filter(_.action inSetBind Set("comment", "close_comment", "reopen_comment")) + .join(Accounts) + .on { case t1 ~ t2 => t1.commentedUserName === t2.userName } + .join(Issues) + .on { case t1 ~ t2 ~ t3 => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) } + .map { case t1 ~ t2 ~ t3 => (t1, t2, t3) } + .firstOption + def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session): List[Label] = { IssueLabels .join(Labels)