diff options
author | S Page <spage@wikimedia.org> | 2015-01-19 23:33:58 -0800 |
---|---|---|
committer | S Page <spage@wikimedia.org> | 2015-02-20 10:40:17 -0800 |
commit | fd6451a6bed669051d9c31d9b7b1566f7a2ba7a7 (patch) | |
tree | 7e0628ea3d0071ca4b068de8251801a0c5165d11 | |
parent | d0f4893d45b1504cf28b6c131180d16b4c4850f9 (diff) |
Generate Trello name -> Phabricator PHID mappings
A human being has to map e.g. 'spage1' in Trello to 'spage' on a
Phabricator host in a YAML data file.
Then the script trello_MakePHIDs.py can determine the mapping to
phabricator PHID. It writes out data/trello-scrub_<HOST>.yaml
Change-Id: Ia574d5896bd0ce73355d470b0bb5b0d337ac8f65
-rw-r--r-- | data/trello_names_phab-01.yaml | 10 | ||||
-rw-r--r-- | data/trello_names_phabricator.yaml | 23 | ||||
-rw-r--r-- | trello_makePHIDs.py | 107 |
3 files changed, 140 insertions, 0 deletions
diff --git a/data/trello_names_phab-01.yaml b/data/trello_names_phab-01.yaml new file mode 100644 index 0000000..e3be646 --- /dev/null +++ b/data/trello_names_phab-01.yaml @@ -0,0 +1,10 @@ +# Map usernames in Trello to usernames on phab-01.wmflabs.org +# To get Trello usernames you can use, e.g. +# python export_trello.py print-users --trello-file SOMEtrello_board_export.json +# To get Phabricator usernames you can e.g. go to a project and look for members and CCs. +trelloUserMap: + gtisza: Tgr + legoktm: legoktm + matthewflaschen: mattflaschen + pauginer: + spage1: spage diff --git a/data/trello_names_phabricator.yaml b/data/trello_names_phabricator.yaml new file mode 100644 index 0000000..c75ca22 --- /dev/null +++ b/data/trello_names_phabricator.yaml @@ -0,0 +1,23 @@ + antoinemusso: hashar + benmq: Bencmq + dannyhorn1: DannyH + erikbernhardson: EBernhardson + fflorin: Fabrice_Florin + gdubuc: Gilles + gtisza: Tgr + jaredmzimmerman: Jaredzimmerman-WMF + jonrobson1: Jdlrobson + kaityhammerstein: KHammerstein + legoktm: Legoktm + matthewflaschen: Mattflaschen + matthiasmullie: matthiasmullie + maygalloway: violetto + mholmquist: MarkTraceur + moizsyed_: MSyed + oliverkeyes: Ironholds + pauginer: Pginer-WMF + pginer: Pginer-WMF + quiddity1: Quiddity + spage1: Spage + wctaiwan: wctaiwan + werdnum: werdna diff --git a/trello_makePHIDs.py b/trello_makePHIDs.py new file mode 100644 index 0000000..ab38837 --- /dev/null +++ b/trello_makePHIDs.py @@ -0,0 +1,107 @@ +# Given a manually-maintained .yaml file mapping Trello usernames to Phabricator usernames, +# write out a new "scrub" file mapping Trello usernames to Phabricator PHIDs +# for later use by export_trello.py. +# Documentation at https://www.mediawiki.org/wiki/Phabricator/Trello_to_Phabricator +import argparse +import json +import os.path +import sys +import yaml + +# cburroughs' work +import export_trello + +from phabricator import Phabricator +from wmfphablib import config +from wmfphablib import log +from wmfphablib import vlog +from wmfphablib import errorlog as elog + +class Phidify: + + def __init__(self, args): + self.args = args # FIXME unpack all the args into member variables? + if config.phab_host.find('phab-01') != -1: + self.host = 'phab-01' + elif config.phab_host.find('phabricator.wikimedia.org') != -1: + self.host = 'phabricator' + else: + self.json_error('Unrecognized host %s in config' % (config.phab_host)) + sys.exit(1) + self.userMap = 'data/trello_names_' + self.host + '.yaml' + with open(self.userMap) as f: + yam = yaml.load(f) + self.trelloUserMap = yam['trelloUserMap'] + vlog('Looks like we loaded self.trelloUserMap OK \o/') + + + def connect_to_phab(self): + self.phab = Phabricator(config.phab_user, + config.phab_cert, + config.phab_host) + + self.phab.update_interfaces() + # DEBUG to verify the API connection worked: print phab.user.whoami() + vlog('Looks like we connected to the phab API \o/') + + # Returns dict mapping Trello usernames to phab PHIDs + def get_trelloUserPHIDs(self, trelloUserMap): + self.connect_to_phab() + # trelloUserMap maps trello usernames to phabricator usernames, e.g. + # {'spage1': 'spage', 'Tisza': 'Tgr'} + # We can query to get the PHID of the phab username + # {'spage': 'PHID-USER-rwvw2dwvvjiyrlzy4iho', 'Tisza': 'PHID-USER-66kvyuekkkwkqbpze2uk'} + # we want to return {'spage1' : 'PHID-USER-rwvw2dwvvjiyrlzy4iho'} + + # Get list of unique Phabricator usernames to query, excluding 'None' and empty + lookupNames = [u for u in set(trelloUserMap.values()) if u] + + vlog('get_trelloUserPHIDs querying Phab for %d usernames: %s ' % (len(lookupNames), lookupNames)) + response = self.phab.user.query(usernames = lookupNames) + + # That conduit query returns an array of users' data, each containing phabUsername and phid. + # Turn it into a dict. + phabUserPHIDMap = {} + for userInfo in response: + if userInfo["userName"] and userInfo["phid"]: + phabUserPHIDMap[userInfo["userName"]] = userInfo["phid"] + + # Now create what we want, a dict of trelloUsername -> phid + trelloUserPHIDMap = {} + for trelloUsername, phabUsername in trelloUserMap.iteritems(): + if (phabUsername + and phabUsername in phabUserPHIDMap + and phabUserPHIDMap[phabUsername] + and phabUserPHIDMap[phabUsername] != 'None'): # XXX fires? + trelloUserPHIDMap[trelloUsername] = phabUserPHIDMap[phabUsername] + + return trelloUserPHIDMap + + def writeUserPHIDs(self): + trelloUserPHIDMap = self.get_trelloUserPHIDs(self.trelloUserMap) + fname = 'conf/trello-scrub_' + self.host + '.yaml' + if os.path.exists(fname): + elog('ERROR: ' + fname + ' already exists') + sys.exit(2) + stream = file(fname, 'w') + trelloScrub = { + 'uid-map': trelloUserPHIDMap, + 'uid-cheatsheet': {} + } + # safe_dump() avoids gtisza: !!python/unicode 'PHID-USER-66kvyuekkkwkqbpze2uk' + yaml.safe_dump( trelloScrub, stream, width=30) + log('SUCCESS: wrote trello usernames->PHIDs to ' + fname) + + +def main(): + parser = argparse.ArgumentParser() + + parser.add_argument("-vv", "--verbose-logging", action="store_true", + help="wmfphablib verbose logging") + args = parser.parse_args() + + phidify = Phidify(args) + phidify.writeUserPHIDs() + +if __name__ == '__main__': + main() |