Skip to content

Instantly share code, notes, and snippets.

@gbougeard
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbougeard/86ae26acf7841fb161fb to your computer and use it in GitHub Desktop.
Save gbougeard/86ae26acf7841fb161fb to your computer and use it in GitHub Desktop.
def compare = Action.async {
implicit request =>
play.Logger.debug("compare branches")
val future: Future[(List[String], List[String])] = for {
newRepo <- Gitweb.branches("reservit")
oldRepo <- Gitweb.branches("components")
} yield (Gitweb.extractBranches(newRepo.body), Gitweb.extractBranches(oldRepo.body))
future.map { case (newRepo, oldRepo) =>
val migrated: List[String] = newRepo.intersect(oldRepo)
val notMigrated: List[String] = oldRepo.diff(newRepo)
val onlyNew: List[String] = newRepo.diff(oldRepo)
val futures: List[Future[Res]] = notMigrated.map { branch =>
for {
o <- Gerrit.open(branch)
m <- Gerrit.merged(branch)
} yield Res(branch, o.body, m.body)
}
Future.sequence(futures).map {
results =>
// I want to return this result but I don't find how :(
play.Logger.debug(s"futRes $results")
Ok(views.html.git.compare("Comparaison", newRepo, oldRepo, migrated, onlyNew, notMigrated, results))
}
// I wish I do not return this one
Ok(views.html.git.compare("Comparaison", newRepo, oldRepo, migrated, onlyNew, notMigrated, List()))
}.recover {
case e: Exception =>
play.Logger.error(e.getMessage, e)
Ok(Json.obj("error" -> e.getMessage))
}
}
@mandubian
Copy link

Yes first map should be flatMap...
Concerning Async, having studied it a lot, I can say it works but has limitations and I'm not a so big fan of this kind of approach... it depends on your way of developing actually ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment