Skip to content

Commit

Permalink
Merge pull request #216 from ivan-cukic/develop
Browse files Browse the repository at this point in the history
Phabricator service: Adding option to filter on users and projects
  • Loading branch information
ralphbean committed Apr 20, 2015
2 parents 07ef02d + 15a6a43 commit 1f1f4f0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
30 changes: 29 additions & 1 deletion bugwarrior/docs/services/phabricator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,41 @@ Here's an example of an Phabricator target::
.. note::

Although this may not look like enough information for us
to gather information from Phabricator,
to gather information from Phabricator,
but credentials will be gathered from the user's ``~/.arcrc``.

The above example is the minimum required to import issues from
Phabricator. You can also feel free to use any of the
configuration options described in :ref:`common_configuration_options`.

Service Features
----------------

If you have dozens of users and projects, you might want to
pull the tasks and code review requests only for the specific ones.

If you want to show only the tasks related to a specific user,
you just need to add its PHID to the service configuration like this::

phabricator.user_phids = PHID-USER-ab12c3defghi45jkl678

If you want to show only the tasks and diffs related to a specific project or a repository,
just add their PHIDs to the service configuration::

phabricator.project_phids = PHID-PROJ-ab12c3defghi45jkl678,PHID-REPO-ab12c3defghi45jkl678

Both ``phabricator.user_phids`` and ``phabricator.project_phids`` accept
a comma-separated (no spaces) list of PHIDs.

If you specify both, you will get tasks and diffs that match one **or** the other.

If you do not know PHID of a user, project or repository,
you can find it out by querying Phabricator Conduit
(``https://YOUR_PHABRICATOR_HOST/conduit/``) --
the methods which return the needed info are ``user.query``, ``project.query``
and ``repository.query`` respectively.


Provided UDA Fields
-------------------

Expand Down
2 changes: 1 addition & 1 deletion bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'activecollab': 'bugwarrior.services.activecollab:ActiveCollabService',
'jira': 'bugwarrior.services.jira:JiraService',
'megaplan': 'bugwarrior.services.megaplan:MegaplanService',
'phabricator': 'bugwarrior.services.phabricator:PhabricatorService',
'phabricator': 'bugwarrior.services.phab:PhabricatorService',
'versionone': 'bugwarrior.services.versionone:VersionOneService',
})

Expand Down
62 changes: 61 additions & 1 deletion bugwarrior/services/phab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# This comes from PyPI
import phabricator


class PhabricatorIssue(Issue):
TITLE = 'phabricatortitle'
URL = 'phabricatorurl'
Expand Down Expand Up @@ -63,6 +62,14 @@ def __init__(self, *args, **kw):
# These reads in login credentials from ~/.arcrc
self.api = phabricator.Phabricator()

self.shown_user_phids = self.config_get_default("user_phids", "").strip().split(',')
if self.shown_user_phids[0] == "":
self.shown_user_phids = None

self.shown_project_phids = self.config_get_default("project_phids", "").strip().split(',')
if self.shown_project_phids[0] == "":
self.shown_project_phids = None

def issues(self):

# TODO -- get a list of these from the api
Expand All @@ -74,17 +81,41 @@ def issues(self):
log.name(self.target).info("Found %i issues" % len(issues))

for phid, issue in issues:

project = self.target # a sensible default
try:
project = projects.get(issue['projectPHIDs'][0], project)
except IndexError:
pass

this_issue_matches = False

if self.shown_user_phids is None and self.shown_project_phids is None:
this_issue_matches = True

if self.shown_user_phids is not None:
# Checking whether authorPHID, ccPHIDs, ownerPHID
# are intersecting with self.shown_user_phids
issue_relevant_to = set(issue['ccPHIDs'] + [issue['ownerPHID'], issue['authorPHID']])
if len(issue_relevant_to.intersection(self.shown_user_phids)) > 0:
this_issue_matches = True

if self.shown_project_phids is not None:
# Checking whether projectPHIDs
# is intersecting with self.shown_project_phids
issue_relevant_to = set(issue['projectPHIDs'])
if len(issue_relevant_to.intersection(self.shown_user_phids)) > 0:
this_issue_matches = True

if not this_issue_matches:
continue

extra = {
'project': project,
'type': 'issue',
#'annotations': self.annotations(phid, issue)
}

yield self.get_issue_for_record(issue, extra)

diffs = self.api.differential.query(status='status-open')
Expand All @@ -93,12 +124,41 @@ def issues(self):
log.name(self.target).info("Found %i differentials" % len(diffs))

for diff in list(diffs):

project = self.target # a sensible default
try:
project = projects.get(issue['projectPHIDs'][0], project)
except IndexError:
pass

this_diff_matches = False

if self.shown_user_phids is None and self.shown_project_phids is None:
this_diff_matches = True

if self.shown_user_phids is not None:
# Checking whether authorPHID, ccPHIDs, ownerPHID
# are intersecting with self.shown_user_phids
diff_relevant_to = set(diff['reviewers'] + [diff['authorPHID']])
if len(diff_relevant_to.intersection(self.shown_user_phids)) > 0:
this_diff_matches = True

if self.shown_project_phids is not None:
# Checking whether projectPHIDs
# is intersecting with self.shown_project_phids
phabricator_projects = []
try:
phabricator_projects = diff['phabricator:projects']
except KeyError:
pass

diff_relevant_to = set(phabricator_projects + [diff['repositoryPHID']])
if len(diff_relevant_to.intersection(self.shown_user_phids)) > 0:
this_diff_matches = True

if not this_diff_matches:
continue

extra = {
'project': project,
'type': 'pull_request',
Expand Down

0 comments on commit 1f1f4f0

Please sign in to comment.