mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
fix pull-request url on webhook payload
This commit is contained in:
@@ -14,16 +14,16 @@ case class ApiComment(
|
|||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
body: String,
|
body: String,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
updated_at: Date)(repositoryName: RepositoryName, issueId: Int){
|
updated_at: Date)(repositoryName: RepositoryName, issueId: Int, issueOrPullRequest: IssueOrPullRequest){
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/issues/${issueId}#comment-${id}")
|
val html_url = ApiPath(s"/${repositoryName.fullName}/${issueOrPullRequest.html}/${issueId}#comment-${id}")
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApiComment{
|
object ApiComment{
|
||||||
def apply(comment: IssueComment, repositoryName: RepositoryName, issueId: Int, user: ApiUser): ApiComment =
|
def apply(comment: IssueComment, repositoryName: RepositoryName, issueId: Int, user: ApiUser, isPullRequest: Boolean): ApiComment =
|
||||||
ApiComment(
|
ApiComment(
|
||||||
id = comment.commentId,
|
id = comment.commentId,
|
||||||
user = user,
|
user = user,
|
||||||
body = comment.content,
|
body = comment.content,
|
||||||
created_at = comment.registeredDate,
|
created_at = comment.registeredDate,
|
||||||
updated_at = comment.updatedDate)(repositoryName, issueId)
|
updated_at = comment.updatedDate)(repositoryName, issueId, IssueOrPullRequest(isPullRequest))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ case class ApiIssue(
|
|||||||
state: String,
|
state: String,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
updated_at: Date,
|
updated_at: Date,
|
||||||
body: String)(repositoryName: RepositoryName){
|
body: String)(repositoryName: RepositoryName, issueOrPullRequest: IssueOrPullRequest){
|
||||||
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/${issueOrPullRequest.api}/${number}/comments")
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/issues/${number}")
|
val html_url = ApiPath(s"/${repositoryName.fullName}/${issueOrPullRequest.html}/${number}")
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApiIssue{
|
object ApiIssue{
|
||||||
@@ -31,5 +31,5 @@ object ApiIssue{
|
|||||||
state = if(issue.closed){ "closed" }else{ "open" },
|
state = if(issue.closed){ "closed" }else{ "open" },
|
||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
created_at = issue.registeredDate,
|
created_at = issue.registeredDate,
|
||||||
updated_at = issue.updatedDate)(repositoryName)
|
updated_at = issue.updatedDate)(repositoryName, IssueOrPullRequest(issue.isPullRequest))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
case class IssueOrPullRequest(isPullRequest:Boolean){
|
||||||
|
val (html, api) = if(isPullRequest){ ("pull","pulls") }else{ ("issues","issues") }
|
||||||
|
}
|
||||||
@@ -86,7 +86,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
comments = getCommentsForApi(repository.owner, repository.name, issueId.toInt)
|
comments = getCommentsForApi(repository.owner, repository.name, issueId.toInt)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(comments.map{ case (issueComment, user) => ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user)) })
|
JsonFormat(comments.map{ case (issueComment, user, issue) => ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user), issue.isPullRequest) })
|
||||||
}).getOrElse(NotFound)
|
}).getOrElse(NotFound)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
(issue, id) <- handleComment(issueId, Some(body), repository)()
|
(issue, id) <- handleComment(issueId, Some(body), repository)()
|
||||||
issueComment <- getComment(repository.owner, repository.name, id.toString())
|
issueComment <- getComment(repository.owner, repository.name, id.toString())
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(context.loginAccount.get)))
|
JsonFormat(ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(context.loginAccount.get), issue.isPullRequest))
|
||||||
}) getOrElse NotFound
|
}) getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ trait IssuesService {
|
|||||||
def getComments(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
def getComments(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||||
IssueComments filter (_.byIssue(owner, repository, issueId)) list
|
IssueComments filter (_.byIssue(owner, repository, issueId)) list
|
||||||
|
|
||||||
/** @return IssueComment and commentedUser */
|
/** @return IssueComment and commentedUser and Issue */
|
||||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account)] =
|
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] =
|
||||||
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
||||||
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
||||||
.innerJoin(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
.innerJoin(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
||||||
|
.innerJoin(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) }
|
||||||
|
.map{ case ((t1, t2), t3) => (t1, t2, t3) }
|
||||||
.list
|
.list
|
||||||
|
|
||||||
def getComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
def getComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ object WebHookService {
|
|||||||
action = "created",
|
action = "created",
|
||||||
repository = ApiRepository(repository, repositoryUser),
|
repository = ApiRepository(repository, repositoryUser),
|
||||||
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
||||||
comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser)),
|
comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser), issue.isPullRequest),
|
||||||
sender = ApiUser(sender))
|
sender = ApiUser(sender))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class JsonFormatSpec extends Specification {
|
|||||||
user = apiUser,
|
user = apiUser,
|
||||||
body= "Me too",
|
body= "Me too",
|
||||||
created_at= date1,
|
created_at= date1,
|
||||||
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100)
|
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100, IssueOrPullRequest(false))
|
||||||
val apiCommentJson = s"""{
|
val apiCommentJson = s"""{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"body": "Me too",
|
"body": "Me too",
|
||||||
@@ -100,6 +100,21 @@ class JsonFormatSpec extends Specification {
|
|||||||
"updated_at": "2011-04-14T16:00:49Z"
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
val apiCommentPR = ApiComment(
|
||||||
|
id =1,
|
||||||
|
user = apiUser,
|
||||||
|
body= "Me too",
|
||||||
|
created_at= date1,
|
||||||
|
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100, IssueOrPullRequest(true))
|
||||||
|
val apiCommentPRJson = s"""{
|
||||||
|
"id": 1,
|
||||||
|
"body": "Me too",
|
||||||
|
"user": $apiUserJson,
|
||||||
|
"html_url" : "${context.baseUrl}/octocat/Hello-World/pull/100#comment-1",
|
||||||
|
"created_at": "2011-04-14T16:00:49Z",
|
||||||
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
|
}"""
|
||||||
|
|
||||||
val apiPersonIdent = ApiPersonIdent("Monalisa Octocat","support@example.com",date1)
|
val apiPersonIdent = ApiPersonIdent("Monalisa Octocat","support@example.com",date1)
|
||||||
val apiPersonIdentJson = """ {
|
val apiPersonIdentJson = """ {
|
||||||
"name": "Monalisa Octocat",
|
"name": "Monalisa Octocat",
|
||||||
@@ -158,7 +173,7 @@ class JsonFormatSpec extends Specification {
|
|||||||
state = "open",
|
state = "open",
|
||||||
body = "I'm having a problem with this.",
|
body = "I'm having a problem with this.",
|
||||||
created_at = date1,
|
created_at = date1,
|
||||||
updated_at = date1)(RepositoryName("octocat","Hello-World"))
|
updated_at = date1)(RepositoryName("octocat","Hello-World"), IssueOrPullRequest(false))
|
||||||
val apiIssueJson = s"""{
|
val apiIssueJson = s"""{
|
||||||
"number": 1347,
|
"number": 1347,
|
||||||
"state": "open",
|
"state": "open",
|
||||||
@@ -171,6 +186,26 @@ class JsonFormatSpec extends Specification {
|
|||||||
"updated_at": "2011-04-14T16:00:49Z"
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
val apiIssuePR = ApiIssue(
|
||||||
|
number = 1347,
|
||||||
|
title = "Found a bug",
|
||||||
|
user = apiUser,
|
||||||
|
state = "open",
|
||||||
|
body = "I'm having a problem with this.",
|
||||||
|
created_at = date1,
|
||||||
|
updated_at = date1)(RepositoryName("octocat","Hello-World"), IssueOrPullRequest(true))
|
||||||
|
val apiIssuePRJson = s"""{
|
||||||
|
"number": 1347,
|
||||||
|
"state": "open",
|
||||||
|
"title": "Found a bug",
|
||||||
|
"body": "I'm having a problem with this.",
|
||||||
|
"user": $apiUserJson,
|
||||||
|
"comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/pulls/1347/comments",
|
||||||
|
"html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347",
|
||||||
|
"created_at": "2011-04-14T16:00:49Z",
|
||||||
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
|
}"""
|
||||||
|
|
||||||
val apiPullRequest = ApiPullRequest(
|
val apiPullRequest = ApiPullRequest(
|
||||||
number = 1347,
|
number = 1347,
|
||||||
updated_at = date1,
|
updated_at = date1,
|
||||||
@@ -264,6 +299,7 @@ class JsonFormatSpec extends Specification {
|
|||||||
}
|
}
|
||||||
"apiComment" in {
|
"apiComment" in {
|
||||||
JsonFormat(apiComment) must beFormatted(apiCommentJson)
|
JsonFormat(apiComment) must beFormatted(apiCommentJson)
|
||||||
|
JsonFormat(apiCommentPR) must beFormatted(apiCommentPRJson)
|
||||||
}
|
}
|
||||||
"apiCommitListItem" in {
|
"apiCommitListItem" in {
|
||||||
JsonFormat(apiCommitListItem) must beFormatted(apiCommitListItemJson)
|
JsonFormat(apiCommitListItem) must beFormatted(apiCommitListItemJson)
|
||||||
@@ -276,6 +312,7 @@ class JsonFormatSpec extends Specification {
|
|||||||
}
|
}
|
||||||
"apiIssue" in {
|
"apiIssue" in {
|
||||||
JsonFormat(apiIssue) must beFormatted(apiIssueJson)
|
JsonFormat(apiIssue) must beFormatted(apiIssueJson)
|
||||||
|
JsonFormat(apiIssuePR) must beFormatted(apiIssuePRJson)
|
||||||
}
|
}
|
||||||
"apiPullRequest" in {
|
"apiPullRequest" in {
|
||||||
JsonFormat(apiPullRequest) must beFormatted(apiPullRequestJson)
|
JsonFormat(apiPullRequest) must beFormatted(apiPullRequestJson)
|
||||||
|
|||||||
Reference in New Issue
Block a user