Merge branch 'add_assignee_to_pr_api'

This commit is contained in:
Naoki Takezoe
2017-09-05 20:37:03 +09:00
5 changed files with 35 additions and 16 deletions

View File

@@ -3,7 +3,6 @@ package gitbucket.core.api
import gitbucket.core.model.{Account, Issue, IssueComment, PullRequest} import gitbucket.core.model.{Account, Issue, IssueComment, PullRequest}
import java.util.Date import java.util.Date
/** /**
* https://developer.github.com/v3/pulls/ * https://developer.github.com/v3/pulls/
*/ */
@@ -19,7 +18,8 @@ case class ApiPullRequest(
merged_by: Option[ApiUser], merged_by: Option[ApiUser],
title: String, title: String,
body: String, body: String,
user: ApiUser) { user: 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")
//val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch") //val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
@@ -39,6 +39,7 @@ object ApiPullRequest{
headRepo: ApiRepository, headRepo: ApiRepository,
baseRepo: ApiRepository, baseRepo: ApiRepository,
user: ApiUser, user: ApiUser,
assignee: Option[ApiUser],
mergedComment: Option[(IssueComment, Account)] mergedComment: Option[(IssueComment, Account)]
): ApiPullRequest = ): ApiPullRequest =
ApiPullRequest( ApiPullRequest(
@@ -59,14 +60,16 @@ object ApiPullRequest{
merged_by = mergedComment.map { case (_, account) => ApiUser(account) }, merged_by = mergedComment.map { case (_, account) => ApiUser(account) },
title = issue.title, title = issue.title,
body = issue.content.getOrElse(""), body = issue.content.getOrElse(""),
user = user user = user,
assignee = assignee
) )
case class Commit( case class Commit(
sha: String, sha: String,
ref: String, ref: String,
repo: ApiRepository)(baseOwner:String){ repo: ApiRepository)(baseOwner:String){
val label = if( baseOwner == repo.owner.login ){ ref }else{ s"${repo.owner.login}:${ref}" } val label = if( baseOwner == repo.owner.login ){ ref } else { s"${repo.owner.login}:${ref}" }
val user = repo.owner val user = repo.owner
} }
} }

View File

@@ -501,7 +501,7 @@ trait ApiControllerBase extends ControllerBase {
val condition = IssueSearchCondition(request) val condition = IssueSearchCondition(request)
val baseOwner = getAccountByUserName(repository.owner).get val baseOwner = getAccountByUserName(repository.owner).get
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account)] = val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, Option[Account])] =
searchPullRequestByApi( searchPullRequestByApi(
condition = condition, condition = condition,
offset = (page - 1) * PullRequestLimit, offset = (page - 1) * PullRequestLimit,
@@ -509,13 +509,14 @@ trait ApiControllerBase extends ControllerBase {
repos = repository.owner -> repository.name repos = repository.owner -> repository.name
) )
JsonFormat(issues.map { case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner) => JsonFormat(issues.map { case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignee) =>
ApiPullRequest( ApiPullRequest(
issue = issue, issue = issue,
pullRequest = pullRequest, pullRequest = pullRequest,
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),
assignee = assignee.map(ApiUser.apply),
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
) )
}) })
@@ -532,6 +533,7 @@ trait ApiControllerBase extends ControllerBase {
baseOwner <- users.get(repository.owner) baseOwner <- users.get(repository.owner)
headOwner <- users.get(pullRequest.requestUserName) headOwner <- users.get(pullRequest.requestUserName)
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
} yield { } yield {
JsonFormat(ApiPullRequest( JsonFormat(ApiPullRequest(
@@ -540,6 +542,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),
assignee = assignee.map(ApiUser.apply),
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId) mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
)) ))
}) getOrElse NotFound() }) getOrElse NotFound()

View File

@@ -202,15 +202,16 @@ trait IssuesService {
* @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner) * @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner)
*/ */
def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*) def searchPullRequestByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)
(implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = { (implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account, Option[Account])] = {
// get issues and comment count and labels // get issues and comment count and labels
searchIssueQueryBase(condition, true, offset, limit, repos) searchIssueQueryBase(condition, true, offset, limit, repos)
.join(PullRequests).on { case t1 ~ t2 ~ i ~ t3 => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } .join (PullRequests).on { case t1 ~ t2 ~ i ~ t3 => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) }
.join(Repositories).on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t4.byRepository(t1.userName, t1.repositoryName) } .join (Repositories).on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t4.byRepository(t1.userName, t1.repositoryName) }
.join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t5.userName === t1.openedUserName } .join (Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t5.userName === t1.openedUserName }
.join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => t6.userName === t4.userName } .join (Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => t6.userName === t4.userName }
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => i asc } .joinLeft(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 => t7.userName === t1.assignedUserName}
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => (t1, t5, t2.commentCount, t3, t4, t6) } .sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 => i asc }
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 => (t1, t5, t2.commentCount, t3, t4, t6, t7) }
.list .list
} }

View File

