Add get-an-issue-comment API endpoint (#2536)

This commit is contained in:
onukura
2020-09-05 23:23:16 +09:00
committed by GitHub
parent 7544f64c65
commit 8dbcbb5485
2 changed files with 26 additions and 2 deletions

View File

@@ -35,9 +35,19 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
*/
/*
* 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

View File

@@ -71,6 +71,20 @@ trait IssuesService {
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)