mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
(refs #121)Create WebHookPayload only when web hook has been registered.
This commit is contained in:
@@ -137,13 +137,16 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
|
|||||||
.setMaxCount(3)
|
.setMaxCount(3)
|
||||||
.call.iterator.asScala.map(new CommitInfo(_))
|
.call.iterator.asScala.map(new CommitInfo(_))
|
||||||
|
|
||||||
callWebHook(repository.owner, repository.name,
|
val webHookURLs = getWebHookURLs(repository.owner, repository.name)
|
||||||
WebHookPayload(
|
if(webHookURLs.nonEmpty){
|
||||||
git,
|
callWebHook(repository.owner, repository.name, webHookURLs,
|
||||||
"refs/heads/" + repository.repository.defaultBranch,
|
WebHookPayload(
|
||||||
repository,
|
git,
|
||||||
commits.toList,
|
"refs/heads/" + repository.repository.defaultBranch,
|
||||||
getAccountByUserName(repository.owner).get))
|
repository,
|
||||||
|
commits.toList,
|
||||||
|
getAccountByUserName(repository.owner).get))
|
||||||
|
}
|
||||||
|
|
||||||
flash += "info" -> "Test payload deployed!"
|
flash += "info" -> "Test payload deployed!"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ trait WebHookService {
|
|||||||
def deleteWebHookURL(owner: String, repository: String, url :String): Unit =
|
def deleteWebHookURL(owner: String, repository: String, url :String): Unit =
|
||||||
Query(WebHooks).filter(_.byPrimaryKey(owner, repository, url)).delete
|
Query(WebHooks).filter(_.byPrimaryKey(owner, repository, url)).delete
|
||||||
|
|
||||||
def callWebHook(owner: String, repository: String, payload: WebHookPayload): Unit = {
|
def callWebHook(owner: String, repository: 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}
|
||||||
@@ -41,8 +41,6 @@ trait WebHookService {
|
|||||||
logger.debug("start callWebHook")
|
logger.debug("start callWebHook")
|
||||||
implicit val formats = Serialization.formats(NoTypeHints)
|
implicit val formats = Serialization.formats(NoTypeHints)
|
||||||
|
|
||||||
val webHookURLs = getWebHookURLs(owner, repository)
|
|
||||||
|
|
||||||
if(webHookURLs.nonEmpty){
|
if(webHookURLs.nonEmpty){
|
||||||
val json = write(payload)
|
val json = write(payload)
|
||||||
val httpClient = new DefaultHttpClient()
|
val httpClient = new DefaultHttpClient()
|
||||||
|
|||||||
@@ -129,14 +129,17 @@ class CommitLogHook(owner: String, repository: String, userName: String, baseURL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call web hook
|
// call web hook
|
||||||
val payload = WebHookPayload(
|
val webHookURLs = getWebHookURLs(owner, repository)
|
||||||
git,
|
if(webHookURLs.nonEmpty){
|
||||||
command.getRefName,
|
val payload = WebHookPayload(
|
||||||
getRepository(owner, repository, baseURL).get,
|
git,
|
||||||
newCommits,
|
command.getRefName,
|
||||||
getAccountByUserName(owner).get)
|
getRepository(owner, repository, baseURL).get,
|
||||||
|
newCommits,
|
||||||
|
getAccountByUserName(owner).get)
|
||||||
|
|
||||||
callWebHook(owner, repository, payload)
|
callWebHook(owner, repository, webHookURLs, payload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update repository last modified time.
|
// update repository last modified time.
|
||||||
|
|||||||
Reference in New Issue
Block a user