mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Merge pull request #718 from team-lab/feature/api-add-issue-urls
Feature/api add issue urls
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
import gitbucket.core.model.IssueComment
|
import gitbucket.core.model.IssueComment
|
||||||
|
import gitbucket.core.util.RepositoryName
|
||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@@ -13,14 +14,16 @@ case class ApiComment(
|
|||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
body: String,
|
body: String,
|
||||||
created_at: Date,
|
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{
|
object ApiComment{
|
||||||
def apply(comment: IssueComment, user: ApiUser): ApiComment =
|
def apply(comment: IssueComment, repositoryName: RepositoryName, issueId: Int, user: ApiUser): 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)
|
updated_at = comment.updatedDate)(repositoryName, issueId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
import gitbucket.core.model.Issue
|
import gitbucket.core.model.Issue
|
||||||
|
import gitbucket.core.util.RepositoryName
|
||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@@ -16,10 +17,13 @@ case class ApiIssue(
|
|||||||
state: String,
|
state: String,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
updated_at: Date,
|
updated_at: Date,
|
||||||
body: String)
|
body: String)(repositoryName: RepositoryName){
|
||||||
|
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
||||||
|
val html_url = ApiPath(s"/${repositoryName.fullName}/issues/${number}")
|
||||||
|
}
|
||||||
|
|
||||||
object ApiIssue{
|
object ApiIssue{
|
||||||
def apply(issue: Issue, user: ApiUser): ApiIssue =
|
def apply(issue: Issue, repositoryName: RepositoryName, user: ApiUser): ApiIssue =
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
number = issue.issueId,
|
number = issue.issueId,
|
||||||
title = issue.title,
|
title = issue.title,
|
||||||
@@ -27,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)
|
updated_at = issue.updatedDate)(repositoryName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ object JsonFormat {
|
|||||||
) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() +
|
) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() +
|
||||||
FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() +
|
FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() +
|
||||||
FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() +
|
FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() +
|
||||||
FieldSerializer[ApiPullRequest.Commit]()
|
FieldSerializer[ApiPullRequest.Commit]() + FieldSerializer[ApiIssue]() + FieldSerializer[ApiComment]()
|
||||||
|
|
||||||
|
|
||||||
def apiPathSerializer(c: Context) = new CustomSerializer[ApiPath](format =>
|
def apiPathSerializer(c: Context) = new CustomSerializer[ApiPath](format =>
|
||||||
|
|||||||
@@ -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, ApiUser(user)) })
|
JsonFormat(comments.map{ case (issueComment, user) => ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user)) })
|
||||||
}).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, ApiUser(context.loginAccount.get)))
|
JsonFormat(ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(context.loginAccount.get)))
|
||||||
}) getOrElse NotFound
|
}) getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
action = action,
|
action = action,
|
||||||
number = issue.issueId,
|
number = issue.issueId,
|
||||||
repository = ApiRepository(repository, ApiUser(repoOwner)),
|
repository = ApiRepository(repository, ApiUser(repoOwner)),
|
||||||
issue = ApiIssue(issue, ApiUser(issueUser)),
|
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
||||||
sender = ApiUser(sender))
|
sender = ApiUser(sender))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,8 +272,8 @@ object WebHookService {
|
|||||||
WebHookIssueCommentPayload(
|
WebHookIssueCommentPayload(
|
||||||
action = "created",
|
action = "created",
|
||||||
repository = ApiRepository(repository, repositoryUser),
|
repository = ApiRepository(repository, repositoryUser),
|
||||||
issue = ApiIssue(issue, ApiUser(issueUser)),
|
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
||||||
comment = ApiComment(comment, ApiUser(commentUser)),
|
comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser)),
|
||||||
sender = ApiUser(sender))
|
sender = ApiUser(sender))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,11 +90,12 @@ class JsonFormatSpec extends Specification {
|
|||||||
user = apiUser,
|
user = apiUser,
|
||||||
body= "Me too",
|
body= "Me too",
|
||||||
created_at= date1,
|
created_at= date1,
|
||||||
updated_at= date1)
|
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100)
|
||||||
val apiCommentJson = s"""{
|
val apiCommentJson = s"""{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"body": "Me too",
|
"body": "Me too",
|
||||||
"user": $apiUserJson,
|
"user": $apiUserJson,
|
||||||
|
"html_url" : "${context.baseUrl}/octocat/Hello-World/issues/100#comment-1",
|
||||||
"created_at": "2011-04-14T16:00:49Z",
|
"created_at": "2011-04-14T16:00:49Z",
|
||||||
"updated_at": "2011-04-14T16:00:49Z"
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
}"""
|
}"""
|
||||||
@@ -157,13 +158,15 @@ 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)
|
updated_at = date1)(RepositoryName("octocat","Hello-World"))
|
||||||
val apiIssueJson = s"""{
|
val apiIssueJson = s"""{
|
||||||
"number": 1347,
|
"number": 1347,
|
||||||
"state": "open",
|
"state": "open",
|
||||||
"title": "Found a bug",
|
"title": "Found a bug",
|
||||||
"body": "I'm having a problem with this.",
|
"body": "I'm having a problem with this.",
|
||||||
"user": $apiUserJson,
|
"user": $apiUserJson,
|
||||||
|
"comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|
||||||
|
"html_url": "${context.baseUrl}/octocat/Hello-World/issues/1347",
|
||||||
"created_at": "2011-04-14T16:00:49Z",
|
"created_at": "2011-04-14T16:00:49Z",
|
||||||
"updated_at": "2011-04-14T16:00:49Z"
|
"updated_at": "2011-04-14T16:00:49Z"
|
||||||
}"""
|
}"""
|
||||||
|
|||||||
Reference in New Issue
Block a user