mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 06:25:51 +01:00
remove ApiPushCommit class (merge to ApiCommit)
This commit is contained in:
@@ -20,13 +20,21 @@ case class ApiCommit(
|
|||||||
removed: List[String],
|
removed: List[String],
|
||||||
modified: List[String],
|
modified: List[String],
|
||||||
author: ApiPersonIdent,
|
author: ApiPersonIdent,
|
||||||
committer: ApiPersonIdent)(repositoryName:RepositoryName) extends FieldSerializable{
|
committer: ApiPersonIdent)(repositoryName:RepositoryName, urlIsHtmlUrl: Boolean) extends FieldSerializable{
|
||||||
val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}")
|
val url = if(urlIsHtmlUrl){
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}")
|
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{
|
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)
|
val diffs = JGitUtil.getDiffs(git, commit.id, false)
|
||||||
ApiCommit(
|
ApiCommit(
|
||||||
id = commit.id,
|
id = commit.id,
|
||||||
@@ -43,6 +51,7 @@ object ApiCommit{
|
|||||||
},
|
},
|
||||||
author = ApiPersonIdent.author(commit),
|
author = ApiPersonIdent.author(commit),
|
||||||
committer = ApiPersonIdent.committer(commit)
|
committer = ApiPersonIdent.committer(commit)
|
||||||
)(repositoryName)
|
)(repositoryName, urlIsHtmlUrl)
|
||||||
}
|
}
|
||||||
|
def forPushPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = apply(git, repositoryName, commit, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -195,7 +195,7 @@ object WebHookService {
|
|||||||
ref: String,
|
ref: String,
|
||||||
before: String,
|
before: String,
|
||||||
after: String,
|
after: String,
|
||||||
commits: List[ApiPushCommit],
|
commits: List[ApiCommit],
|
||||||
repository: ApiRepository
|
repository: ApiRepository
|
||||||
) extends FieldSerializable with WebHookPayload {
|
) extends FieldSerializable with WebHookPayload {
|
||||||
val compare = commits.size match {
|
val compare = commits.size match {
|
||||||
@@ -216,7 +216,7 @@ object WebHookService {
|
|||||||
ref = refName,
|
ref = refName,
|
||||||
before = ObjectId.toString(oldId),
|
before = ObjectId.toString(oldId),
|
||||||
after = ObjectId.toString(newId),
|
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(
|
repository = ApiRepository.forPushPayload(
|
||||||
repositoryInfo,
|
repositoryInfo,
|
||||||
owner= ApiUser(repositoryOwner))
|
owner= ApiUser(repositoryOwner))
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ 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(
|
val apiPushCommit = ApiCommit(
|
||||||
id = "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
id = "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||||
message = "Update README.md",
|
message = "Update README.md",
|
||||||
timestamp = date1,
|
timestamp = date1,
|
||||||
@@ -93,7 +93,7 @@ class JsonFormatSpec extends Specification {
|
|||||||
removed = Nil,
|
removed = Nil,
|
||||||
modified = List("README.md"),
|
modified = List("README.md"),
|
||||||
author = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1),
|
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"""{
|
val apiPushCommitJson = s"""{
|
||||||
"id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
"id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||||
// "distinct": true,
|
// "distinct": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user