src/Pure/Tools/phabricator.scala
changeset 75393 87ebf5a50283
parent 75382 81673c441ce3
child 75394 42267c650205
--- a/src/Pure/Tools/phabricator.scala	Fri Apr 01 11:51:42 2022 +0200
+++ b/src/Pure/Tools/phabricator.scala	Fri Apr 01 17:06:10 2022 +0200
@@ -15,8 +15,7 @@
 import scala.util.matching.Regex
 
 
-object Phabricator
-{
+object Phabricator {
   /** defaults **/
 
   /* required packages */
@@ -32,8 +31,7 @@
       // mercurial build packages
       "make", "gcc", "python", "python2-dev", "python-docutils", "python-openssl")
 
-  def packages: List[String] =
-  {
+  def packages: List[String] = {
     val release = Linux.Release()
     if (release.is_ubuntu_20_04) packages_ubuntu_20_04
     else error("Bad Linux version: expected Ubuntu 20.04 LTS")
@@ -81,8 +79,7 @@
   def global_config_script(
     init: String = "",
     body: String = "",
-    exit: String = ""): String =
-  {
+    exit: String = ""): String = {
 """#!/bin/bash
 """ + (if (init.nonEmpty) "\n" + init else "") + """
 {
@@ -98,16 +95,14 @@
     (if (exit.nonEmpty) "\n" + exit + "\n" else "")
   }
 
-  sealed case class Config(name: String, root: Path)
-  {
+  sealed case class Config(name: String, root: Path) {
     def home: Path = root + Path.explode(phabricator_name())
 
     def execute(command: String): Process_Result =
       Isabelle_System.bash("bin/" + command, cwd = home.file, redirect = true).check
   }
 
-  def read_config(): List[Config] =
-  {
+  def read_config(): List[Config] = {
     if (global_config.is_file) {
       for (entry <- Library.trim_split_lines(File.read(global_config)) if entry.nonEmpty)
       yield {
@@ -120,8 +115,7 @@
     else Nil
   }
 
-  def write_config(configs: List[Config]): Unit =
-  {
+  def write_config(configs: List[Config]): Unit = {
     File.write(global_config,
       configs.map(config => config.name + ":" + config.root.implode).mkString("", "\n", "\n"))
   }
@@ -138,8 +132,8 @@
 
   val isabelle_tool1 =
     Isabelle_Tool("phabricator", "invoke command-line tool within Phabricator home directory",
-      Scala_Project.here, args =>
-    {
+      Scala_Project.here,
+      args => {
       var list = false
       var name = default_name
 
@@ -178,8 +172,7 @@
 
   /** setup **/
 
-  def user_setup(name: String, description: String, ssh_setup: Boolean = false): Unit =
-  {
+  def user_setup(name: String, description: String, ssh_setup: Boolean = false): Unit = {
     if (!Linux.user_exists(name)) {
       Linux.user_add(name, description = description, system = true, ssh_setup = ssh_setup)
     }
@@ -192,8 +185,8 @@
   def command_setup(name: String,
     init: String = "",
     body: String = "",
-    exit: String = ""): Path =
-  {
+    exit: String = ""
+  ): Path = {
     val command = Path.explode("/usr/local/bin") + Path.basic(name)
     File.write(command, global_config_script(init = init, body = body, exit = exit))
     Isabelle_System.chmod("755", command)
@@ -201,11 +194,9 @@
     command
   }
 
-  def mercurial_setup(mercurial_source: String, progress: Progress = new Progress): Unit =
-  {
+  def mercurial_setup(mercurial_source: String, progress: Progress = new Progress): Unit = {
     progress.echo("\nMercurial installation from source " + quote(mercurial_source) + " ...")
-    Isabelle_System.with_tmp_dir("mercurial")(tmp_dir =>
-    {
+    Isabelle_System.with_tmp_dir("mercurial")(tmp_dir => {
       val archive =
         if (Url.is_wellformed(mercurial_source)) {
           val archive = tmp_dir + Path.basic("mercurial.tar.gz")
@@ -228,8 +219,8 @@
     repo: String = "",
     package_update: Boolean = false,
     mercurial_source: String = "",
-    progress: Progress = new Progress): Unit =
-  {
+    progress: Progress = new Progress
+  ): Unit = {
     /* system environment */
 
     Linux.check_system_root()
@@ -345,8 +336,7 @@
     Linux.service_restart("mysql")
 
 
-    def mysql_conf(R: Regex, which: String): String =
-    {
+    def mysql_conf(R: Regex, which: String): String = {
       val conf = Path.explode("/etc/mysql/debian.cnf")
       split_lines(File.read(conf)).collectFirst({ case R(a) => a }) match {
         case Some(res) => res
@@ -528,8 +518,8 @@
 
   val isabelle_tool2 =
     Isabelle_Tool("phabricator_setup", "setup Phabricator server on Ubuntu Linux",
-      Scala_Project.here, args =>
-    {
+      Scala_Project.here,
+      args => {
       var mercurial_source = ""
       var repo = ""
       var package_update = false
@@ -595,8 +585,8 @@
     name: String = default_name,
     config_file: Option[Path] = None,
     test_user: String = "",
-    progress: Progress = new Progress): Unit =
-  {
+    progress: Progress = new Progress
+  ): Unit = {
     Linux.check_system_root()
 
     val config = get_config(name)
@@ -604,8 +594,7 @@
 
     val mail_config = config_file getOrElse default_config_file
 
-    def setup_mail: Unit =
-    {
+    def setup_mail: Unit = {
       progress.echo("Using mail configuration from " + mail_config)
       config.execute("config set cluster.mailers --stdin < " + File.bash_path(mail_config))
 
@@ -636,8 +625,8 @@
 
   val isabelle_tool3 =
     Isabelle_Tool("phabricator_setup_mail", "setup mail for one Phabricator installation",
-      Scala_Project.here, args =>
-    {
+      Scala_Project.here,
+      args => {
       var test_user = ""
       var name = default_name
       var config_file: Option[Path] = None
@@ -679,8 +668,7 @@
   def conf_ssh_port(port: Int): String =
     if (port == SSH.default_port) "#Port " + SSH.default_port else "Port " + port
 
-  def read_ssh_port(conf: Path): Int =
-  {
+  def read_ssh_port(conf: Path): Int = {
     val lines = split_lines(File.read(conf))
     val ports =
       lines.flatMap({
@@ -695,8 +683,7 @@
     }
   }
 
-  def write_ssh_port(conf: Path, port: Int): Boolean =
-  {
+  def write_ssh_port(conf: Path, port: Int): Boolean = {
     val old_port = read_ssh_port(conf)
     if (old_port == port) false
     else {
@@ -713,8 +700,8 @@
   def phabricator_setup_ssh(
     server_port: Int = default_server_port,
     system_port: Int = default_system_port,
-    progress: Progress = new Progress): Unit =
-  {
+    progress: Progress = new Progress
+  ): Unit = {
     Linux.check_system_root()
 
     val configs = read_config()
@@ -799,8 +786,8 @@
 
   val isabelle_tool4 =
     Isabelle_Tool("phabricator_setup_ssh", "setup ssh service for all Phabricator installations",
-      Scala_Project.here, args =>
-    {
+      Scala_Project.here,
+      args => {
       var server_port = default_server_port
       var system_port = default_system_port
 
@@ -836,8 +823,7 @@
 
   /** conduit API **/
 
-  object API
-  {
+  object API {
     /* user information */
 
     sealed case class User(
@@ -845,8 +831,8 @@
       phid: String,
       name: String,
       real_name: String,
-      roles: List[String])
-    {
+      roles: List[String]
+    ) {
       def is_valid: Boolean =
         roles.contains("verified") &&
         roles.contains("approved") &&
@@ -866,13 +852,12 @@
       callsign: String,
       short_name: String,
       importing: Boolean,
-      ssh_url: String)
-    {
+      ssh_url: String
+    ) {
       def is_hg: Boolean = vcs == VCS.hg
     }
 
-    object VCS extends Enumeration
-    {
+    object VCS extends Enumeration {
       val hg, git, svn = Value
       def read(s: String): Value =
         try { withName(s) }
@@ -888,8 +873,7 @@
 
     /* result with optional error */
 
-    sealed case class Result(result: JSON.T, error: Option[String])
-    {
+    sealed case class Result(result: JSON.T, error: Option[String]) {
       def ok: Boolean = error.isEmpty
       def get: JSON.T = if (ok) result else Exn.error(error.get)
 
@@ -899,8 +883,7 @@
       def get_string: String = get_value(JSON.Value.String.unapply)
     }
 
-    def make_result(json: JSON.T): Result =
-    {
+    def make_result(json: JSON.T): Result = {
       val result = JSON.value(json, "result").getOrElse(JSON.Object.empty)
       val error_info = JSON.string(json, "error_info")
       val error_code = JSON.string(json, "error_code")
@@ -914,8 +897,7 @@
       new API(user, host, port)
   }
 
-  final class API private(ssh_user: String, ssh_host: String, ssh_port: Int)
-  {
+  final class API private(ssh_user: String, ssh_host: String, ssh_port: Int) {
     /* connection */
 
     require(ssh_host.nonEmpty && ssh_port >= 0, "bad ssh host or port")
@@ -929,10 +911,8 @@
 
     /* execute methods */
 
-    def execute_raw(method: String, params: JSON.T = JSON.Object.empty): JSON.T =
-    {
-      Isabelle_System.with_tmp_file("params", "json")(params_file =>
-      {
+    def execute_raw(method: String, params: JSON.T = JSON.Object.empty): JSON.T = {
+      Isabelle_System.with_tmp_file("params", "json")(params_file => {
         File.write(params_file, JSON.Format(JSON.Object("params" -> JSON.Format(params))))
         val result =
           Isabelle_System.bash(
@@ -946,8 +926,10 @@
       API.make_result(execute_raw(method, params = params))
 
     def execute_search[A](
-      method: String, params: JSON.Object.T, unapply: JSON.T => Option[A]): List[A] =
-    {
+      method: String,
+      params: JSON.Object.T,
+      unapply: JSON.T => Option[A]
+    ): List[A] = {
       val results = new mutable.ListBuffer[A]
       var after = ""
 
@@ -974,8 +956,8 @@
     def get_users(
       all: Boolean = false,
       phid: String = "",
-      name: String = ""): List[API.User] =
-    {
+      name: String = ""
+    ): List[API.User] = {
       val constraints: JSON.Object.T =
         (for { (key, value) <- List("phids" -> phid, "usernames" -> name) if value.nonEmpty }
           yield (key, List(value))).toMap
@@ -1005,8 +987,8 @@
       all: Boolean = false,
       phid: String = "",
       callsign: String = "",
-      short_name: String = ""): List[API.Repository] =
-    {
+      short_name: String = ""
+    ): List[API.Repository] = {
       val constraints: JSON.Object.T =
         (for {
           (key, value) <- List("phids" -> phid, "callsigns" -> callsign, "shortNames" -> short_name)
@@ -1051,8 +1033,8 @@
       short_name: String = "",  // unique name
       description: String = "",
       public: Boolean = false,
-      vcs: API.VCS.Value = API.VCS.hg): API.Repository =
-    {
+      vcs: API.VCS.Value = API.VCS.hg
+    ): API.Repository = {
       require(name.nonEmpty, "bad repository name")
 
       val transactions =