diff options
author | cpettet <rush@wikimedia.org> | 2014-12-14 19:30:33 -0600 |
---|---|---|
committer | cpettet <rush@wikimedia.org> | 2014-12-14 19:31:23 -0600 |
commit | d33e8c56e65856a410fea855b6b5e9b34b5f3f6a (patch) | |
tree | 30080e1059c4a2f60f4927ec3452d634713671aa | |
parent | 08ca3e6d00133740c9adb62233f97bb802c6889f (diff) |
add update job that appends a literal reference
to refer/referd to tasks for RT
__This is not idempotent__
-rwxr-xr-x | rt_update_tasks.py | 29 | ||||
-rwxr-xr-x | rt_update_tasks_references.py | 117 | ||||
-rwxr-xr-x | wmfphablib/phabdb.py | 20 | ||||
-rwxr-xr-x | wmfphablib/rtlib.py | 1 |
4 files changed, 153 insertions, 14 deletions
diff --git a/rt_update_tasks.py b/rt_update_tasks.py index 47921d4..d8adc5c 100755 --- a/rt_update_tasks.py +++ b/rt_update_tasks.py @@ -40,24 +40,29 @@ def update(bugid): blocker_ref = extref(bugid) tinfo = json.loads(header[0][0]) + + upstream = [] - if 'blocks' not in tinfo['links']: - log("%s doesn't block anything" % (str(bugid),)) - return True + if 'parent' in tinfo['links']: + upstream += tinfo['links']['parent'] + + if 'blocks' in tinfo['links']: + upstream += tinfo['links']['blocks'] - for b in tinfo['links']['blocks']: - blocked_ref = extref(b) - log("%s is blocking %s" % (blocker_ref, - blocked_ref)) - if blocked_ref: - log(phabdb.set_blocked_task(blocker_ref, + if upstream: + for b in upstream: + blocked_ref = extref(b) + log("%s is blocking %s" % (blocker_ref, + blocked_ref)) + if blocked_ref: + log(phabdb.set_blocked_task(blocker_ref, blocked_ref)) - else: - log('%s is missing blocker %s' % (blocked_ref, + else: + log('%s is missing blocker %s' % (blocked_ref, blocker_ref)) - blocks = phabdb.get_tasks_blocked(blocker_ref) vlog('%s is blocking %s' % (blocker_ref, str(blocks))) + current = pmig.sql_x("SELECT * \ from task_relations \ WHERE id = %s", bugid) diff --git a/rt_update_tasks_references.py b/rt_update_tasks_references.py new file mode 100755 index 0000000..88e6fad --- /dev/null +++ b/rt_update_tasks_references.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +import sys +import time +import json +import multiprocessing +from wmfphablib import phabdb +from wmfphablib import log +from wmfphablib import vlog +from wmfphablib import errorlog as elog +from wmfphablib import now +from wmfphablib import return_bug_list +from wmfphablib import rtlib +from wmfphablib import ipriority +from wmfphablib import config + + +def update(bugid): + + pmig = phabdb.phdb(db=config.rtmigrate_db) + + epriority = pmig.sql_x("SELECT priority \ + from task_relations \ + where id = %s", bugid) + + if epriority and epriority[0] == ipriority['update_success']: + log('skipping %s as blockers already updated' % (bugid,)) + return True + + query = "SELECT header FROM rt_meta WHERE id = %s" + header = pmig.sql_x(query, (bugid,)) + if not header: + elog('no header found for %s' % (bugid,)) + return False + + def extref(ticket): + refid = phabdb.reference_ticket("%s%s" % (rtlib.prepend, ticket)) + if not refid: + return '' + return refid[0] + + blocker_ref = extref(bugid) + tinfo = json.loads(header[0][0]) + + if 'refers_to' in tinfo['links'] and tinfo['links']['refers_to']: + refers_to = [] + for b in tinfo['links']['refers_to']: + refersto_ref = extref(b) + if not refersto_ref: + continue + refers_to.append(phabdb.get_task_id_by_phid(refersto_ref)) + if refers_to: + refers_block = '\n\n**Refers To:**\n' + refers_block += '\n'.join(["{T%s}" % r for r in refers_to]) + log(phabdb.append_to_task_description(blocker_ref, + refers_block)) + + if 'refers_toby' in tinfo['links'] and tinfo['links']['refers_toby']: + refers_toby = [] + for b in tinfo['links']['refers_toby']: + referstoby_ref = extref(b) + if not referstoby_ref: + continue + refers_toby.append(phabdb.get_task_id_by_phid(referstoby_ref)) + if refers_toby: + refer_block = '\n\n**Referred To By:**\n' + refer_block += '\n'.join(["{T%s}" % r for r in refers_toby]) + log(phabdb.append_to_task_description(blocker_ref, + refer_block)) + return True + + +def run_update(bugid, tries=1): + if tries == 0: + pmig = phabdb.phdb(db=config.rtmigrate_db) + current = pmig.sql_x("SELECT * from \ + task_relations \ + where id = %s", bugid) + if current: + pmig.sql_x("UPDATE task_relations \ + SET priority=%s, \ + blocks=%s, \ + modified=%s \ + WHERE id = %s", + (ipriority['creation_failed'], + json.dumps([]), now(), bugid)) + else: + sql = "INSERT INTO task_relations \ + (id, priority, blocks, modified) \ + VALUES (%s, %s, %s, %s)" + pmig.sql_x(sql, (bugid, + ipriority['creation_failed'], + json.dumps([]), + now())) + pmig.close() + elog('final fail to update %s' % (bugid,)) + return False + try: + return update(bugid) + except Exception as e: + import traceback + tries -= 1 + time.sleep(5) + traceback.print_exc(file=sys.stdout) + elog('failed to update %s' % (bugid,)) + return run_update(bugid, tries=tries) + +def main(): + bugs = return_bug_list() + from multiprocessing import Pool + pool = Pool(processes=int(config.bz_updatemulti)) + _ = pool.map(run_update, bugs) + complete = len(filter(bool, _)) + failed = len(_) - complete + print '%s completed %s, failed %s' % (sys.argv[0], complete, failed) + +if __name__ == '__main__': + main() diff --git a/wmfphablib/phabdb.py b/wmfphablib/phabdb.py index 33d00cf..d498f11 100755 --- a/wmfphablib/phabdb.py +++ b/wmfphablib/phabdb.py @@ -418,6 +418,22 @@ def set_task_ctime(taskPHID, ctime): p.close() +def append_to_task_description(taskPHID, text): + """append text to task description + :param taskPHID: str + """ + description = get_task_description(taskPHID) + if not description: + return + newdescript = description + text + p = phdb(db='phabricator_maniphest', + user=phuser_user, + passwd=phuser_passwd) + p.sql_x("UPDATE maniphest_task \ + SET description=%s \ + WHERE phid=%s", (newdescript, taskPHID)) + p.close() + def get_task_description(taskPHID): """get task description :param taskPHID: str @@ -915,7 +931,7 @@ def get_blocking_tasks(taskPHID): return '' return _ -def get_task_id_by_phid(taskid): +def get_task_id_by_phid(phid): """ get task id by phid :param taskid: str :returns: str @@ -928,7 +944,7 @@ def get_task_id_by_phid(taskid): _ = p.sql_x("SELECT id \ from maniphest_task \ where phid=%s;", - (taskid,), limit=None) + (phid,), limit=None) p.close() if _ is not None and len(_[0]) > 0: return _[0][0] diff --git a/wmfphablib/rtlib.py b/wmfphablib/rtlib.py index 225ec7d..8e3a714 100755 --- a/wmfphablib/rtlib.py +++ b/wmfphablib/rtlib.py @@ -103,6 +103,7 @@ def links_to_dict(link_text): link_refs = {'refers_to': 'RefersTo:', 'refers_toby': 'ReferredToBy:', 'children': 'Members:', + 'parent': 'MemberOf', 'blockers': 'DependsOn', 'blocks': 'DependedOnBy'} |