diff --git a/src/main/scala/gitbucket/core/api/ApiIssue.scala b/src/main/scala/gitbucket/core/api/ApiIssue.scala index 47374ed..9f27f55 100644 --- a/src/main/scala/gitbucket/core/api/ApiIssue.scala +++ b/src/main/scala/gitbucket/core/api/ApiIssue.scala @@ -13,7 +13,7 @@ number: Int, title: String, user: ApiUser, - // labels, + labels: List[ApiLabel], state: String, created_at: Date, updated_at: Date, @@ -33,11 +33,12 @@ } 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, diff --git a/src/main/scala/gitbucket/core/api/ApiPullRequest.scala b/src/main/scala/gitbucket/core/api/ApiPullRequest.scala index dc25e83..bf7f886 100644 --- a/src/main/scala/gitbucket/core/api/ApiPullRequest.scala +++ b/src/main/scala/gitbucket/core/api/ApiPullRequest.scala @@ -20,6 +20,7 @@ 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 @@ headRepo: ApiRepository, baseRepo: ApiRepository, user: ApiUser, + labels: List[ApiLabel], assignee: Option[ApiUser], mergedComment: Option[(IssueComment, Account)] ): ApiPullRequest = @@ -63,6 +65,7 @@ title = issue.title, body = issue.content.getOrElse(""), user = user, + labels = labels, assignee = assignee ) diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 6ba77d5..9054dfa 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -352,7 +352,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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) )) diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index f7a4e07..2dfca94 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -3,7 +3,7 @@ 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 @@ 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 @@ 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 @@ headOwner = headOwner, baseRepository = repository, baseOwner = baseOwner, + labels = labels, sender = sender, mergedComment = getMergedComment(repository.owner, repository.name, issueId) ) @@ -277,6 +280,7 @@ ((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 @@ headOwner = headOwner, baseRepository = baseRepo, baseOwner = baseOwner, + labels = labels, sender = sender, mergedComment = getMergedComment(baseRepo.owner, baseRepo.name, issue.issueId) ) @@ -312,6 +317,7 @@ 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 @@ headOwner = headOwner, baseRepository = repository, baseOwner = baseOwner, + labels = labels, sender = sender, mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) ) @@ -345,6 +352,7 @@ 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 @@ commentUser = commenter, repository = repository, repositoryUser = repoOwner, - sender = sender) + sender = sender, + labels = labels) } } } @@ -465,6 +474,7 @@ headOwner: Account, baseRepository: RepositoryInfo, baseOwner: Account, + labels: List[ApiLabel], sender: Account, mergedComment: Option[(IssueComment, Account)]): WebHookPullRequestPayload = { @@ -477,6 +487,7 @@ headRepo = headRepoPayload, baseRepo = baseRepoPayload, user = ApiUser(issueUser), + labels = labels, assignee = assignee.map(ApiUser.apply), mergedComment = mergedComment ) @@ -508,11 +519,12 @@ 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 @@ headOwner: Account, baseRepository: RepositoryInfo, baseOwner: Account, + labels: List[ApiLabel], sender: Account, mergedComment: Option[(IssueComment, Account)] ): WebHookPullRequestReviewCommentPayload = { @@ -559,6 +572,7 @@ headRepo = headRepoPayload, baseRepo = baseRepoPayload, user = ApiUser(issueUser), + labels = labels, assignee = assignee.map(ApiUser.apply), mergedComment = mergedComment ), diff --git a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala index ab0b69b..ccf6914 100644 --- a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala +++ b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala @@ -221,6 +221,7 @@ 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 @@ "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 @@ 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 @@ "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 @@ title = "new-feature", body = "Please pull these awesome changes", user = apiUser, + labels = List(apiLabel), assignee = Some(apiUser) ) @@ -315,6 +320,7 @@ "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",