mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Merge pull request #919 from team-lab/fix-push-commit-url
fix commit url in webhook `push` event.
This commit is contained in:
@@ -20,7 +20,7 @@ case class ApiCommit(
|
|||||||
removed: List[String],
|
removed: List[String],
|
||||||
modified: List[String],
|
modified: List[String],
|
||||||
author: ApiPersonIdent,
|
author: ApiPersonIdent,
|
||||||
committer: ApiPersonIdent)(repositoryName:RepositoryName){
|
committer: ApiPersonIdent)(repositoryName:RepositoryName) extends FieldSerializable{
|
||||||
val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
|
val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
|
val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/main/scala/gitbucket/core/api/ApiPushCommit.scala
Normal file
39
src/main/scala/gitbucket/core/api/ApiPushCommit.scala
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
import gitbucket.core.util.JGitUtil
|
||||||
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
|
import gitbucket.core.util.RepositoryName
|
||||||
|
|
||||||
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
|
import org.eclipse.jgit.api.Git
|
||||||
|
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://developer.github.com/v3/activity/events/types/#pushevent
|
||||||
|
*/
|
||||||
|
case class ApiPushCommit(
|
||||||
|
id: String,
|
||||||
|
message: String,
|
||||||
|
timestamp: Date,
|
||||||
|
added: List[String],
|
||||||
|
removed: List[String],
|
||||||
|
modified: List[String],
|
||||||
|
author: ApiPersonIdent,
|
||||||
|
committer: ApiPersonIdent)(repositoryName:RepositoryName) extends FieldSerializable {
|
||||||
|
val url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
|
||||||
|
}
|
||||||
|
|
||||||
|
object ApiPushCommit{
|
||||||
|
def apply(commit: ApiCommit, repositoryName: RepositoryName): ApiPushCommit = ApiPushCommit(
|
||||||
|
id = commit.id,
|
||||||
|
message = commit.message,
|
||||||
|
timestamp = commit.timestamp,
|
||||||
|
added = commit.added,
|
||||||
|
removed = commit.removed,
|
||||||
|
modified = commit.modified,
|
||||||
|
author = commit.author,
|
||||||
|
committer = commit.committer)(repositoryName)
|
||||||
|
def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiPushCommit =
|
||||||
|
ApiPushCommit(ApiCommit(git, repositoryName, commit), repositoryName)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
/** export fields for json */
|
||||||
|
trait FieldSerializable
|
||||||
@@ -22,7 +22,7 @@ object JsonFormat {
|
|||||||
)
|
)
|
||||||
) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() +
|
) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() +
|
||||||
FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() +
|
FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() +
|
||||||
FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() +
|
FieldSerializer[ApiCommitStatus]() + FieldSerializer[FieldSerializable]() + FieldSerializer[ApiCombinedCommitStatus]() +
|
||||||
FieldSerializer[ApiPullRequest.Commit]() + FieldSerializer[ApiIssue]() + FieldSerializer[ApiComment]()
|
FieldSerializer[ApiPullRequest.Commit]() + FieldSerializer[ApiIssue]() + FieldSerializer[ApiComment]()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ object WebHookService {
|
|||||||
case class WebHookPushPayload(
|
case class WebHookPushPayload(
|
||||||
pusher: ApiUser,
|
pusher: ApiUser,
|
||||||
ref: String,
|
ref: String,
|
||||||
commits: List[ApiCommit],
|
commits: List[ApiPushCommit],
|
||||||
repository: ApiRepository
|
repository: ApiRepository
|
||||||
) extends WebHookPayload
|
) extends WebHookPayload
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ object WebHookService {
|
|||||||
WebHookPushPayload(
|
WebHookPushPayload(
|
||||||
ApiUser(pusher),
|
ApiUser(pusher),
|
||||||
refName,
|
refName,
|
||||||
commits.map{ commit => ApiCommit(git, RepositoryName(repositoryInfo), commit) },
|
commits.map{ commit => ApiPushCommit(git, RepositoryName(repositoryInfo), commit) },
|
||||||
ApiRepository(
|
ApiRepository(
|
||||||
repositoryInfo,
|
repositoryInfo,
|
||||||
owner= ApiUser(repositoryOwner)
|
owner= ApiUser(repositoryOwner)
|
||||||
|
|||||||
@@ -85,6 +85,44 @@ class JsonFormatSpec extends Specification {
|
|||||||
"url": "http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/statuses"
|
"url": "http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/statuses"
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
val apiPushCommit = ApiPushCommit(
|
||||||
|
id = "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||||
|
message = "Update README.md",
|
||||||
|
timestamp = date1,
|
||||||
|
added = Nil,
|
||||||
|
removed = Nil,
|
||||||
|
modified = List("README.md"),
|
||||||
|
author = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1),
|
||||||
|
committer = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1))(RepositoryName("baxterthehacker", "public-repo"))
|
||||||
|
val apiPushCommitJson = s"""{
|
||||||
|
"id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||||
|
// "distinct": true,
|
||||||
|
"message": "Update README.md",
|
||||||
|
"timestamp": "2011-04-14T16:00:49Z",
|
||||||
|
"url": "http://gitbucket.exmple.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||||
|
"author": {
|
||||||
|
"name": "baxterthehacker",
|
||||||
|
"email": "baxterthehacker@users.noreply.github.com",
|
||||||
|
// "username": "baxterthehacker",
|
||||||
|
"date" : "2011-04-14T16:00:49Z"
|
||||||
|
},
|
||||||
|
"committer": {
|
||||||
|
"name": "baxterthehacker",
|
||||||
|
"email": "baxterthehacker@users.noreply.github.com",
|
||||||
|
// "username": "baxterthehacker",
|
||||||
|
"date" : "2011-04-14T16:00:49Z"
|
||||||
|
},
|
||||||
|
"added": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"removed": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"modified": [
|
||||||
|
"README.md"
|
||||||
|
]
|
||||||
|
}"""
|
||||||
|
|
||||||
val apiComment = ApiComment(
|
val apiComment = ApiComment(
|
||||||
id =1,
|
id =1,
|
||||||
user = apiUser,
|
user = apiUser,
|
||||||
@@ -297,6 +335,9 @@ class JsonFormatSpec extends Specification {
|
|||||||
"repository" in {
|
"repository" in {
|
||||||
JsonFormat(repository) must beFormatted(repositoryJson)
|
JsonFormat(repository) must beFormatted(repositoryJson)
|
||||||
}
|
}
|
||||||
|
"apiPushCommit" in {
|
||||||
|
JsonFormat(apiPushCommit) must beFormatted(apiPushCommitJson)
|
||||||
|
}
|
||||||
"apiComment" in {
|
"apiComment" in {
|
||||||
JsonFormat(apiComment) must beFormatted(apiCommentJson)
|
JsonFormat(apiComment) must beFormatted(apiCommentJson)
|
||||||
JsonFormat(apiCommentPR) must beFormatted(apiCommentPRJson)
|
JsonFormat(apiCommentPR) must beFormatted(apiCommentPRJson)
|
||||||
|
|||||||
Reference in New Issue
Block a user