mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 11:36:05 +01:00
Add "X-Github-Event" header, and change interface.
This commit is contained in:
@@ -192,10 +192,11 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
closeIssuesFromMessage(form.message, loginAccount.userName, owner, name)
|
closeIssuesFromMessage(form.message, loginAccount.userName, owner, name)
|
||||||
}
|
}
|
||||||
// call web hook
|
// call web hook
|
||||||
|
// TODO: set action https://developer.github.com/v3/activity/events/types/#pullrequestevent
|
||||||
getWebHookURLs(owner, name) match {
|
getWebHookURLs(owner, name) match {
|
||||||
case webHookURLs if(webHookURLs.nonEmpty) =>
|
case webHookURLs if(webHookURLs.nonEmpty) =>
|
||||||
for(ownerAccount <- getAccountByUserName(owner)){
|
for(ownerAccount <- getAccountByUserName(owner)){
|
||||||
callWebHook(owner, name, webHookURLs,
|
callWebHook("pull_request", webHookURLs,
|
||||||
WebHookPayload(git, loginAccount, mergeBaseRefName, repository, commits.flatten.toList, ownerAccount))
|
WebHookPayload(git, loginAccount, mergeBaseRefName, repository, commits.flatten.toList, ownerAccount))
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
.call.iterator.asScala.map(new CommitInfo(_))
|
.call.iterator.asScala.map(new CommitInfo(_))
|
||||||
|
|
||||||
getAccountByUserName(repository.owner).foreach { ownerAccount =>
|
getAccountByUserName(repository.owner).foreach { ownerAccount =>
|
||||||
callWebHook(repository.owner, repository.name,
|
callWebHook("push",
|
||||||
List(model.WebHook(repository.owner, repository.name, form.url)),
|
List(model.WebHook(repository.owner, repository.name, form.url)),
|
||||||
WebHookPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount)
|
WebHookPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
getWebHookURLs(repository.owner, repository.name) match {
|
getWebHookURLs(repository.owner, repository.name) match {
|
||||||
case webHookURLs if(webHookURLs.nonEmpty) =>
|
case webHookURLs if(webHookURLs.nonEmpty) =>
|
||||||
for(ownerAccount <- getAccountByUserName(repository.owner)){
|
for(ownerAccount <- getAccountByUserName(repository.owner)){
|
||||||
callWebHook(repository.owner, repository.name, webHookURLs,
|
callWebHook("push", webHookURLs,
|
||||||
WebHookPayload(git, loginAccount, headName, repository, List(commit), ownerAccount))
|
WebHookPayload(git, loginAccount, headName, repository, List(commit), ownerAccount))
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ trait WebHookService {
|
|||||||
def deleteWebHookURL(owner: String, repository: String, url :String)(implicit s: Session): Unit =
|
def deleteWebHookURL(owner: String, repository: String, url :String)(implicit s: Session): Unit =
|
||||||
WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete
|
WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete
|
||||||
|
|
||||||
def callWebHook(owner: String, repository: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = {
|
def callWebHook(eventName: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = {
|
||||||
import org.json4s._
|
import org.json4s._
|
||||||
import org.json4s.jackson.Serialization
|
import org.json4s.jackson.Serialization
|
||||||
import org.json4s.jackson.Serialization.{read, write}
|
import org.json4s.jackson.Serialization.{read, write}
|
||||||
@@ -47,6 +47,7 @@ trait WebHookService {
|
|||||||
val f = Future {
|
val f = Future {
|
||||||
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
||||||
val httpPost = new HttpPost(webHookUrl.url)
|
val httpPost = new HttpPost(webHookUrl.url)
|
||||||
|
httpPost.addHeader("X-Github-Event", eventName)
|
||||||
|
|
||||||
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
||||||
params.add(new BasicNameValuePair("payload", json))
|
params.add(new BasicNameValuePair("payload", json))
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
for(pusherAccount <- getAccountByUserName(pusher);
|
for(pusherAccount <- getAccountByUserName(pusher);
|
||||||
ownerAccount <- getAccountByUserName(owner);
|
ownerAccount <- getAccountByUserName(owner);
|
||||||
repositoryInfo <- getRepository(owner, repository, baseUrl)){
|
repositoryInfo <- getRepository(owner, repository, baseUrl)){
|
||||||
callWebHook(owner, repository, webHookURLs,
|
callWebHook("push", webHookURLs,
|
||||||
WebHookPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount))
|
WebHookPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount))
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
|
|||||||
Reference in New Issue
Block a user