Skip to content

Commit

Permalink
Merge pull request #128 from guardian/rt/organisation-webhook
Browse files Browse the repository at this point in the history
Redux: Handle organisation level ping webhooks
  • Loading branch information
rtyley authored Jan 22, 2025
2 parents ea8accf + d99dd2a commit ba0598b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/controllers/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ class Api(
cc: ControllerAppComponents
) extends AbstractAppController(cc) {

def githubHook() = Action.async(parse.json.map(parseGitHubHookJson)) { implicit request =>
val repoId = request.body
def githubHook() = Action.async(parse.json) { implicit request =>
val githubDeliveryGuid = request.headers.get("X-GitHub-Delivery")
logger.info(s"githubHook repo=${repoId.fullName} githubDeliveryGuid=$githubDeliveryGuid xRequestId=$xRequestId")
updateFor(repoId)

val eventOpt: Option[String] = request.headers.get("X-Github-Event")
val repoIdOpt = Option.unless(eventOpt.contains("ping"))(parseGitHubHookJson(request.body))

logger.info(s"githubHook event=${eventOpt.getOrElse("unknown")} repo=${repoIdOpt.map(_.fullName)} githubDeliveryGuid=$githubDeliveryGuid xRequestId=$xRequestId")

repoIdOpt.fold(Future.successful(Ok("pong")))(updateForRepo)
}

def updateRepo(repoId: RepoId) = Action.async { implicit request =>
logger.info(s"updateRepo repo=${repoId.fullName} xRequestId=$xRequestId")
updateFor(repoId)
updateForRepo(repoId)
}

def xRequestId(implicit request: RequestHeader): Option[String] = request.headers.get("X-Request-ID")

def updateFor(repoId: RepoId): Future[Result] = {
def updateForRepo(repoId: RepoId): Future[Result] = {
logger.debug(s"update requested for $repoId")
for {
acceptList <- repoAcceptListService.acceptList()
Expand Down

0 comments on commit ba0598b

Please sign in to comment.