mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Correctly display "url" and "html_url" of API models
This commit is contained in:
@@ -21,22 +21,14 @@ case class ApiCommit(
|
||||
modified: List[String],
|
||||
author: ApiPersonIdent,
|
||||
committer: ApiPersonIdent
|
||||
)(repositoryName: RepositoryName, urlIsHtmlUrl: Boolean)
|
||||
)(repositoryName: RepositoryName)
|
||||
extends FieldSerializable {
|
||||
val url = if (urlIsHtmlUrl) {
|
||||
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}"))
|
||||
}
|
||||
val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
|
||||
val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
|
||||
}
|
||||
|
||||
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)
|
||||
ApiCommit(
|
||||
id = commit.id,
|
||||
@@ -53,8 +45,6 @@ object ApiCommit {
|
||||
},
|
||||
author = ApiPersonIdent.author(commit),
|
||||
committer = ApiPersonIdent.committer(commit)
|
||||
)(repositoryName, urlIsHtmlUrl)
|
||||
)(repositoryName)
|
||||
}
|
||||
def forWebhookPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit =
|
||||
apply(git, repositoryName, commit, true)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ object ApiCommits {
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||
sha = 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(
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||
author = ApiPersonIdent.author(commitInfo),
|
||||
|
||||
@@ -13,15 +13,11 @@ case class ApiRepository(
|
||||
`private`: Boolean,
|
||||
default_branch: String,
|
||||
owner: ApiUser
|
||||
)(urlIsHtmlUrl: Boolean) {
|
||||
) {
|
||||
val id = 0 // dummy id
|
||||
val forks_count = forks
|
||||
val watchers_count = watchers
|
||||
val url = if (urlIsHtmlUrl) {
|
||||
ApiPath(s"/${full_name}")
|
||||
} else {
|
||||
ApiPath(s"/api/v3/repos/${full_name}")
|
||||
}
|
||||
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
||||
val http_url = ApiPath(s"/git/${full_name}.git")
|
||||
val clone_url = ApiPath(s"/git/${full_name}.git")
|
||||
val html_url = ApiPath(s"/${full_name}")
|
||||
@@ -33,8 +29,7 @@ object ApiRepository {
|
||||
repository: Repository,
|
||||
owner: ApiUser,
|
||||
forkedCount: Int = 0,
|
||||
watchers: Int = 0,
|
||||
urlIsHtmlUrl: Boolean = false
|
||||
watchers: Int = 0
|
||||
): ApiRepository =
|
||||
ApiRepository(
|
||||
name = repository.repositoryName,
|
||||
@@ -45,7 +40,7 @@ object ApiRepository {
|
||||
`private` = repository.isPrivate,
|
||||
default_branch = repository.defaultBranch,
|
||||
owner = owner
|
||||
)(urlIsHtmlUrl)
|
||||
)
|
||||
|
||||
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
||||
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
|
||||
@@ -63,5 +58,5 @@ object ApiRepository {
|
||||
`private` = false,
|
||||
default_branch = "master",
|
||||
owner = owner
|
||||
)(true)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ object WebHookService {
|
||||
before = ObjectId.toString(oldId),
|
||||
after = ObjectId.toString(newId),
|
||||
commits = commits.map { commit =>
|
||||
ApiCommit.forWebhookPayload(git, RepositoryName(repositoryInfo), commit)
|
||||
ApiCommit(git, RepositoryName(repositoryInfo), commit)
|
||||
},
|
||||
repository = ApiRepository(repositoryInfo, repositoryOwner)
|
||||
)
|
||||
|
||||
@@ -182,8 +182,7 @@ object ApiSpecModels {
|
||||
repository = repository,
|
||||
owner = apiUser,
|
||||
forkedCount = repositoryInfo.forkedCount,
|
||||
watchers = 0,
|
||||
urlIsHtmlUrl = false
|
||||
watchers = 0
|
||||
)
|
||||
|
||||
val apiLabel = ApiLabel(
|
||||
@@ -270,7 +269,7 @@ object ApiSpecModels {
|
||||
modified = List("README.md"),
|
||||
author = ApiPersonIdent.author(commit),
|
||||
committer = ApiPersonIdent.committer(commit)
|
||||
)(repo1Name, true)
|
||||
)(repo1Name)
|
||||
}
|
||||
|
||||
val apiCommits = ApiCommits(
|
||||
@@ -438,7 +437,6 @@ object ApiSpecModels {
|
||||
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/issues/1347"
|
||||
|}""".stripMargin
|
||||
|
||||
// TODO comments_url is correct?
|
||||
val jsonIssuePR = s"""{
|
||||
|"number":1347,
|
||||
|"title":"new-feature",
|
||||
@@ -456,7 +454,6 @@ object ApiSpecModels {
|
||||
|"html_url":"http://gitbucket.exmple.com/octocat/Hello-World/pull/1347"}
|
||||
|}""".stripMargin
|
||||
|
||||
// TODO comments_url is correct?
|
||||
val jsonPullRequest = s"""{
|
||||
|"number":1347,
|
||||
|"state":"closed",
|
||||
@@ -531,7 +528,6 @@ object ApiSpecModels {
|
||||
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e"
|
||||
|}""".stripMargin
|
||||
|
||||
// TODO url is correct?
|
||||
val jsonCommit = (id: String) => s"""{
|
||||
|"id":"$id",
|
||||
|"message":"full message",
|
||||
@@ -541,10 +537,10 @@ object ApiSpecModels {
|
||||
|"modified":["README.md"],
|
||||
|"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"},
|
||||
|"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
|
||||
|
||||
// TODO comment_url
|
||||
val jsonCommits = s"""{
|
||||
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
||||
|"sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
||||
|
||||
Reference in New Issue
Block a user