diff --git a/src/main/scala/gitbucket/core/api/ApiComment.scala b/src/main/scala/gitbucket/core/api/ApiComment.scala index fb6b688..47244f2 100644 --- a/src/main/scala/gitbucket/core/api/ApiComment.scala +++ b/src/main/scala/gitbucket/core/api/ApiComment.scala @@ -1,6 +1,7 @@ package gitbucket.core.api import gitbucket.core.model.IssueComment +import gitbucket.core.util.RepositoryName import java.util.Date @@ -13,14 +14,16 @@ user: ApiUser, body: String, created_at: Date, - updated_at: Date) + updated_at: Date)(repositoryName: RepositoryName, issueId: Int){ + val html_url = ApiPath(s"/${repositoryName.fullName}/issues/${issueId}#comment-${id}") +} object ApiComment{ - def apply(comment: IssueComment, user: ApiUser): ApiComment = + def apply(comment: IssueComment, repositoryName: RepositoryName, issueId: Int, user: ApiUser): ApiComment = ApiComment( id = comment.commentId, user = user, body = comment.content, created_at = comment.registeredDate, - updated_at = comment.updatedDate) + updated_at = comment.updatedDate)(repositoryName, issueId) } diff --git a/src/main/scala/gitbucket/core/api/JsonFormat.scala b/src/main/scala/gitbucket/core/api/JsonFormat.scala index 33611fd..a14a116 100644 --- a/src/main/scala/gitbucket/core/api/JsonFormat.scala +++ b/src/main/scala/gitbucket/core/api/JsonFormat.scala @@ -23,7 +23,7 @@ ) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() + FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() + FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() + - FieldSerializer[ApiPullRequest.Commit]() + FieldSerializer[ApiIssue]() + FieldSerializer[ApiPullRequest.Commit]() + FieldSerializer[ApiIssue]() + FieldSerializer[ApiComment]() def apiPathSerializer(c: Context) = new CustomSerializer[ApiPath](format => diff --git a/src/main/scala/gitbucket/core/controller/IssuesController.scala b/src/main/scala/gitbucket/core/controller/IssuesController.scala index 80c450b..1aafbeb 100644 --- a/src/main/scala/gitbucket/core/controller/IssuesController.scala +++ b/src/main/scala/gitbucket/core/controller/IssuesController.scala @@ -86,7 +86,7 @@ issueId <- params("id").toIntOpt comments = getCommentsForApi(repository.owner, repository.name, issueId.toInt) } yield { - JsonFormat(comments.map{ case (issueComment, user) => ApiComment(issueComment, ApiUser(user)) }) + JsonFormat(comments.map{ case (issueComment, user) => ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user)) }) }).getOrElse(NotFound) }) @@ -190,7 +190,7 @@ (issue, id) <- handleComment(issueId, Some(body), repository)() issueComment <- getComment(repository.owner, repository.name, id.toString()) } yield { - JsonFormat(ApiComment(issueComment, ApiUser(context.loginAccount.get))) + JsonFormat(ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(context.loginAccount.get))) }) getOrElse NotFound }) diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 05913fe..04d4d50 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -273,7 +273,7 @@ action = "created", repository = ApiRepository(repository, repositoryUser), issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)), - comment = ApiComment(comment, ApiUser(commentUser)), + comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser)), sender = ApiUser(sender)) } } diff --git a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala index 2116c3c..c564478 100644 --- a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala +++ b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala @@ -90,11 +90,12 @@ user = apiUser, body= "Me too", created_at= date1, - updated_at= date1) + updated_at= date1)(RepositoryName("octocat","Hello-World"), 100) val apiCommentJson = s"""{ "id": 1, "body": "Me too", "user": $apiUserJson, + "html_url" : "${context.baseUrl}/octocat/Hello-World/issues/100#comment-1", "created_at": "2011-04-14T16:00:49Z", "updated_at": "2011-04-14T16:00:49Z" }"""