Merge pull request #1908 from kounoike/pr-add-labels-to-api

Add labels to ApiIssue/ApiPullRequest
This commit is contained in:
Naoki Takezoe
2018-03-12 16:38:56 +09:00
committed by GitHub
5 changed files with 39 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ case class ApiIssue(
number: Int, number: Int,
title: String, title: String,
user: ApiUser, user: ApiUser,
// labels, labels: List[ApiLabel],
state: String, state: String,
created_at: Date, created_at: Date,
updated_at: Date, updated_at: Date,
@@ -33,11 +33,12 @@ case class ApiIssue(
} }
object 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( ApiIssue(
number = issue.issueId, number = issue.issueId,
title = issue.title, title = issue.title,
user = user, user = user,
labels = labels,
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,

View File

@@ -20,6 +20,7 @@ case class ApiPullRequest(
title: String, title: String,
body: String, body: String,
user: ApiUser, user: ApiUser,
labels: List[ApiLabel],
assignee: Option[ApiUser]){ assignee: Option[ApiUser]){
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}") 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") //val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
@@ -40,6 +41,7 @@ object ApiPullRequest{
headRepo: ApiRepository, headRepo: ApiRepository,
baseRepo: ApiRepository, baseRepo: ApiRepository,
user: ApiUser, user: ApiUser,
labels: List[ApiLabel],
assignee: Option[ApiUser], assignee: Option[ApiUser],
mergedComment: Option[(IssueComment, Account)] mergedComment: Option[(IssueComment, Account)]
): ApiPullRequest = ): ApiPullRequest =
@@ -63,6 +65,7 @@ object ApiPullRequest{
title = issue.title, title = issue.title,
body = issue.content.getOrElse(""), body = issue.content.getOrElse(""),
user = user, user = user,
labels = labels,
assignee = assignee assignee = assignee
) )

View File

@@ -352,7 +352,8 @@ trait ApiControllerBase extends ControllerBase {
ApiIssue( ApiIssue(
issue = issue, issue = issue,
repositoryName = RepositoryName(repository), 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) issue <- getIssue(repository.owner, repository.name, issueId.toString)
openedUser <- getAccountByUserName(issue.openedUserName) openedUser <- getAccountByUserName(issue.openedUserName)
} yield { } 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() }) getOrElse NotFound()
}) })
@@ -389,7 +391,8 @@ trait ApiControllerBase extends ControllerBase {
None, None,
data.labels, data.labels,
loginAccount) 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() }) getOrElse NotFound()
} else Unauthorized() } else Unauthorized()
}) })
@@ -532,6 +535,7 @@ trait ApiControllerBase extends ControllerBase {
headRepo = ApiRepository(headRepo, ApiUser(headOwner)), headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
baseRepo = ApiRepository(repository, ApiUser(baseOwner)), baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
user = ApiUser(issueUser), user = ApiUser(issueUser),
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
assignee = assignee.map(ApiUser.apply), assignee = assignee.map(ApiUser.apply),
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
) )
@@ -558,6 +562,7 @@ trait ApiControllerBase extends ControllerBase {
headRepo = ApiRepository(headRepo, ApiUser(headOwner)), headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
baseRepo = ApiRepository(repository, ApiUser(baseOwner)), baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
user = ApiUser(issueUser), user = ApiUser(issueUser),
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
assignee = assignee.map(ApiUser.apply), assignee = assignee.map(ApiUser.apply),
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
)) ))

View File

