def exportAsGitRepo()

in app/controllers/Export.scala [45:79]


  def exportAsGitRepo(contentId: String): Action[AnyContent] = AuthAction {
    val snapshotIds = config.sourceStacks.flatMap { stack =>
      snapshotApi.listForId(stack.snapshotBucket, contentId).map(stack -> _)
    }

    if(snapshotIds.isEmpty) {
      NotFound(s"$contentId does not have any snapshots")
    } else {
      val dir = Files.createTempDirectory(s"export-$contentId")
      val repo = Git.init().setDirectory(dir.toFile).call()

      snapshotIds.foreach { case(stack, id @ SnapshotId(_, timestamp)) =>
        val snapshot = getSnapshot(stack, id)
        val commitTime = Date.from(snapshot.lastModifiedTime)

        val author = new PersonIdent(new PersonIdent(snapshot.lastModifiedName, snapshot.lastModifiedEmail), commitTime)

        write(dir, repo, filename(stack, "metadata"), snapshot.metadata)
        write(dir, repo, filename(stack, "live"), snapshot.live)
        write(dir, repo, filename(stack, "preview"), snapshot.preview)

        repo.commit()
          .setMessage(s"Snapshot update from $timestamp")
          .setAuthor(author)
          .call()
      }

      val zip = zipFolder(contentId, dir)

      Ok.sendPath(zip, onClose = () => {
        FileUtils.deleteDirectory(dir.toFile)
        Files.delete(zip)
      })
    }
  }