mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 06:25:51 +01:00
Add update-an-issue-comment API (#2538)
This commit is contained in:
@@ -75,9 +75,40 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/*
|
||||
* v. Edit a comment
|
||||
* https://developer.github.com/v3/issues/comments/#edit-a-comment
|
||||
* v. Update an issue comment
|
||||
* https://docs.github.com/en/rest/reference/issues#update-an-issue-comment
|
||||
*/
|
||||
patch("/api/v3/repos/:owner/:repository/issues/comments/:id")(readableUsersOnly { repository =>
|
||||
val commentId = params("id")
|
||||
val result = for {
|
||||
issueComment <- getComment(repository.owner, repository.name, commentId)
|
||||
issue <- getIssue(repository.owner, repository.name, issueComment.issueId.toString)
|
||||
} yield {
|
||||
if (isEditable(repository.owner, repository.name, issueComment.commentedUserName)) {
|
||||
val body = extractFromJsonBody[CreateAComment].map(_.body)
|
||||
updateCommentByApi(repository, issue, issueComment.commentId.toString, body)
|
||||
getComment(repository.owner, repository.name, commentId) match {
|
||||
case Some(issueComment) =>
|
||||
JsonFormat(
|
||||
ApiComment(
|
||||
issueComment,
|
||||
RepositoryName(repository),
|
||||
issue.issueId,
|
||||
ApiUser(context.loginAccount.get),
|
||||
issue.isPullRequest
|
||||
)
|
||||
)
|
||||
case _ =>
|
||||
}
|
||||
} else {
|
||||
Unauthorized()
|
||||
}
|
||||
}
|
||||
result match {
|
||||
case Some(response) => response
|
||||
case None => NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
* vi. Delete a comment
|
||||
|
||||
@@ -13,6 +13,10 @@ trait IssueHook {
|
||||
implicit session: Session,
|
||||
context: Context
|
||||
): Unit = ()
|
||||
def updatedComment(commentId: Int, content: String, issue: Issue, repository: RepositoryInfo)(
|
||||
implicit session: Session,
|
||||
context: Context
|
||||
): Unit = ()
|
||||
def closed(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
||||
def reopened(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
||||
def assigned(
|
||||
|
||||
@@ -134,4 +134,42 @@ trait HandleCommentService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def updateCommentByApi(
|
||||
repository: RepositoryService.RepositoryInfo,
|
||||
issue: Issue,
|
||||
commentId: String,
|
||||
content: Option[String]
|
||||
)(implicit context: Context, s: Session): Option[(Issue, Int)] = {
|
||||
context.loginAccount.flatMap { loginAccount =>
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
val userName = loginAccount.userName
|
||||
content match {
|
||||
case Some(content) =>
|
||||
// Update comment
|
||||
val _commentId = Some(updateComment(issue.issueId, commentId.toInt, content))
|
||||
// Record comment activity
|
||||
val commentInfo = if (issue.isPullRequest) {
|
||||
PullRequestCommentInfo(owner, name, userName, content, issue.issueId)
|
||||
} else {
|
||||
IssueCommentInfo(owner, name, userName, content, issue.issueId)
|
||||
}
|
||||
recordActivity(commentInfo)
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, content, loginAccount)
|
||||
// call web hooks
|
||||
commentId foreach (callIssueCommentWebHook(repository, issue, _, loginAccount, context.settings))
|
||||
// call hooks
|
||||
if (issue.isPullRequest)
|
||||
PluginRegistry().getPullRequestHooks
|
||||
.foreach(_.updatedComment(commentId.toInt, content, issue, repository))
|
||||
else
|
||||
PluginRegistry().getIssueHooks.foreach(_.updatedComment(commentId.toInt, content, issue, repository))
|
||||
_commentId.map(issue -> _)
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user