mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-12-24 17:29:55 +01:00
Add get-an-issue-comment API endpoint (#2536)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user