Add assignee and assignees properties to some issues api payload (#2398)

This commit is contained in:
Aoi Tanaka
2019-12-10 10:43:22 +09:00
committed by Naoki Takezoe
parent c241c08904
commit 455183a13e
7 changed files with 62 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ case class ApiIssue(
number: Int, number: Int,
title: String, title: String,
user: ApiUser, user: ApiUser,
assignee: Option[ApiUser],
labels: List[ApiLabel], labels: List[ApiLabel],
state: String, state: String,
created_at: Date, created_at: Date,
@@ -19,6 +20,7 @@ case class ApiIssue(
body: String body: String
)(repositoryName: RepositoryName, isPullRequest: Boolean) { )(repositoryName: RepositoryName, isPullRequest: Boolean) {
val id = 0 // dummy id val id = 0 // dummy id
val assignees = List(assignee).flatten
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments") val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}") val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}")
val pull_request = if (isPullRequest) { val pull_request = if (isPullRequest) {
@@ -36,11 +38,18 @@ case class ApiIssue(
} }
object ApiIssue { object ApiIssue {
def apply(issue: Issue, repositoryName: RepositoryName, user: ApiUser, labels: List[ApiLabel]): ApiIssue = def apply(
issue: Issue,
repositoryName: RepositoryName,
user: ApiUser,
assignee: Option[ApiUser],
labels: List[ApiLabel]
): ApiIssue =
ApiIssue( ApiIssue(
number = issue.issueId, number = issue.issueId,
title = issue.title, title = issue.title,
user = user, user = user,
assignee = assignee,
labels = labels, labels = labels,
state = if (issue.closed) { "closed" } else { "open" }, state = if (issue.closed) { "closed" } else { "open" },
body = issue.content.getOrElse(""), body = issue.content.getOrElse(""),

View File

@@ -31,7 +31,7 @@ trait ApiIssueControllerBase 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)] = val issues: List[(Issue, Account, Option[Account])] =
searchIssueByApi( searchIssueByApi(
condition = condition, condition = condition,
offset = (page - 1) * PullRequestLimit, offset = (page - 1) * PullRequestLimit,
@@ -40,11 +40,12 @@ trait ApiIssueControllerBase extends ControllerBase {
) )
JsonFormat(issues.map { JsonFormat(issues.map {
case (issue, issueUser) => case (issue, issueUser, assignedUser) =>
ApiIssue( ApiIssue(
issue = issue, issue = issue,
repositoryName = RepositoryName(repository), repositoryName = RepositoryName(repository),
user = ApiUser(issueUser), user = ApiUser(issueUser),
assignee = assignedUser.map(ApiUser(_)),
labels = getIssueLabels(repository.owner, repository.name, issue.issueId) labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
.map(ApiLabel(_, RepositoryName(repository))) .map(ApiLabel(_, RepositoryName(repository)))
) )
@@ -59,13 +60,15 @@ trait ApiIssueControllerBase extends ControllerBase {
(for { (for {
issueId <- params("id").toIntOpt issueId <- params("id").toIntOpt
issue <- getIssue(repository.owner, repository.name, issueId.toString) issue <- getIssue(repository.owner, repository.name, issueId.toString)
openedUser <- getAccountByUserName(issue.openedUserName) users = getAccountsByUserNames(Set(issue.openedUserName) ++ issue.assignedUserName, Set())
openedUser <- users.get(issue.openedUserName)
} yield { } yield {
JsonFormat( JsonFormat(
ApiIssue( ApiIssue(
issue, issue,
RepositoryName(repository), RepositoryName(repository),
ApiUser(openedUser), ApiUser(openedUser),
issue.assignedUserName.flatMap(users.get(_)).map(ApiUser(_)),
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))) getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
) )
) )
@@ -98,6 +101,7 @@ trait ApiIssueControllerBase extends ControllerBase {
issue, issue,
RepositoryName(repository), RepositoryName(repository),
ApiUser(loginAccount), ApiUser(loginAccount),
issue.assignedUserName.flatMap(getAccountByUserName(_)).map(ApiUser(_)),
getIssueLabels(repository.owner, repository.name, issue.issueId) getIssueLabels(repository.owner, repository.name, issue.issueId)
.map(ApiLabel(_, RepositoryName(repository))) .map(ApiLabel(_, RepositoryName(repository)))
) )

View File

@@ -265,17 +265,19 @@ trait IssuesService {
} }
/** for api /** for api
* @return (issue, issueUser, commentCount) * @return (issue, issueUser, assignedUser)
*/ */
def searchIssueByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)( def searchIssueByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)(
implicit s: Session implicit s: Session
): List[(Issue, Account)] = { ): List[(Issue, Account, Option[Account])] = {
// get issues and comment count and labels // get issues and comment count and labels
searchIssueQueryBase(condition, false, offset, limit, repos) searchIssueQueryBase(condition, false, offset, limit, repos)
.join(Accounts) .join(Accounts)
.on { case t1 ~ t2 ~ i ~ t3 => t3.userName === t1.openedUserName } .on { case t1 ~ t2 ~ i ~ t3 => t3.userName === t1.openedUserName }
.sortBy { case t1 ~ t2 ~ i ~ t3 => i asc } .joinLeft(Accounts)
.map { case t1 ~ t2 ~ i ~ t3 => (t1, t3) } .on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t4.userName === t1.assignedUserName }
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 => i asc }
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 => (t1, t3, t4) }
.list .list
} }

View File

@@ -318,7 +318,8 @@ trait WebHookPullRequestService extends WebHookService {
sender: Account sender: Account
)(implicit s: Session, context: JsonFormat.Context): Unit = { )(implicit s: Session, context: JsonFormat.Context): Unit = {
callWebHookOf(repository.owner, repository.name, WebHook.Issues) { callWebHookOf(repository.owner, repository.name, WebHook.Issues) {
val users = getAccountsByUserNames(Set(repository.owner, issue.openedUserName), Set(sender)) val users =
getAccountsByUserNames(Set(repository.owner, issue.openedUserName) ++ issue.assignedUserName, Set(sender))
for { for {
repoOwner <- users.get(repository.owner) repoOwner <- users.get(repository.owner)
issueUser <- users.get(issue.openedUserName) issueUser <- users.get(issue.openedUserName)
@@ -331,6 +332,7 @@ trait WebHookPullRequestService extends WebHookService {
issue, issue,
RepositoryName(repository), RepositoryName(repository),
ApiUser(issueUser), ApiUser(issueUser),
issue.assignedUserName.flatMap(users.get(_)).map(ApiUser(_)),
getIssueLabels(repository.owner, repository.name, issue.issueId) getIssueLabels(repository.owner, repository.name, issue.issueId)
.map(ApiLabel(_, RepositoryName(repository))) .map(ApiLabel(_, RepositoryName(repository)))
), ),
@@ -502,12 +504,13 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
for { for {
issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString()) issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString())
users = getAccountsByUserNames( users = getAccountsByUserNames(
Set(issue.openedUserName, repository.owner, issueComment.commentedUserName), Set(issue.openedUserName, repository.owner, issueComment.commentedUserName) ++ issue.assignedUserName,
Set(sender) Set(sender)
) )
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)
assignedUser = issue.assignedUserName.flatMap(users.get(_))
labels = getIssueLabels(repository.owner, repository.name, issue.issueId) labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
} yield { } yield {
WebHookIssueCommentPayload( WebHookIssueCommentPayload(
@@ -517,6 +520,7 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
commentUser = commenter, commentUser = commenter,
repository = repository, repository = repository,
repositoryUser = repoOwner, repositoryUser = repoOwner,
assignedUser = assignedUser,
sender = sender, sender = sender,
labels = labels labels = labels
) )
@@ -690,6 +694,7 @@ object WebHookService {
commentUser: Account, commentUser: Account,
repository: RepositoryInfo, repository: RepositoryInfo,
repositoryUser: Account, repositoryUser: Account,
assignedUser: Option[Account],
sender: Account, sender: Account,
labels: List[Label] labels: List[Label]
): WebHookIssueCommentPayload = ): WebHookIssueCommentPayload =
@@ -700,6 +705,7 @@ object WebHookService {
issue, issue,
RepositoryName(repository), RepositoryName(repository),
ApiUser(issueUser), ApiUser(issueUser),
assignedUser.map(ApiUser(_)),
labels.map(ApiLabel(_, RepositoryName(repository))) labels.map(ApiLabel(_, RepositoryName(repository)))
), ),
comment = comment =

View File

@@ -195,6 +195,15 @@ object ApiSpecModels {
issue = issue, issue = issue,
repositoryName = repo1Name, repositoryName = repo1Name,
user = apiUser, user = apiUser,
assignee = Some(apiUser),
labels = List(apiLabel)
)
val apiNotAssignedIssue = ApiIssue(
issue = issue,
repositoryName = repo1Name,
user = apiUser,
assignee = None,
labels = List(apiLabel) labels = List(apiLabel)
) )
@@ -202,6 +211,7 @@ object ApiSpecModels {
issue = issuePR, issue = issuePR,
repositoryName = repo1Name, repositoryName = repo1Name,
user = apiUser, user = apiUser,
assignee = Some(apiUser),
labels = List(apiLabel) labels = List(apiLabel)
) )
@@ -449,12 +459,29 @@ object ApiSpecModels {
|"number":1347, |"number":1347,
|"title":"Found a bug", |"title":"Found a bug",
|"user":$jsonUser, |"user":$jsonUser,
|"assignee":$jsonUser,
|"labels":[$jsonLabel], |"labels":[$jsonLabel],
|"state":"open", |"state":"open",
|"created_at":"2011-04-14T16:00:49Z", |"created_at":"2011-04-14T16:00:49Z",
|"updated_at":"2011-04-14T16:00:49Z", |"updated_at":"2011-04-14T16:00:49Z",
|"body":"I'm having a problem with this.", |"body":"I'm having a problem with this.",
|"id":0, |"id":0,
|"assignees":[$jsonUser],
|"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347"
|}""".stripMargin
val jsonNotAssignedIssue = s"""{
|"number":1347,
|"title":"Found a bug",
|"user":$jsonUser,
|"labels":[$jsonLabel],
|"state":"open",
|"created_at":"2011-04-14T16:00:49Z",
|"updated_at":"2011-04-14T16:00:49Z",
|"body":"I'm having a problem with this.",
|"id":0,
|"assignees":[],
|"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments", |"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347" |"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347"
|}""".stripMargin |}""".stripMargin
@@ -463,12 +490,14 @@ object ApiSpecModels {
|"number":1347, |"number":1347,
|"title":"new-feature", |"title":"new-feature",
|"user":$jsonUser, |"user":$jsonUser,
|"assignee":$jsonUser,
|"labels":[$jsonLabel], |"labels":[$jsonLabel],
|"state":"closed", |"state":"closed",
|"created_at":"2011-04-14T16:00:49Z", |"created_at":"2011-04-14T16:00:49Z",
|"updated_at":"2011-04-14T16:00:49Z", |"updated_at":"2011-04-14T16:00:49Z",
|"body":"Please pull these awesome changes", |"body":"Please pull these awesome changes",
|"id":0, |"id":0,
|"assignees":[$jsonUser],
|"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments", |"comments_url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/issues/1347/comments",
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/pull/1347", |"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/pull/1347",
|"pull_request":{ |"pull_request":{

View File

@@ -34,6 +34,7 @@ class JsonFormatSpec extends FunSuite {
} }
test("apiIssue") { test("apiIssue") {
assert(JsonFormat(apiIssue) == expected(jsonIssue)) assert(JsonFormat(apiIssue) == expected(jsonIssue))
assert(JsonFormat(apiNotAssignedIssue) == expected(jsonNotAssignedIssue))
assert(JsonFormat(apiIssuePR) == expected(jsonIssuePR)) assert(JsonFormat(apiIssuePR) == expected(jsonIssuePR))
} }
test("apiPullRequest") { test("apiPullRequest") {

View File

@@ -118,6 +118,7 @@ class WebHookJsonFormatSpec extends FunSuite {
commentUser = account, commentUser = account,
repository = repositoryInfo, repository = repositoryInfo,
repositoryUser = account, repositoryUser = account,
assignedUser = Some(account),
sender = account, sender = account,
labels = List(label) labels = List(label)
) )