# HG changeset patch # User wenzelm # Date 1576616784 -3600 # Node ID 3fdd0b93fa4b55ccd9fa2ff3b4b948258713ea84 # Parent ca794da3bb1d61c5987ad7f1e564780a19188e8d clarified signature; more operations; diff -r ca794da3bb1d -r 3fdd0b93fa4b src/Pure/Tools/phabricator.scala --- a/src/Pure/Tools/phabricator.scala Tue Dec 17 21:19:46 2019 +0100 +++ b/src/Pure/Tools/phabricator.scala Tue Dec 17 22:06:24 2019 +0100 @@ -872,6 +872,37 @@ lazy val user_phid: String = execute("user.whoami").get_value(JSON.string(_, "phid")) lazy val user_name: String = execute("user.whoami").get_value(JSON.string(_, "userName")) + + def create_repository( + name: String, + callsign: String = "", // unique name, UPPERCASE + short_name: String = "", // unique name + description: String = "", + public: Boolean = false, + vcs: API.VCS.Value = API.VCS.hg): String = + { + require(name.nonEmpty) + + val transactions = + API.edits("vcs", vcs.toString) ::: + API.edits("name", name) ::: + API.opt_edits("callsign", proper_string(callsign)) ::: + API.opt_edits("shortName", proper_string(short_name)) ::: + API.opt_edits("description", proper_string(description)) ::: + (if (public) Nil + else API.edits("view", user_phid) ::: API.edits("policy.push", user_phid)) ::: + API.edits("status", "active") + + val repo_phid = + execute("diffusion.repository.edit", + params = JSON.Object("transactions" -> transactions)) + .get_value(JSON.value(_, "object", JSON.string(_, "phid"))) + + execute("diffusion.looksoon", + params = JSON.Object("repositories" -> List(repo_phid))).get + + repo_phid + } } object API @@ -955,13 +986,10 @@ val hg, git, svn = Value } - def edit(typ: String, value: JSON.T): JSON.Object.T = - JSON.Object("type" -> typ, "value" -> value) - - def edits(typ: String, value: Option[JSON.T]): List[JSON.Object.T] = - List(edit(typ, value)) + def edits(typ: String, value: JSON.T): List[JSON.Object.T] = + List(JSON.Object("type" -> typ, "value" -> value)) def opt_edits(typ: String, value: Option[JSON.T]): List[JSON.Object.T] = - value.map(edit(typ, _)).toList + value.toList.flatMap(edits(typ, _)) } }