@@ -232,12 +232,14 @@ trait WebHookPullRequestService extends WebHookService {
baseOwner <- users.get(repository.owner) baseOwner <- users.get(repository.owner)
headOwner <- users.get(pullRequest.requestUserName) headOwner <- users.get(pullRequest.requestUserName)
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
} yield { } yield {
WebHookPullRequestPayload( WebHookPullRequestPayload(
action = action, action = action,
issue = issue, issue = issue,
issueUser = issueUser, issueUser = issueUser,
assignee = assignee,
pullRequest = pullRequest, pullRequest = pullRequest,
headRepository = headRepo, headRepository = headRepo,
headOwner = headOwner, headOwner = headOwner,
@@ -273,12 +275,14 @@ trait WebHookPullRequestService extends WebHookService {
import WebHookService._ import WebHookService._
for{ for{
((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) }
baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName) baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName)
} yield { } yield {
val payload = WebHookPullRequestPayload( val payload = WebHookPullRequestPayload(
action = action, action = action,
issue = issue, issue = issue,
issueUser = issueUser, issueUser = issueUser,
assignee = assignee,
pullRequest = pullRequest, pullRequest = pullRequest,
headRepository = requestRepository, headRepository = requestRepository,
headOwner = headOwner, headOwner = headOwner,
@@ -306,6 +310,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
baseOwner <- users.get(repository.owner) baseOwner <- users.get(repository.owner)
headOwner <- users.get(pullRequest.requestUserName) headOwner <- users.get(pullRequest.requestUserName)
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
assignee = issue.assignedUserName.flatMap { userName => getAccountByUserName(userName, false) }
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
} yield { } yield {
WebHookPullRequestReviewCommentPayload( WebHookPullRequestReviewCommentPayload(
@@ -313,6 +318,7 @@ trait WebHookPullRequestReviewCommentService extends WebHookService {
comment = comment, comment = comment,
issue = issue, issue = issue,
issueUser = issueUser, issueUser = issueUser,
assignee = assignee,
pullRequest = pullRequest, pullRequest = pullRequest,
headRepository = headRepo, headRepository = headRepo,
headOwner = headOwner, headOwner = headOwner,
@@ -424,6 +430,7 @@ object WebHookService {
def apply(action: String, def apply(action: String,
issue: Issue, issue: Issue,
issueUser: Account, issueUser: Account,
assignee: Option[Account],
pullRequest: PullRequest, pullRequest: PullRequest,
headRepository: RepositoryInfo, headRepository: RepositoryInfo,
headOwner: Account, headOwner: Account,
@@ -441,6 +448,7 @@ object WebHookService {
headRepo = headRepoPayload, headRepo = headRepoPayload,
baseRepo = baseRepoPayload, baseRepo = baseRepoPayload,
user = ApiUser(issueUser), user = ApiUser(issueUser),
assignee = assignee.map(ApiUser.apply),
mergedComment = mergedComment mergedComment = mergedComment
) )
@@ -495,6 +503,7 @@ object WebHookService {
comment: CommitComment, comment: CommitComment,
issue: Issue, issue: Issue,
issueUser: Account, issueUser: Account,
assignee: Option[Account],
pullRequest: PullRequest, pullRequest: PullRequest,
headRepository: RepositoryInfo, headRepository: RepositoryInfo,
headOwner: Account, headOwner: Account,
@@ -502,7 +511,7 @@ object WebHookService {
baseOwner: Account, baseOwner: Account,
sender: Account, sender: Account,
mergedComment: Option[(IssueComment, Account)] mergedComment: Option[(IssueComment, Account)]
) : WebHookPullRequestReviewCommentPayload = { ): WebHookPullRequestReviewCommentPayload = {
val headRepoPayload = ApiRepository(headRepository, headOwner) val headRepoPayload = ApiRepository(headRepository, headOwner)
val baseRepoPayload = ApiRepository(baseRepository, baseOwner) val baseRepoPayload = ApiRepository(baseRepository, baseOwner)
val senderPayload = ApiUser(sender) val senderPayload = ApiUser(sender)
@@ -521,6 +530,7 @@ object WebHookService {
headRepo = headRepoPayload, headRepo = headRepoPayload,
baseRepo = baseRepoPayload, baseRepo = baseRepoPayload,
user = ApiUser(issueUser), user = ApiUser(issueUser),
assignee = assignee.map(ApiUser.apply),
mergedComment = mergedComment mergedComment = mergedComment
), ),
repository = baseRepoPayload, repository = baseRepoPayload,

View File

@@ -281,7 +281,8 @@ class JsonFormatSpec extends FunSuite {
merged_by = Some(apiUser), merged_by = Some(apiUser),
title = "new-feature", title = "new-feature",
body = "Please pull these awesome changes", body = "Please pull these awesome changes",
user = apiUser user = apiUser,
assignee = Some(apiUser)
) )
val apiPullRequestJson = s"""{ val apiPullRequestJson = s"""{
@@ -311,6 +312,7 @@ class JsonFormatSpec extends FunSuite {
"title": "new-feature", "title": "new-feature",
"body": "Please pull these awesome changes", "body": "Please pull these awesome changes",
"user": $apiUserJson, "user": $apiUserJson,
"assignee": $apiUserJson,
"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",