Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phabricator commandline for creating repository

Tags:

phabricator

I am attempting to use Phabricator's code review feature to grade code submissions by students in a class. The code is committed to a Subversion server in which each student has their own folder under a top level location on the server. For the current classes, I have no control over the root location. If I did, I would just move it so there was a folder that contained all the student repositories for just the classes I need and create a repo in that folder and diffs from lower branches, but at this point I can't.

I've found a way to do almost everything I need to do in Phabricator from the commandline, such as creating each of the student users and generating the diffs. There's only one thing I can't figure out how to do: Create a Repository.

I looked through the options in the help for Phabricator and Arcanist, but I didn't see anything that appeared to do what I needed.

Does anyone know if it's possible to create a repository from the Phabricator or arc commandline? Or in some other automated way?

Thanks!

like image 388
AStouder Avatar asked Jan 11 '14 01:01

AStouder


3 Answers

We don't have a really easy way to do this right now, but you can use arc to call the Conduit API. Pipe a JSON blob into it:

echo '{"name":"repo name", ...}' | arc call-conduit repository.create

You can access /conduit/method/repository.create/ on the web UI for a list of parameters the call accepts.

like image 168
Evan Priestley Avatar answered Jan 03 '23 14:01

Evan Priestley


Update to Evan Priestley's answer: the API method has changed to diffusion.repository.edit.

Developer docs explain how to create and activate a repository here. Copying from that document:

Create a repo:

$ echo '{
  "transactions": [
    {
      "type": "vcs",
      "value": "git"
    },
    {
      "type": "name",
      "value": "Poetry"
    }
  ]
}' | arc call-conduit diffusion.repository.edit

Set remote URLs (if desired) using transaction ID from first response:

$ echo '{
  "transactions": [
    {
      "type": "repository",
      "value": "PHID-REPO-7vm42oayez2rxcmpwhuv"
    },
    {
      "type": "uri",
      "value": "https://github.com/epriestley/poems.git"
    },
    {
      "type": "io",
      "value": "observe"
    }
  ]
}' | arc call-conduit diffusion.uri.edit

Activate repo:

$ echo '{
  "objectIdentifier": "PHID-REPO-7vm42oayez2rxcmpwhuv",
  "transactions": [
    {
      "type": "status",
      "value": "active"
    }
  ]
}' | arc call-conduit diffusion.repository.edit

List of all valid parameters is available in the web UI at /conduit/method/diffusion.repository.edit/.

like image 22
Jack Cushman Avatar answered Jan 03 '23 14:01

Jack Cushman


Because I have VM1 with VCS server (HG) and another VM2 with Phabricator I've made simple scrtip to make from command line repo in VCS and create linked repo in Phab. That is core of script:

#!/bin/bash
REPO=$1
new_URI="http://vcs.domain.com/"$1

create_phab_repo() {
curl http://phabricator.domain.com/api/diffusion.repository.edit \
    -d api.token=api-blablablabla \
    -d transactions[0][type]=vcs \
    -d transactions[0][value]=hg \
    -d transactions[1][type]=name \
    -d transactions[1][value]=$REPO
}


add_phab_repo_URI() {
curl http://phabricator.domain.com/api/diffusion.uri.edit \
    -d api.token=api-blablablabla \
    -d transactions[0][type]=repository \
    -d transactions[0][value]=$2 \
    -d transactions[1][type]=uri \
    -d transactions[1][value]=$new_URI \
    -d transactions[2][type]=io \
    -d transactions[2][value]=observe
}


activate_phab_repo() {
curl http://phabricator.domain.com/api/diffusion.repository.edit \
        -d api.token=api-blablablabla \
        -d transactions[0][type]=status \
        -d transactions[0][value]=active \
        -d objectIdentifier=$1
}

..........

content=$( create_phab_repo | jq -r '.result.object.phid' )

repo_phid=$( curl http://phabricator.domain.com/api/diffusion.repository.edit -d api.token=api-blablablabla -d transactions[0][type]=vcs -d transactions[0][value]=hg -d transactions[1][$REPO | jq -r '.result.object.phid')

add_phab_repo_URI $1 ${repo_phid}

activate_phab_repo ${repo_phid}

Hope this help someone

like image 44
Topper Avatar answered Jan 03 '23 12:01

Topper