Skip to content

Instantly share code, notes, and snippets.

@robwiss
Last active November 10, 2019 16:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwiss/9c7e2bcf2af063635288 to your computer and use it in GitHub Desktop.
Save robwiss/9c7e2bcf2af063635288 to your computer and use it in GitHub Desktop.
# Copyright 2017 Robert Wissmann
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import json
import subprocess
import argparse
def conduit_projPHID(project):
result = execute_apicall(
'project.query',
{
'names' : [project]
}
)
projPHID = result['response']['data'].keys()[0]
return projPHID
def conduit_tasktransactions(taskids):
result = execute_apicall(
'maniphest.gettasktransactions',
{
'ids': taskids
}
)
tasktransactions = result['response']
return tasktransactions
def conduit_phidlookup(phids):
result = execute_apicall(
'phid.lookup',
{
'names': phids
}
)
phidlookup = { x: result['response'][x]['fullName'] for x in result['response'].keys() }
return phidlookup
def find_first(iterable, f):
for x in iterable:
if f(x):
yield x
raise StopIteration
raise StopIteration
def conduit_tasks(projPHID):
result = execute_apicall(
'maniphest.query',
{
'projectPHIDs': [projPHID],
'order': 'order-priority'
}
)
taskPHIDs = result['response'].keys()
all_tasktransactions = conduit_tasktransactions(
[int(x['id']) for x in result['response'].values()]
)
all_columnPHIDs = set([
[
x['newValue']['columnPHIDs'][0] for x in
find_first(
tasktransactions,
lambda x: x['transactionType'] == 'projectcolumn' and \
x['newValue']['projectPHID'] == projPHID
)
][0] for tasktransactions in all_tasktransactions.values()
])
columnPHID_lookup = conduit_phidlookup(list(all_columnPHIDs))
tasks = []
for taskPHID in result['response'].keys():
this_tasktransactions = all_tasktransactions[result['response'][taskPHID]['id']]
columnPHID = [
x['newValue']['columnPHIDs'][0] for x in
find_first(
tasktransactions,
lambda x: x['transactionType'] == 'projectcolumn' and \
x['newValue']['projectPHID'] == projPHID
)
][0]
task = {
'title': result['response'][taskPHID]['title'],
'status': result['response'][taskPHID]['status'],
'phid': taskPHID,
'column': columnPHID_lookup[columnPHID]
}
tasks.append(task)
return tasks
def execute_apicall(apicall, query):
p = subprocess.Popen(
['arc', 'call-conduit', apicall],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
p.stdin.write(json.dumps(query))
stdout = p.communicate()[0]
p.stdin.close()
p.wait()
if p.returncode != 0:
raise Exception(stdout)
return json.loads(stdout)
def main():
project_name = 'PROJECT'
column_name = 'COLUMN'
# get project PHID
projPHID = conduit_projPHID(project_name)
# get task PHIDs for project
tasks = conduit_tasks(projPHID)
# prune to tasks in certain column
tasks = filter(lambda x: x['column'] == column_name, tasks)
# group tasks by status
by_status = {}
for t in tasks:
if t['status'] in by_status:
by_status[t['status']].append(t)
else:
by_status[t['status']] = [t]
# print report
for status, tasks in by_status.items():
print '%s:' % status
for t in tasks:
print '\t* %s' % t['title']
print
if __name__ == '__main__':
main()
@robla
Copy link

robla commented Feb 19, 2016

Thanks for publishing this! Could you put a copyright license on this code? I'm afraid of looking at it too closely without knowing that.

@jseadragon
Copy link

+1 for the copyright license. Thanks for sharing this!

@robwiss
Copy link
Author

robwiss commented Jun 30, 2017

Updated with a license. I didn't get a notification about the comments, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment