Correctly display "url" and "html_url" of API models

This commit is contained in:
shimamoto
2019-01-11 19:34:37 +09:00
parent 0d2a154622
commit d6f6938465
5 changed files with 16 additions and 35 deletions

View File

@@ -21,22 +21,14 @@ case class ApiCommit(
modified: List[String], modified: List[String],
author: ApiPersonIdent, author: ApiPersonIdent,
committer: ApiPersonIdent committer: ApiPersonIdent
)(repositoryName: RepositoryName, urlIsHtmlUrl: Boolean) )(repositoryName: RepositoryName)
extends FieldSerializable { extends FieldSerializable {
val url = if (urlIsHtmlUrl) { val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
ApiPath(s"/${repositoryName.fullName}/commit/${id}") val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
} else {
ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
}
val html_url = if (urlIsHtmlUrl) {
None
} else {
Some(ApiPath(s"/${repositoryName.fullName}/commit/${id}"))
}
} }
object ApiCommit { object ApiCommit {
def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo, urlIsHtmlUrl: Boolean = false): ApiCommit = { def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = {
val diffs = JGitUtil.getDiffs(git, None, commit.id, false, false) val diffs = JGitUtil.getDiffs(git, None, commit.id, false, false)
ApiCommit( ApiCommit(
id = commit.id, id = commit.id,
@@ -53,8 +45,6 @@ object ApiCommit {
}, },
author = ApiPersonIdent.author(commit), author = ApiPersonIdent.author(commit),
committer = ApiPersonIdent.committer(commit) committer = ApiPersonIdent.committer(commit)
)(repositoryName, urlIsHtmlUrl) )(repositoryName)
} }
def forWebhookPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit =
apply(git, repositoryName, commit, true)
} }

View File

@@ -98,7 +98,7 @@ object ApiCommits {
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"), url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
sha = commitInfo.id, sha = commitInfo.id,
html_url = ApiPath(s"${repositoryName.fullName}/commit/${commitInfo.id}"), html_url = ApiPath(s"${repositoryName.fullName}/commit/${commitInfo.id}"),
comment_url = ApiPath(""), comment_url = ApiPath(""), // TODO no API for commit comment
commit = Commit( commit = Commit(
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"), url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
author = ApiPersonIdent.author(commitInfo), author = ApiPersonIdent.author(commitInfo),

View File

@@ -13,15 +13,11 @@ case class ApiRepository(
`private`: Boolean, `private`: Boolean,
default_branch: String, default_branch: String,
owner: ApiUser owner: ApiUser
)(urlIsHtmlUrl: Boolean) { ) {
val id = 0 // dummy id val id = 0 // dummy id
val forks_count = forks val forks_count = forks
val watchers_count = watchers val watchers_count = watchers
val url = if (urlIsHtmlUrl) { val url = ApiPath(s"/api/v3/repos/${full_name}")
ApiPath(s"/${full_name}")
} else {
ApiPath(s"/api/v3/repos/${full_name}")
}
val http_url = ApiPath(s"/git/${full_name}.git") val http_url = ApiPath(s"/git/${full_name}.git")
val clone_url = ApiPath(s"/git/${full_name}.git") val clone_url = ApiPath(s"/git/${full_name}.git")
val html_url = ApiPath(s"/${full_name}") val html_url = ApiPath(s"/${full_name}")
@@ -33,8 +29,7 @@ object ApiRepository {
repository: Repository, repository: Repository,
owner: ApiUser, owner: ApiUser,
forkedCount: Int = 0, forkedCount: Int = 0,
watchers: Int = 0, watchers: Int = 0
urlIsHtmlUrl: Boolean = false
): ApiRepository = ): ApiRepository =
ApiRepository( ApiRepository(
name = repository.repositoryName, name = repository.repositoryName,
@@ -45,7 +40,7 @@ object ApiRepository {
`private` = repository.isPrivate, `private` = repository.isPrivate,
default_branch = repository.defaultBranch, default_branch = repository.defaultBranch,
owner = owner owner = owner
)(urlIsHtmlUrl) )
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository = def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount) ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
@@ -63,5 +58,5 @@ object ApiRepository {
`private` = false, `private` = false,
default_branch = "master", default_branch = "master",
owner = owner owner = owner
)(true) )
} }

View File

@@ -594,7 +594,7 @@ object WebHookService {
before = ObjectId.toString(oldId), before = ObjectId.toString(oldId),
after = ObjectId.toString(newId), after = ObjectId.toString(newId),
commits = commits.map { commit => commits = commits.map { commit =>
ApiCommit.forWebhookPayload(git, RepositoryName(repositoryInfo), commit) ApiCommit(git, RepositoryName(repositoryInfo), commit)
}, },
repository = ApiRepository(repositoryInfo, repositoryOwner) repository = ApiRepository(repositoryInfo, repositoryOwner)
) )

View File

@@ -182,8 +182,7 @@ object ApiSpecModels {
repository = repository, repository = repository,
owner = apiUser, owner = apiUser,
forkedCount = repositoryInfo.forkedCount, forkedCount = repositoryInfo.forkedCount,
watchers = 0, watchers = 0
urlIsHtmlUrl = false
) )
val apiLabel = ApiLabel( val apiLabel = ApiLabel(
@@ -270,7 +269,7 @@ object ApiSpecModels {
modified = List("README.md"), modified = List("README.md"),
author = ApiPersonIdent.author(commit), author = ApiPersonIdent.author(commit),
committer = ApiPersonIdent.committer(commit) committer = ApiPersonIdent.committer(commit)
)(repo1Name, true) )(repo1Name)
} }
val apiCommits = ApiCommits( val apiCommits = ApiCommits(
@@ -438,7 +437,6 @@ object ApiSpecModels {
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347" |"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347"
|}""".stripMargin |}""".stripMargin
// TODO comments_url is correct?
val jsonIssuePR = s"""{ val jsonIssuePR = s"""{
|"number":1347, |"number":1347,
|"title":"new-feature", |"title":"new-feature",
@@ -456,7 +454,6 @@ object ApiSpecModels {
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/pull/1347"} |"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/pull/1347"}
|}""".stripMargin |}""".stripMargin
// TODO comments_url is correct?
val jsonPullRequest = s"""{ val jsonPullRequest = s"""{
|"number":1347, |"number":1347,
|"state":"closed", |"state":"closed",
@@ -531,7 +528,6 @@ object ApiSpecModels {
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e" |"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e"
|}""".stripMargin |}""".stripMargin
// TODO url is correct?
val jsonCommit = (id: String) => s"""{ val jsonCommit = (id: String) => s"""{
|"id":"$id", |"id":"$id",
|"message":"full message", |"message":"full message",
@@ -541,10 +537,10 @@ object ApiSpecModels {
|"modified":["README.md"], |"modified":["README.md"],
|"author":{"name":"octocat","email":"octocat@example.com","date":"2011-04-14T16:00:49Z"}, |"author":{"name":"octocat","email":"octocat@example.com","date":"2011-04-14T16:00:49Z"},
|"committer":{"name":"octocat","email":"octocat@example.com","date":"2011-04-14T16:00:49Z"}, |"committer":{"name":"octocat","email":"octocat@example.com","date":"2011-04-14T16:00:49Z"},
|"url":"http://gitbucket.exmple.com/octocat/Hello-World/commit/$id" |"url":"http://gitbucket.exmple.com/api/v3/octocat/Hello-World/commits/$id",
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/commit/$id"
|}""".stripMargin |}""".stripMargin
// TODO comment_url
val jsonCommits = s"""{ val jsonCommits = s"""{
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e", |"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
|"sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e", |"sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e",