Merge pull request #919 from team-lab/fix-push-commit-url

fix commit url in webhook `push` event.
This commit is contained in:
Naoki Takezoe
2015-10-02 21:13:58 +09:00
6 changed files with 88 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ case class ApiCommit(
removed: List[String],
modified: List[String],
author: ApiPersonIdent,
committer: ApiPersonIdent)(repositoryName:RepositoryName){
committer: ApiPersonIdent)(repositoryName:RepositoryName) extends FieldSerializable{
val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
}

View 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)
}

View File

@@ -0,0 +1,4 @@
package gitbucket.core.api
/** export fields for json */
trait FieldSerializable

View File

@@ -22,7 +22,7 @@ object JsonFormat {
)
) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() +
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]()

View File

@@ -192,7 +192,7 @@ object WebHookService {
case class WebHookPushPayload(
pusher: ApiUser,
ref: String,
commits: List[ApiCommit],
commits: List[ApiPushCommit],
repository: ApiRepository
) extends WebHookPayload
@@ -202,7 +202,7 @@ object WebHookService {
WebHookPushPayload(
ApiUser(pusher),
refName,
commits.map{ commit => ApiCommit(git, RepositoryName(repositoryInfo), commit) },
commits.map{ commit => ApiPushCommit(git, RepositoryName(repositoryInfo), commit) },
ApiRepository(
repositoryInfo,
owner= ApiUser(repositoryOwner)

View File

@@ -85,6 +85,44 @@ class JsonFormatSpec extends Specification {
"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(
id =1,
user = apiUser,
@@ -297,6 +335,9 @@ class JsonFormatSpec extends Specification {
"repository" in {
JsonFormat(repository) must beFormatted(repositoryJson)
}
"apiPushCommit" in {
JsonFormat(apiPushCommit) must beFormatted(apiPushCommitJson)
}
"apiComment" in {
JsonFormat(apiComment) must beFormatted(apiCommentJson)
JsonFormat(apiCommentPR) must beFormatted(apiCommentPRJson)