HomePhabricator
Reading and Writing Paths in Owners

Owners has new owners.search and owners.edit endpoints in HEAD, which you can use to read and write paths. For example, you could use them to synchronize package definitions from an external source.

To read definitions, do something like this:

owners.search
$ cat search.json 
{
  "constraints": {
    "ids": [32]
  },
  "attachments": {
    "paths": true
  }
}
$ arc call-conduit owners.search < search.json

This will give you some output. Here's the full output, for reference:

Full Output
{
  "error": null,
  "errorMessage": null,
  "response": {
    "data": [
      {
        "id": 32,
        "type": "OPKG",
        "phid": "PHID-OPKG-j5c3t7td6n6mpoancgfi",
        "fields": {
          "name": "Directories with \"M\"",
          "description": "",
          "status": "active",
          "owners": [
            
          ],
          "policy": {
            "view": "users",
            "edit": "users"
          },
          "custom.test.text": null,
          "custom.test.int": 22,
          "custom.test.bool": false,
          "custom.test.select": "a",
          "custom.test.remarkup": null,
          "custom.test.users": null,
          "custom.test.date": null,
          "custom.test.header": null,
          "custom.test.link": null
        },
        "attachments": {
          "paths": {
            "paths": [
              {
                "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
                "path": "\/src\/applications\/maniphest\/",
                "excluded": false
              },
              {
                "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
                "path": "\/src\/applications\/macro\/",
                "excluded": false
              }
            ]
          }
        }
      }
    ],
    "query": {
      "queryKey": "7.dKrTvYhwtv"
    },
    "cursor": {
      "limit": 100,
      "after": null,
      "before": null,
      "order": null
    }
  }
}

Here's the interesting part of the output, for these purposes:

...
"data": [
  {
    "id": 32,
    "type": "OPKG",
    "phid": "PHID-OPKG-j5c3t7td6n6mpoancgfi",
    "fields": {
      "name": "Directories with \"M\"",
      "description": "",
      "status": "active",
      "owners": [
        
      ],
      "policy": {
        "view": "users",
        "edit": "users"
      },
      ...
    },
    "attachments": {
      "paths": {
        "paths": [
          {
            "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
            "path": "\/src\/applications\/maniphest\/",
            "excluded": false
          },
          {
            "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
            "path": "\/src\/applications\/macro\/",
            "excluded": false
          }
        ]
      }
    }
  }
],
...

Since we asked for the paths attachment, we got paths data back in the response.

To edit the paths, we'll take that data, add, change or remove any paths, then call owners.edit with the new data, applying it as a transaction of type paths.set. Here, I'm adding a new path (.../multimeter/):

$ cat edit.json
{
  "objectIdentifier": 32,
  "transactions": [
    {
      "type": "paths.set",
      "value": [
        {
          "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
          "path": "\/src\/applications\/maniphest\/",
          "excluded": false
        },
        {
          "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
          "path": "\/src\/applications\/macro\/",
          "excluded": false
        },
        {
          "repositoryPHID": "PHID-REPO-wif5lutk5gn3y6ursk4p",
          "path": "\/src\/applications\/multimeter\/",
          "excluded": false
        }
      ]
    }
  ]
}
$ arc call-conduit owners.edit < edit.json
{
  "error": null,
  "errorMessage": null,
  "response": {
    "object": {
      "id": "32",
      "phid": "PHID-OPKG-j5c3t7td6n6mpoancgfi"
    },
    "transactions": [
      {
        "phid": "PHID-XACT-OPKG-3uymynp4b6s4lui"
      }
    ]
  }
}

Now if we look in the web UI, we can see that the transaction applied as expected. Note "Via Conduit", too.

Screen Shot 2015-12-18 at 4.26.05 AM.png (87×899 px, 17 KB)

Screen Shot 2015-12-18 at 4.26.09 AM.png (207×880 px, 23 KB)

For more information, see:

Written by epriestley on Dec 18 2015, 12:29 PM.
Overengineer
Projects
None
Subscribers
None

Event Timeline