def updateTask(fab, **args): # 获取 tid tid = args.pop('tid') if None == tid: return title = args.pop('task') description = args.pop('description', u"") priority = args.pop('priority', u"Needs Triage") status = args.pop('status', u"Open") owner = args.pop('assigned', u"") projectsStr = unicode(args.pop('tags', u"")) deadline = args.pop('deadline').strip() kickoff = args.pop('kickoff') points = args.pop('points') projectNames = map(lambda x: x.strip(), projectsStr.split(',')) if tid[0] == 'T': tid = int(tid[1:]) else: tid = int(tid) tf = TaskInfoFactory() tif = tf.info(tid) if tif == None: print 'invalid task {tid}'.format(tid=tid) if deadline == 'TBD': deadline = '' pif = ProjectInfoFactory() projects = pif.projectsByName(projectNames) projectPHIDs = map(lambda x: x['phid'], projects) ui = UserInfo() ownerPhid = ui.getUserByRealName(owner)['phid'] updateArgs = {} editArgs = {'objectIdentifier': tif['phid'], 'transactions': []} if title != tif['title']: updateArgs['title'] = title if description != tif['description']: updateArgs['description'] = description if ownerPhid != tif['ownerPHID']: updateArgs['ownerPHID'] = ownerPhid if priority != tif['priority']: updateArgs['priority'] = settings.PRIORITY_VALUES[priority] # 更新 project newProjects = set(projectPHIDs) oldProjects = set(tif['projectPHIDs']) # 整理要添加的project addingProjects = list(newProjects - oldProjects) # 整理要删除的project removingProjects = list(oldProjects - newProjects) if len(addingProjects) > 0: editArgs['transactions'].append({ 'type': 'projects.add', 'value': addingProjects }) if len(removingProjects) > 0: editArgs['transactions'].append({ 'type': 'projects.remove', 'value': removingProjects }) pass if len(removingProjects) > 0: pass if status != tif['statusName']: try: updateArgs['status'] = settings.STATUS_NAMES[status] except Exception, e: if status != tif['status']: updateArgs['status'] = status pass
def updateTask(fab, **args): # 获取 tid tid = args.pop('tid') if None == tid: return title = args.pop('task') description = args.pop('description', u"") priority = args.pop('priority', u"Needs Triage") status = args.pop('status', u"Open") owner = args.pop('assigned', u"") projectsStr = unicode(args.pop('tags', u"")) deadline = args.pop('deadline').strip() kickoff = args.pop('kickoff') points = args.pop('points') projectNames = map(lambda x: x.strip(), projectsStr.split(',')) if tid[0] == 'T': tid = int(tid[1:]) else: tid = int(tid) tf = TaskInfoFactory() tif = tf.info(tid) if tif == None: print 'invalid task {tid}'.format(tid = tid) if deadline == 'TBD': deadline = '' pif = ProjectInfoFactory() projects = pif.projectsByName(projectNames) projectPHIDs = map(lambda x: x['phid'], projects) ui = UserInfo() ownerPhid = ui.getUserByRealName(owner)['phid'] updateArgs = {} editArgs = {'objectIdentifier': tif['phid'], 'transactions': []} if title != tif['title']: updateArgs['title'] = title if description != tif['description']: updateArgs['description'] = description if ownerPhid != tif['ownerPHID']: updateArgs['ownerPHID'] = ownerPhid if priority != tif['priority']: updateArgs['priority'] = settings.PRIORITY_VALUES[priority] # 更新 project newProjects = set(projectPHIDs) oldProjects = set(tif['projectPHIDs']) # 整理要添加的project addingProjects = list(newProjects - oldProjects) # 整理要删除的project removingProjects = list(oldProjects - newProjects) if len(addingProjects) > 0: editArgs['transactions'].append({'type': 'projects.add', 'value': addingProjects}) if len(removingProjects) > 0: editArgs['transactions'].append({'type': 'projects.remove', 'value': removingProjects}) pass if len(removingProjects) > 0: pass if status != tif['statusName']: try: updateArgs['status'] = settings.STATUS_NAMES[status] except Exception, e: if status != tif['status']: updateArgs['status'] = status pass
auxDict[kickoffFieldName] = kickoff # pp(dict( # title = title, # description = description, # projectPHIDs = projectPHIDs, # auxiliary = auxDict)) # return theTask = fab.maniphest.createtask(title=title, description=description, projectPHIDs=projectPHIDs, auxiliary=auxDict) taskId = theTask['id'] ui = UserInfo() try: ownerPhid = ui.getUserByRealName(owner)['phid'] except Exception, e: ownerPhid = None theTask = fab.maniphest.update(id=taskId, priority=settings.PRIORITY_VALUES[priority], status=settings.STATUS_NAMES[status], ownerPHID=ownerPhid) if None != parent: mock = FabMock() session = requests.Session() mock = FabMock() resp = session.get(settings.SITE['URL']) csrfToken = mock.getCsrfValue(resp.text) resp = mock.login(settings.USER['username'], settings.USER['password'], csrfToken, session) csrfToken = mock.getCsrfValue(resp.text)
# title = title, # description = description, # projectPHIDs = projectPHIDs, # auxiliary = auxDict)) # return theTask = fab.maniphest.createtask( title = title, description = description, projectPHIDs = projectPHIDs, auxiliary = auxDict) taskId = theTask['id'] ui = UserInfo() try: ownerPhid = ui.getUserByRealName(owner)['phid'] except Exception, e: ownerPhid = None theTask = fab.maniphest.update( id = taskId, priority = settings.PRIORITY_VALUES[priority], status = settings.STATUS_NAMES[status], ownerPHID = ownerPhid) if None != parent: mock = FabMock() session = requests.Session() mock = FabMock() resp = session.get(settings.SITE['URL']) csrfToken = mock.getCsrfValue(resp.text) resp = mock.login( settings.USER['username'],