Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GitHubPullRequestWebHooksDirectives.scala « server « rorschach « getbootstrap « com « scala « main « src - github.com/twbs/rorschach.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ea7d4752748c774eb408bfcc20fe76c042b87a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.getbootstrap.rorschach.server

import scala.util.{Success, Failure, Try}
import spray.routing.{Directive1, ValidationRejection}
import spray.routing.directives.{BasicDirectives, RouteDirectives}
import org.eclipse.egit.github.core.event.PullRequestPayload
import org.eclipse.egit.github.core.client.GsonUtils

trait GitHubPullRequestWebHooksDirectives {
  import RouteDirectives.reject
  import BasicDirectives.provide
  import HubSignatureDirectives.stringEntityMatchingHubSignature

  def authenticatedPullRequestEvent(secretKey: Array[Byte]): Directive1[PullRequestPayload] = stringEntityMatchingHubSignature(secretKey).flatMap{ entityJsonString =>
    Try { GsonUtils.fromJson(entityJsonString, classOf[PullRequestPayload]) } match {
      case Failure(exc) => reject(ValidationRejection("JSON was either malformed or did not match expected schema!"))
      case Success(payload) => provide(payload)
    }
  }
}

object GitHubPullRequestWebHooksDirectives extends GitHubPullRequestWebHooksDirectives