mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 06:25:51 +01:00
date time format to iso-8601 ( fit The GitHub spec )
This commit is contained in:
@@ -36,19 +36,14 @@ trait WebHookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def callWebHook(eventName: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = {
|
def callWebHook(eventName: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = {
|
||||||
import org.json4s._
|
|
||||||
import org.json4s.jackson.Serialization
|
|
||||||
import org.json4s.jackson.Serialization.{read, write}
|
|
||||||
import org.apache.http.client.methods.HttpPost
|
import org.apache.http.client.methods.HttpPost
|
||||||
import org.apache.http.impl.client.HttpClientBuilder
|
import org.apache.http.impl.client.HttpClientBuilder
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
import ExecutionContext.Implicits.global
|
import ExecutionContext.Implicits.global
|
||||||
|
|
||||||
logger.debug("start callWebHook")
|
|
||||||
implicit val formats = Serialization.formats(NoTypeHints)
|
|
||||||
|
|
||||||
if(webHookURLs.nonEmpty){
|
if(webHookURLs.nonEmpty){
|
||||||
val json = write(payload)
|
implicit val formats = jsonFormats
|
||||||
|
val json = org.json4s.jackson.Serialization.write(payload)
|
||||||
val httpClient = HttpClientBuilder.create.build
|
val httpClient = HttpClientBuilder.create.build
|
||||||
|
|
||||||
webHookURLs.foreach { webHookUrl =>
|
webHookURLs.foreach { webHookUrl =>
|
||||||
@@ -151,6 +146,24 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
|
|||||||
|
|
||||||
object WebHookService {
|
object WebHookService {
|
||||||
|
|
||||||
|
val jsonFormats = {
|
||||||
|
import org.json4s._
|
||||||
|
import org.json4s.jackson.Serialization
|
||||||
|
import scala.util.Try
|
||||||
|
import org.joda.time.format._
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
|
val parserISO = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||||
|
Serialization.formats(NoTypeHints) + new CustomSerializer[Date](format =>
|
||||||
|
(
|
||||||
|
{ case JString(s) => Try(parserISO.parseDateTime(s)).toOption.map(_.toDate)
|
||||||
|
.getOrElse(throw new MappingException("Can't convert " + s + " to Date")) },
|
||||||
|
{ case x: Date => JString(parserISO.print(new DateTime(x).withZone(DateTimeZone.UTC))) }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
trait WebHookPayload
|
trait WebHookPayload
|
||||||
|
|
||||||
// https://developer.github.com/v3/activity/events/types/#pushevent
|
// https://developer.github.com/v3/activity/events/types/#pushevent
|
||||||
@@ -244,7 +257,7 @@ object WebHookService {
|
|||||||
case class WebHookCommit(
|
case class WebHookCommit(
|
||||||
id: String,
|
id: String,
|
||||||
message: String,
|
message: String,
|
||||||
timestamp: String, // "2014-10-09T17:10:36-07:00",
|
timestamp: Date,
|
||||||
url: String,
|
url: String,
|
||||||
added: List[String],
|
added: List[String],
|
||||||
removed: List[String],
|
removed: List[String],
|
||||||
@@ -259,7 +272,7 @@ object WebHookService {
|
|||||||
WebHookCommit(
|
WebHookCommit(
|
||||||
id = commit.id,
|
id = commit.id,
|
||||||
message = commit.fullMessage,
|
message = commit.fullMessage,
|
||||||
timestamp = commit.commitTime.toString,
|
timestamp = commit.commitTime,
|
||||||
url = commitUrl,
|
url = commitUrl,
|
||||||
added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath },
|
added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath },
|
||||||
removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath },
|
removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath },
|
||||||
@@ -297,6 +310,7 @@ object WebHookService {
|
|||||||
// https://developer.github.com/v3/repos/
|
// https://developer.github.com/v3/repos/
|
||||||
case class WebHookRepository(
|
case class WebHookRepository(
|
||||||
name: String,
|
name: String,
|
||||||
|
full_name: String,
|
||||||
url: String,
|
url: String,
|
||||||
description: String,
|
description: String,
|
||||||
watchers: Int,
|
watchers: Int,
|
||||||
@@ -308,6 +322,7 @@ object WebHookService {
|
|||||||
def apply(repositoryInfo: RepositoryInfo, owner: WebHookApiUser): WebHookRepository =
|
def apply(repositoryInfo: RepositoryInfo, owner: WebHookApiUser): WebHookRepository =
|
||||||
WebHookRepository(
|
WebHookRepository(
|
||||||
name = repositoryInfo.name,
|
name = repositoryInfo.name,
|
||||||
|
full_name = s"${repositoryInfo.owner}/${repositoryInfo.name}",
|
||||||
url = repositoryInfo.httpUrl,
|
url = repositoryInfo.httpUrl,
|
||||||
description = repositoryInfo.repository.description.getOrElse(""),
|
description = repositoryInfo.repository.description.getOrElse(""),
|
||||||
watchers = 0,
|
watchers = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user