diff --git a/src/main/scala/gitbucket/core/api/ApiPushCommit.scala b/src/main/scala/gitbucket/core/api/ApiPushCommit.scala new file mode 100644 index 0000000..46a99e0 --- /dev/null +++ b/src/main/scala/gitbucket/core/api/ApiPushCommit.scala @@ -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) +} diff --git a/src/main/scala/gitbucket/core/api/FieldSerializable.scala b/src/main/scala/gitbucket/core/api/FieldSerializable.scala new file mode 100644 index 0000000..706bf9c --- /dev/null +++ b/src/main/scala/gitbucket/core/api/FieldSerializable.scala @@ -0,0 +1,4 @@ +package gitbucket.core.api + +/** export fields for json */ +trait FieldSerializable diff --git a/src/main/scala/gitbucket/core/api/JsonFormat.scala b/src/main/scala/gitbucket/core/api/JsonFormat.scala index a14a116..fe9e3e5 100644 --- a/src/main/scala/gitbucket/core/api/JsonFormat.scala +++ b/src/main/scala/gitbucket/core/api/JsonFormat.scala @@ -22,7 +22,7 @@ ) ) + 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]() diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 04d4d50..d0df746 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -192,7 +192,7 @@ case class WebHookPushPayload( pusher: ApiUser, ref: String, - commits: List[ApiCommit], + commits: List[ApiPushCommit], repository: ApiRepository ) extends WebHookPayload @@ -202,7 +202,7 @@ 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) diff --git a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala index 6308d26..0ed5c33 100644 --- a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala +++ b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala @@ -85,6 +85,44 @@ "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, @@ -262,6 +300,9 @@ "repository" in { JsonFormat(repository) must beFormatted(repositoryJson) } + "apiPushCommit" in { + JsonFormat(apiPushCommit) must beFormatted(apiPushCommitJson) + } "apiComment" in { JsonFormat(apiComment) must beFormatted(apiCommentJson) }