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: 47ce9fc557c1b2eab2e924a290a19eb293b94806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.getbootstrap.rorschach.server

import scala.util.{Success, Failure, Try}
import spray.routing.{Directive1, ValidationRejection}
import spray.routing.directives.{BasicDirectives, RouteDirectives}

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