@@ -3,7 +3,7 @@ package gitbucket.core.service
import fr.brouillard.oss.security.xhub.XHub import fr.brouillard.oss.security.xhub.XHub
import fr.brouillard.oss.security.xhub.XHub.{XHubConverter, XHubDigest} import fr.brouillard.oss.security.xhub.XHub.{XHubConverter, XHubDigest}
import gitbucket.core.api._ 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._
import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.profile.blockingApi._
import org.apache.http.client.utils.URLEncodedUtils import org.apache.http.client.utils.URLEncodedUtils
@@ -216,7 +216,8 @@ 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, 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)) sender = ApiUser(sender))
} }
} }
@@ -234,6 +235,7 @@ trait WebHookPullRequestService extends WebHookService {
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) } assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
labels = getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
} yield { } yield {
WebHookPullRequestPayload( WebHookPullRequestPayload(
action = action, action = action,
@@ -245,6 +247,7 @@ trait WebHookPullRequestService extends WebHookService {
headOwner = headOwner, headOwner = headOwner,
baseRepository = repository, baseRepository = repository,
baseOwner = baseOwner, baseOwner = baseOwner,
labels = labels,
sender = sender, sender = sender,
mergedComment = getMergedComment(repository.owner, repository.name, issueId) 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) ((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) } assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName) baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName)
labels = getIssueLabels(pullRequest.userName, pullRequest.repositoryName, issue.issueId).map(ApiLabel(_, RepositoryName(pullRequest.userName, pullRequest.repositoryName)))
} yield { } yield {
val payload = WebHookPullRequestPayload( val payload = WebHookPullRequestPayload(
action = action, action = action,
@@ -288,6 +292,7 @@ trait WebHookPullRequestService extends WebHookService {
headOwner = headOwner, headOwner = headOwner,
baseRepository = baseRepo, baseRepository = baseRepo,
baseOwner = baseOwner, baseOwner = baseOwner,
labels = labels,
sender = sender, sender = sender,
mergedComment = getMergedComment(baseRepo.owner, baseRepo.name, issue.issueId) mergedComment = getMergedComment(baseRepo.owner, baseRepo.name, issue.issueId)
) )
@@ -312,6 +317,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) } assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
labels = getIssueLabels(pullRequest.userName, pullRequest.repositoryName, issue.issueId).map(ApiLabel(_, RepositoryName(pullRequest.userName, pullRequest.repositoryName)))
} yield { } yield {
WebHookPullRequestReviewCommentPayload( WebHookPullRequestReviewCommentPayload(
action = action, action = action,
@@ -324,6 +330,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
headOwner = headOwner, headOwner = headOwner,
baseRepository = repository, baseRepository = repository,
baseOwner = baseOwner, baseOwner = baseOwner,
labels = labels,
sender = sender, sender = sender,
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
) )
@@ -345,6 +352,7 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
repoOwner <- users.get(repository.owner) repoOwner <- users.get(repository.owner)
commenter <- users.get(issueComment.commentedUserName) commenter <- users.get(issueComment.commentedUserName)
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
} yield { } yield {
WebHookIssueCommentPayload( WebHookIssueCommentPayload(
issue = issue, issue = issue,
@@ -353,7 +361,8 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
commentUser = commenter, commentUser = commenter,
repository = repository, repository = repository,
repositoryUser = repoOwner, repositoryUser = repoOwner,
sender = sender) sender = sender,
labels = labels)
} }
} }
} }
@@ -465,6 +474,7 @@ object WebHookService {
headOwner: Account, headOwner: Account,
baseRepository: RepositoryInfo, baseRepository: RepositoryInfo,
baseOwner: Account, baseOwner: Account,
labels: List[ApiLabel],
sender: Account, sender: Account,
mergedComment: Option[(IssueComment, Account)]): WebHookPullRequestPayload = { mergedComment: Option[(IssueComment, Account)]): WebHookPullRequestPayload = {
@@ -477,6 +487,7 @@ object WebHookService {
headRepo = headRepoPayload, headRepo = headRepoPayload,
baseRepo = baseRepoPayload, baseRepo = baseRepoPayload,
user = ApiUser(issueUser), user = ApiUser(issueUser),
labels = labels,
assignee = assignee.map(ApiUser.apply), assignee = assignee.map(ApiUser.apply),
mergedComment = mergedComment mergedComment = mergedComment
) )
@@ -508,11 +519,12 @@ object WebHookService {
commentUser: Account, commentUser: Account,
repository: RepositoryInfo, repository: RepositoryInfo,
repositoryUser: Account, repositoryUser: Account,
sender: Account): WebHookIssueCommentPayload = sender: Account,
labels: List[Label]): WebHookIssueCommentPayload =
WebHookIssueCommentPayload( WebHookIssueCommentPayload(
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), labels.map(ApiLabel(_, RepositoryName(repository)))),
comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser), issue.isPullRequest), comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser), issue.isPullRequest),
sender = ApiUser(sender)) sender = ApiUser(sender))
} }
@@ -538,6 +550,7 @@ object WebHookService {
headOwner: Account, headOwner: Account,
baseRepository: RepositoryInfo, baseRepository: RepositoryInfo,
baseOwner: Account, baseOwner: Account,
labels: List[ApiLabel],
sender: Account, sender: Account,
mergedComment: Option[(IssueComment, Account)] mergedComment: Option[(IssueComment, Account)]
): WebHookPullRequestReviewCommentPayload = { ): WebHookPullRequestReviewCommentPayload = {
@@ -559,6 +572,7 @@ object WebHookService {
headRepo = headRepoPayload, headRepo = headRepoPayload,
baseRepo = baseRepoPayload, baseRepo = baseRepoPayload,
user = ApiUser(issueUser), user = ApiUser(issueUser),
labels = labels,
assignee = assignee.map(ApiUser.apply), assignee = assignee.map(ApiUser.apply),
mergedComment = mergedComment mergedComment = mergedComment
), ),

View File

@@ -221,6 +221,7 @@ class JsonFormatSpec extends FunSuite {
number = 1347, number = 1347,
title = "Found a bug", title = "Found a bug",
user = apiUser, user = apiUser,
labels = List(apiLabel),
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,
@@ -231,6 +232,7 @@ class JsonFormatSpec extends FunSuite {
"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,
"labels": [$apiLabelJson],
"comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments", "comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments",
"html_url": "${context.baseUrl}/octocat/Hello-World/issues/1347", "html_url": "${context.baseUrl}/octocat/Hello-World/issues/1347",
"created_at": "2011-04-14T16:00:49Z", "created_at": "2011-04-14T16:00:49Z",
@@ -241,6 +243,7 @@ class JsonFormatSpec extends FunSuite {
number = 1347, number = 1347,
title = "Found a bug", title = "Found a bug",
user = apiUser, user = apiUser,
labels = List(apiLabel),
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,
@@ -251,6 +254,7 @@ class JsonFormatSpec extends FunSuite {
"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,
"labels": [$apiLabelJson],
"comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments", "comments_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/issues/1347/comments",
"html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347", "html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347",
"pull_request": { "pull_request": {
@@ -283,6 +287,7 @@ class JsonFormatSpec extends FunSuite {
title = "new-feature", title = "new-feature",
body = "Please pull these awesome changes", body = "Please pull these awesome changes",
user = apiUser, user = apiUser,
labels = List(apiLabel),
assignee = Some(apiUser) assignee = Some(apiUser)
) )
@@ -315,6 +320,7 @@ class JsonFormatSpec extends FunSuite {
"body": "Please pull these awesome changes", "body": "Please pull these awesome changes",
"user": $apiUserJson, "user": $apiUserJson,
"assignee": $apiUserJson, "assignee": $apiUserJson,
"labels": [$apiLabelJson],
"html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347", "html_url": "${context.baseUrl}/octocat/Hello-World/pull/1347",
"url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/pulls/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", "commits_url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/pulls/1347/commits",