mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 18:05:50 +01:00
Merge pull request #1908 from kounoike/pr-add-labels-to-api
Add labels to ApiIssue/ApiPullRequest
This commit is contained in:
@@ -13,7 +13,7 @@ case class ApiIssue(
|
||||
number: Int,
|
||||
title: String,
|
||||
user: ApiUser,
|
||||
// labels,
|
||||
labels: List[ApiLabel],
|
||||
state: String,
|
||||
created_at: Date,
|
||||
updated_at: Date,
|
||||
@@ -33,11 +33,12 @@ case class ApiIssue(
|
||||
}
|
||||
|
||||
object ApiIssue{
|
||||
def apply(issue: Issue, repositoryName: RepositoryName, user: ApiUser): ApiIssue =
|
||||
def apply(issue: Issue, repositoryName: RepositoryName, user: ApiUser, labels: List[ApiLabel]): ApiIssue =
|
||||
ApiIssue(
|
||||
number = issue.issueId,
|
||||
title = issue.title,
|
||||
user = user,
|
||||
labels = labels,
|
||||
state = if(issue.closed){ "closed" }else{ "open" },
|
||||
body = issue.content.getOrElse(""),
|
||||
created_at = issue.registeredDate,
|
||||
|
||||
@@ -20,6 +20,7 @@ case class ApiPullRequest(
|
||||
title: String,
|
||||
body: String,
|
||||
user: ApiUser,
|
||||
labels: List[ApiLabel],
|
||||
assignee: Option[ApiUser]){
|
||||
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
||||
//val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
|
||||
@@ -40,6 +41,7 @@ object ApiPullRequest{
|
||||
headRepo: ApiRepository,
|
||||
baseRepo: ApiRepository,
|
||||
user: ApiUser,
|
||||
labels: List[ApiLabel],
|
||||
assignee: Option[ApiUser],
|
||||
mergedComment: Option[(IssueComment, Account)]
|
||||
): ApiPullRequest =
|
||||
@@ -63,6 +65,7 @@ object ApiPullRequest{
|
||||
title = issue.title,
|
||||
body = issue.content.getOrElse(""),
|
||||
user = user,
|
||||
labels = labels,
|
||||
assignee = assignee
|
||||
)
|
||||
|
||||
|
||||
@@ -352,7 +352,8 @@ trait ApiControllerBase extends ControllerBase {
|
||||
ApiIssue(
|
||||
issue = issue,
|
||||
repositoryName = RepositoryName(repository),
|
||||
user = ApiUser(issueUser)
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -366,7 +367,8 @@ trait ApiControllerBase extends ControllerBase {
|
||||
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||
openedUser <- getAccountByUserName(issue.openedUserName)
|
||||
} yield {
|
||||
JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(openedUser)))
|
||||
JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(openedUser),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))))
|
||||
}) getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -389,7 +391,8 @@ trait ApiControllerBase extends ControllerBase {
|
||||
None,
|
||||
data.labels,
|
||||
loginAccount)
|
||||
JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(loginAccount)))
|
||||
JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(loginAccount),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))))
|
||||
}) getOrElse NotFound()
|
||||
} else Unauthorized()
|
||||
})
|
||||
@@ -532,6 +535,7 @@ trait ApiControllerBase extends ControllerBase {
|
||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
)
|
||||
@@ -558,6 +562,7 @@ trait ApiControllerBase extends ControllerBase {
|
||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
))
|
||||
|
||||
@@ -3,7 +3,7 @@ package gitbucket.core.service
|
||||
import fr.brouillard.oss.security.xhub.XHub
|
||||
import fr.brouillard.oss.security.xhub.XHub.{XHubConverter, XHubDigest}
|
||||
import gitbucket.core.api._
|
||||
import gitbucket.core.model.{Account, CommitComment, Issue, IssueComment, PullRequest, WebHook, RepositoryWebHook, RepositoryWebHookEvent, AccountWebHook, AccountWebHookEvent}
|
||||
import gitbucket.core.model.{Account, CommitComment, Issue, IssueComment, Label, PullRequest, WebHook, RepositoryWebHook, RepositoryWebHookEvent, AccountWebHook, AccountWebHookEvent}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import org.apache.http.client.utils.URLEncodedUtils
|
||||
@@ -216,7 +216,8 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
action = action,
|
||||
number = issue.issueId,
|
||||
repository = ApiRepository(repository, ApiUser(repoOwner)),
|
||||
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
||||
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))),
|
||||
sender = ApiUser(sender))
|
||||
}
|
||||
}
|
||||
@@ -234,6 +235,7 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
|
||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
||||
} yield {
|
||||
WebHookPullRequestPayload(
|
||||
action = action,
|
||||
@@ -245,6 +247,7 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
headOwner = headOwner,
|
||||
baseRepository = repository,
|
||||
baseOwner = baseOwner,
|
||||
labels = labels,
|
||||
sender = sender,
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issueId)
|
||||
)
|
||||
@@ -277,6 +280,7 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
|
||||
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
|
||||
baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName)
|
||||
labels = getIssueLabels(pullRequest.userName, pullRequest.repositoryName, issue.issueId).map(ApiLabel(_, RepositoryName(pullRequest.userName, pullRequest.repositoryName)))
|
||||
} yield {
|
||||
val payload = WebHookPullRequestPayload(
|
||||
action = action,
|
||||
@@ -288,6 +292,7 @@ trait WebHookPullRequestService extends WebHookService {
|
||||
headOwner = headOwner,
|
||||
baseRepository = baseRepo,
|
||||
baseOwner = baseOwner,
|
||||
labels = labels,
|
||||
sender = sender,
|
||||
mergedComment = getMergedComment(baseRepo.owner, baseRepo.name, issue.issueId)
|
||||
)
|
||||
@@ -312,6 +317,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
|
||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
|
||||
labels = getIssueLabels(pullRequest.userName, pullRequest.repositoryName, issue.issueId).map(ApiLabel(_, RepositoryName(pullRequest.userName, pullRequest.repositoryName)))
|
||||
} yield {
|
||||
WebHookPullRequestReviewCommentPayload(
|
||||
action = action,
|
||||
@@ -324,6 +330,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
|
||||
headOwner = headOwner,
|
||||
baseRepository = repository,
|
||||
baseOwner = baseOwner,
|
||||
labels = labels,
|
||||
sender = sender,
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
)
|
||||
@@ -345,6 +352,7 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
repoOwner <- users.get(repository.owner)
|
||||
commenter <- users.get(issueComment.commentedUserName)
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
} yield {
|
||||
WebHookIssueCommentPayload(
|
||||
issue = issue,
|
||||
@@ -353,7 +361,8 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
|
||||
commentUser = commenter,
|
||||
repository = repository,
|
||||
repositoryUser = repoOwner,
|
||||
sender = sender)
|
||||
sender = sender,
|
||||
labels = labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,6 +474,7 @@ object WebHookService {
|
||||
headOwner: Account,
|
||||
baseRepository: RepositoryInfo,
|
||||
baseOwner: Account,
|
||||
labels: List[ApiLabel],
|
||||
sender: Account,
|
||||
mergedComment: Option[(IssueComment, Account)]): WebHookPullRequestPayload = {
|
||||
|
||||
@@ -477,6 +487,7 @@ object WebHookService {
|
||||
headRepo = headRepoPayload,
|
||||
baseRepo = baseRepoPayload,
|
||||
user = ApiUser(issueUser),
|
||||
labels = labels,
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = mergedComment
|
||||
)
|
||||
@@ -508,11 +519,12 @@ object WebHookService {
|
||||
commentUser: Account,
|
||||
repository: RepositoryInfo,
|
||||
repositoryUser: Account,
|
||||
sender: Account): WebHookIssueCommentPayload =
|
||||
sender: Account,
|
||||
labels: List[Label]): WebHookIssueCommentPayload =
|
||||
WebHookIssueCommentPayload(
|
||||
action = "created",
|
||||
repository = ApiRepository(repository, repositoryUser),
|
||||
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser)),
|
||||
issue = ApiIssue(issue, RepositoryName(repository), ApiUser(issueUser), labels.map(ApiLabel(_, RepositoryName(repository)))),
|
||||
comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser), issue.isPullRequest),
|
||||
sender = ApiUser(sender))
|
||||
}
|
||||
@@ -538,6 +550,7 @@ object WebHookService {
|
||||
headOwner: Account,
|
||||
baseRepository: RepositoryInfo,
|
||||
baseOwner: Account,
|
||||
labels: List[ApiLabel],
|
||||
sender: Account,
|
||||
mergedComment: Option[(IssueComment, Account)]
|
||||
): WebHookPullRequestReviewCommentPayload = {
|
||||
@@ -559,6 +572,7 @@ object WebHookService {
|
||||
headRepo = headRepoPayload,
|
||||
baseRepo = baseRepoPayload,
|
||||
user = ApiUser(issueUser),
|
||||
labels = labels,
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = mergedComment
|
||||
),
|
||||
|
||||
@@ -221,6 +221,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
number = 1347,
|
||||
title = "Found a bug",
|
||||
user = apiUser,
|
||||
labels = List(apiLabel),
|
||||
state = "open",
|
||||
body = "I'm having a problem with this.",
|
||||
created_at = date1,
|
||||
@@ -231,6 +232,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"title": "Found a bug",
|
||||
"body": "I'm having a problem with this.",
|
||||
"user": $apiUserJson,
|
||||
"labels": [$apiLabelJson],
|
||||
"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",
|
||||
@@ -241,6 +243,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
number = 1347,
|
||||
title = "Found a bug",
|
||||
user = apiUser,
|
||||
labels = List(apiLabel),
|
||||
state = "open",
|
||||
body = "I'm having a problem with this.",
|
||||
created_at = date1,
|
||||
@@ -251,6 +254,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"title": "Found a bug",
|
||||
"body": "I'm having a problem with this.",
|
||||
"user": $apiUserJson,
|
||||
"labels": [$apiLabelJson],
|
||||
"comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|
||||
"html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347",
|
||||
"pull_request": {
|
||||
@@ -283,6 +287,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
title = "new-feature",
|
||||
body = "Please pull these awesome changes",
|
||||
user = apiUser,
|
||||
labels = List(apiLabel),
|
||||
assignee = Some(apiUser)
|
||||
)
|
||||
|
||||
@@ -315,6 +320,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"body": "Please pull these awesome changes",
|
||||
"user": $apiUserJson,
|
||||
"assignee": $apiUserJson,
|
||||
"labels": [$apiLabelJson],
|
||||
"html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347",
|
||||
"url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/pulls/1347",
|
||||
"commits_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/pulls/1347/commits",
|
||||
|
||||
Reference in New Issue
Block a user