Note:5: Difference between revisions

From notes
No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Note
{{Note
|title=Querying Phabricator using Conduit
|title=Querying Phabricator using Conduit
|tags=Phabricator
}}
}}
Motivation: I would like to be able to visualize the relationships between a set of tasks in Phabricator. That is, for a set of tasks, I want a directed graph showing the parent task/subtask relationships. Bonus if it also shows the tags and/or status on each task. It should be straightforward to display that in a force-directed graph using D3 with information queried using the Conduit Phabricator API.
Motivation: I would like to be able to visualize the relationships between a set of tasks in Phabricator. That is, for a set of tasks, I want a directed graph showing the parent task/subtask relationships. Nodes should be labeled with the task name. Status of the task should be indicted by the node color. And projects associated with the task should be visible as a tooltip. Eventually, highlighting nodes by project should be possible.


https://phabricator.wikimedia.org/api/maniphest.search
It should be straightforward to display that in a force-directed graph using [https://d3js.org/ D3] ([http://www.coppelia.io/2014/07/an-a-to-z-of-extra-features-for-the-d3-force-layout/ examples]) with information queried using the Conduit Phabricator API. The following shows how the required data would be queried.


In the query form, fill in:
Visit https://phabricator.wikimedia.org/conduit/method/maniphest.search/. In the query form, fill in:


{#!:
{| class="wikitable"
{|
! constraints
! constraints
| {"parentIDs": [174043]}
| {"parentIDs": [174043]}
Line 16: Line 16:
| {"projects": true}
| {"projects": true}
|}
|}
}}


This finds all of the subtasks of T174043 and lists their information including the internal ids of the tags, which could then also be queried.
This finds all of the subtasks of T174043 and lists their information including the internal ids of the project tags, which could then also be queried.
 
The names of the projects can then be found by visiting https://phabricator.wikimedia.org/conduit/method/project.search/. In the query form, fill in:
 
{| class="wikitable"
! constraints
| {{"phids": ["PHID-PROJ-m7f7bw4ri4xwgnzi7vnt"]}
|}
 
where the phids are taken from the project tag ids in the results of the previous query.
 
To create a Coduit API token to be able to make the queries above from scripts or programmatically, visit https://phabricator.wikimedia.org/settings/user/<phabricator user id>/page/apitokens/.
 
A PHP program to perform the query above is:
 
<pre>
<?php
 
define('__ROOT__', '/usr/share/libphutil/src/');
require_once(__ROOT__.'__phutil_library_init__.php');
 
 
$api_token = "<insert Conduit API token here>";
$api_parameters = [
  'constraints' => [
      'phids' => [
            'PHID-PROJ-m7f7bw4ri4xwgnzi7vnt'
],
],
];


The code to reproduce this query is generated as follows:
$client = new ConduitClient('https://phabricator.wikimedia.org/');
$client->setConduitToken($api_token);


<code>
$result = $client->callMethodSynchronous('project.search', $api_parameters);
$ echo '{
</pre>
  "constraints": {
    "parentIDs": [
      174043
    ]
  },
  "attachments": {
    "projects": true
  }
}' | arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token <conduit-token> maniphest.search
</code>

Latest revision as of 09:25, 7 September 2017

Author
Created 7 September 2017 01:42:07
Last Modified 7 September 2017 14:25:07
Tags Phabricator

Motivation: I would like to be able to visualize the relationships between a set of tasks in Phabricator. That is, for a set of tasks, I want a directed graph showing the parent task/subtask relationships. Nodes should be labeled with the task name. Status of the task should be indicted by the node color. And projects associated with the task should be visible as a tooltip. Eventually, highlighting nodes by project should be possible.

It should be straightforward to display that in a force-directed graph using D3 (examples) with information queried using the Conduit Phabricator API. The following shows how the required data would be queried.

Visit https://phabricator.wikimedia.org/conduit/method/maniphest.search/. In the query form, fill in:

constraints {"parentIDs": [174043]}
attachments {"projects": true}

This finds all of the subtasks of T174043 and lists their information including the internal ids of the project tags, which could then also be queried.

The names of the projects can then be found by visiting https://phabricator.wikimedia.org/conduit/method/project.search/. In the query form, fill in:

constraints {{"phids": ["PHID-PROJ-m7f7bw4ri4xwgnzi7vnt"]}

where the phids are taken from the project tag ids in the results of the previous query.

To create a Coduit API token to be able to make the queries above from scripts or programmatically, visit https://phabricator.wikimedia.org/settings/user/<phabricator user id>/page/apitokens/.

A PHP program to perform the query above is:

<?php

define('__ROOT__', '/usr/share/libphutil/src/');
require_once(__ROOT__.'__phutil_library_init__.php');


$api_token = "<insert Conduit API token here>";
$api_parameters = [
	  'constraints' => [
		      'phids' => [
			            'PHID-PROJ-m7f7bw4ri4xwgnzi7vnt'
			],
		],
	];

$client = new ConduitClient('https://phabricator.wikimedia.org/');
$client->setConduitToken($api_token);

$result = $client->callMethodSynchronous('project.search', $api_parameters);