Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.apache.commons.codec.digest.HmacUtils
import org.webjars.WebJarAssetLocator
import org.webjars.play.WebJarsUtil
import play.api.http.HttpErrorHandler
import play.api.libs.json.{JsArray, JsObject, JsValue, Json}
import play.api.libs.json.{JsArray, JsObject, JsValue}
import play.api.mvc.Results.EmptyContent
import play.api.mvc._
import play.api.{Configuration, Environment, Logging}
Expand Down Expand Up @@ -146,7 +146,11 @@ class Application @Inject()
Future.unit
} { prUrl =>
val (ownerRepo, prNum) = GitHub.pullRequestInfo(prUrl)
revalidatePullRequest(ownerRepo, prNum, Some(authInfo)).map(_ => ())
// the CLA is already signed, so don't fail the request when the pull request can't be revalidated
revalidatePullRequest(ownerRepo, prNum, Some(authInfo)).map(_ => ()).recover {
case e: Exception =>
logger.error(s"Error revalidating pull request $ownerRepo#$prNum", e)
}
}
}

Expand Down Expand Up @@ -268,6 +272,9 @@ class Application @Inject()
Redirect(gitHubAppAuthUrl(routes.Application.status(ownerRepo, prNum).absoluteURL()))
case irs: GitHub.IncorrectResponseStatus if irs.actualStatusCode == NOT_FOUND =>
NotFound("Repo Not Found")
case e: Exception =>
logger.error(s"Error revalidating pull request $ownerRepo#$prNum", e)
InternalServerError("The CLA status could not be checked. Please try again later.")
}
}
}
Expand Down Expand Up @@ -461,10 +468,6 @@ class Application @Inject()
}
}
}
}.recover {
case e: Exception =>
logger.error(s"Error revalidating pull request $ownerRepo#$prNum", e)
(Set.empty[GitHub.Contributor], Set.empty[GitHub.Contributor], Json.obj())
}
}

Expand Down
16 changes: 10 additions & 6 deletions app/utils/GitHub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ class GitHub @Inject() (configuration: Configuration, ws: WSClient, messagesApi:
}

private def fetchPagesWithExtractor(path: String, accessToken: String, pageSize: Int = 100)(extractor: JsValue => JsArray): Future[JsArray] = {
fetchPagesForRequest(ws(path, accessToken), pageSize)(extractor)
}

private def fetchPagesForRequest(request: WSRequest, pageSize: Int = 100)(extractor: JsValue => JsArray): Future[JsArray] = {
implicit class Regex(sc: StringContext) {
def r = new scala.util.matching.Regex(sc.parts.mkString, sc.parts.tail.map(_ => "x").toSeq: _*)
}

def req(path: String, accessToken: String, page: Int, pageSize: Int): Future[WSResponse] = {
ws(path, accessToken).withQueryStringParameters("page" -> page.toString, "per_page" -> pageSize.toString).get().flatMap(ok)
def req(page: Int, pageSize: Int): Future[WSResponse] = {
request.withQueryStringParameters("page" -> page.toString, "per_page" -> pageSize.toString).get().flatMap(ok)
}

// get the first page
req(path, accessToken, 1, pageSize).flatMap { response =>
req(1, pageSize).flatMap { response =>
val firstPage = extractor(response.json)

def urlToPage(urlString: String): Int = {
Expand All @@ -151,7 +155,7 @@ class GitHub @Inject() (configuration: Configuration, ws: WSClient, messagesApi:
Range(0, 0)
}

val pagesFutures = pages.map(req(path, accessToken, _, pageSize).map(response => extractor(response.json)))
val pagesFutures = pages.map(req(_, pageSize).map(response => extractor(response.json)))

// assume numeric paging so we can parallelize
Future.foldLeft(pagesFutures)(firstPage)(_ ++ _)
Expand Down Expand Up @@ -366,8 +370,8 @@ class GitHub @Inject() (configuration: Configuration, ws: WSClient, messagesApi:
}

def integrationInstallations(): Future[JsArray] = {
val (ws, _) = jwtWs("app/installations")
ws.get().flatMap(okT[JsArray])
val (request, _) = jwtWs("app/installations")
fetchPagesForRequest(request)(_.as[JsArray])
}

def userInstallations(accessToken: String): Future[JsArray] = {
Expand Down