diff --git a/src/main/scala/gitbucket/core/api/ApiCommit.scala b/src/main/scala/gitbucket/core/api/ApiCommit.scala index 95128c1..9229d0c 100644 --- a/src/main/scala/gitbucket/core/api/ApiCommit.scala +++ b/src/main/scala/gitbucket/core/api/ApiCommit.scala @@ -20,13 +20,21 @@ removed: List[String], modified: List[String], author: ApiPersonIdent, - 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}") + committer: ApiPersonIdent)(repositoryName:RepositoryName, urlIsHtmlUrl: Boolean) 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}")) + } } object ApiCommit{ - def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = { + def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo, urlIsHtmlUrl: Boolean = false): ApiCommit = { val diffs = JGitUtil.getDiffs(git, commit.id, false) ApiCommit( id = commit.id, @@ -43,6 +51,7 @@ }, author = ApiPersonIdent.author(commit), committer = ApiPersonIdent.committer(commit) - )(repositoryName) + )(repositoryName, urlIsHtmlUrl) } + def forPushPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = apply(git, repositoryName, commit, true) } diff --git a/src/main/scala/gitbucket/core/api/ApiPushCommit.scala b/src/main/scala/gitbucket/core/api/ApiPushCommit.scala deleted file mode 100644 index 46a99e0..0000000 --- a/src/main/scala/gitbucket/core/api/ApiPushCommit.scala +++ /dev/null @@ -1,39 +0,0 @@ -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/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 2b18cae..da5cdc8 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -195,7 +195,7 @@ ref: String, before: String, after: String, - commits: List[ApiPushCommit], + commits: List[ApiCommit], repository: ApiRepository ) extends FieldSerializable with WebHookPayload { val compare = commits.size match { @@ -216,7 +216,7 @@ ref = refName, before = ObjectId.toString(oldId), after = ObjectId.toString(newId), - commits = commits.map{ commit => ApiPushCommit(git, RepositoryName(repositoryInfo), commit) }, + commits = commits.map{ commit => ApiCommit.forPushPayload(git, RepositoryName(repositoryInfo), commit) }, repository = ApiRepository.forPushPayload( 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 590180d..fe317ce 100644 --- a/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala +++ b/src/test/scala/gitbucket/core/api/JsonFormatSpec.scala @@ -85,7 +85,7 @@ "url": "http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/statuses" }""" - val apiPushCommit = ApiPushCommit( + val apiPushCommit = ApiCommit( id = "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", message = "Update README.md", timestamp = date1, @@ -93,7 +93,7 @@ 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")) + committer = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1))(RepositoryName("baxterthehacker", "public-repo"), true) val apiPushCommitJson = s"""{ "id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", // "distinct": true,