mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Add assignee entry for the result of pull request related api
This commit is contained in:
@@ -2,6 +2,9 @@ package gitbucket.core.api
|
||||
|
||||
import gitbucket.core.model.{Account, Issue, IssueComment, PullRequest}
|
||||
import java.util.Date
|
||||
import gitbucket.core.service.AccountService
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,7 +22,8 @@ case class ApiPullRequest(
|
||||
merged_by: Option[ApiUser],
|
||||
title: String,
|
||||
body: String,
|
||||
user: ApiUser) {
|
||||
user: ApiUser,
|
||||
assignee: Either[ApiUser,AnyRef]) extends AccountService {
|
||||
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 patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
|
||||
@@ -40,7 +44,7 @@ object ApiPullRequest{
|
||||
baseRepo: ApiRepository,
|
||||
user: ApiUser,
|
||||
mergedComment: Option[(IssueComment, Account)]
|
||||
): ApiPullRequest =
|
||||
)(implicit s: Session): ApiPullRequest =
|
||||
ApiPullRequest(
|
||||
number = issue.issueId,
|
||||
updated_at = issue.updatedDate,
|
||||
@@ -59,7 +63,8 @@ object ApiPullRequest{
|
||||
merged_by = mergedComment.map { case (_, account) => ApiUser(account) },
|
||||
title = issue.title,
|
||||
body = issue.content.getOrElse(""),
|
||||
user = user
|
||||
user = user,
|
||||
assignee = if (issue.assignedUserName == None) Right(null) else Left(ApiUser(getAccountByUserName(issue.assignedUserName.getOrElse("")).get))
|
||||
)
|
||||
|
||||
case class Commit(
|
||||
@@ -69,4 +74,7 @@ object ApiPullRequest{
|
||||
val label = if( baseOwner == repo.owner.login ){ ref }else{ s"${repo.owner.login}:${ref}" }
|
||||
val user = repo.owner
|
||||
}
|
||||
|
||||
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
||||
Accounts filter(t => (t.userName === userName.bind) && (t.removed === false.bind, !includeRemoved)) firstOption
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ object JsonFormat {
|
||||
{ case x: Date => JString(parserISO.print(new DateTime(x).withZone(DateTimeZone.UTC))) }
|
||||
)
|
||||
) + FieldSerializer[ApiUser]() +
|
||||
FieldSerializer[ApiPullRequest]() +
|
||||
FieldSerializer[ApiPullRequest](FieldSerializer.ignore("gitbucket$core$service$AccountService$$logger")) +
|
||||
FieldSerializer[ApiRepository]() +
|
||||
FieldSerializer[ApiCommitListItem.Parent]() +
|
||||
FieldSerializer[ApiCommitListItem]() +
|
||||
|
||||
@@ -498,7 +498,7 @@ trait ApiControllerBase extends ControllerBase {
|
||||
val condition = IssueSearchCondition(request)
|
||||
val baseOwner = getAccountByUserName(repository.owner).get
|
||||
|
||||
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account)] =
|
||||
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, Account)] =
|
||||
searchPullRequestByApi(
|
||||
condition = condition,
|
||||
offset = (page - 1) * PullRequestLimit,
|
||||
@@ -506,7 +506,7 @@ trait ApiControllerBase extends ControllerBase {
|
||||
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(
|
||||
issue = issue,
|
||||
pullRequest = pullRequest,
|
||||
|
||||
@@ -199,15 +199,16 @@ trait IssuesService {
|
||||
* @return (issue, issueUser, commentCount, pullRequest, headRepo, headOwner)
|
||||
*/
|
||||
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, Account)] = {
|
||||
// get issues and comment count and labels
|
||||
searchIssueQueryBase(condition, true, offset, limit, repos)
|
||||
.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(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 }
|
||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => i asc }
|
||||
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => (t1, t5, t2.commentCount, t3, t4, t6) }
|
||||
.join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 => t7.userName === t1.assignedUserName}
|
||||
.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
|
||||
}
|
||||
|
||||
|
||||
@@ -430,7 +430,7 @@ object WebHookService {
|
||||
baseRepository: RepositoryInfo,
|
||||
baseOwner: Account,
|
||||
sender: Account,
|
||||
mergedComment: Option[(IssueComment, Account)]): WebHookPullRequestPayload = {
|
||||
mergedComment: Option[(IssueComment, Account)])(implicit s: Session): WebHookPullRequestPayload = {
|
||||
|
||||
val headRepoPayload = ApiRepository(headRepository, headOwner)
|
||||
val baseRepoPayload = ApiRepository(baseRepository, baseOwner)
|
||||
@@ -502,7 +502,7 @@ object WebHookService {
|
||||
baseOwner: Account,
|
||||
sender: Account,
|
||||
mergedComment: Option[(IssueComment, Account)]
|
||||
) : WebHookPullRequestReviewCommentPayload = {
|
||||
)(implicit s: Session) : WebHookPullRequestReviewCommentPayload = {
|
||||
val headRepoPayload = ApiRepository(headRepository, headOwner)
|
||||
val baseRepoPayload = ApiRepository(baseRepository, baseOwner)
|
||||
val senderPayload = ApiUser(sender)
|
||||
|
||||
@@ -281,7 +281,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
merged_by = Some(apiUser),
|
||||
title = "new-feature",
|
||||
body = "Please pull these awesome changes",
|
||||
user = apiUser
|
||||
user = apiUser,
|
||||
assignee = Left(apiUser)
|
||||
)
|
||||
|
||||
val apiPullRequestJson = s"""{
|
||||
@@ -311,6 +312,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"title": "new-feature",
|
||||
"body": "Please pull these awesome changes",
|
||||
"user": $apiUserJson,
|
||||
"assignee": $apiUserJson,
|
||||
"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