def alm_add_task(self, task): if self.config['alm_issue_label']: tags_string = self.config['alm_issue_label'] for tag in task['tags']: tags_string += '; ' + tag default_args = { 'State': self.config['tfs_new_status'], 'Iteration Path': self.config['tfs_iterationpath'], 'Area Path': self.config['alm_project'], 'Work Item Type': self.config['tfs_issue_type'], 'Tags': tags_string } create_args = self.get_new_issue(task, defaults=default_args) target_url = '%s/%s/_apis/wit/workitems/$Task?api-version=1.0' % \ (self.config['tfs_collection'], urlquote_str(self.config['alm_project'])) try: work_item = self.alm_plugin.call_api(target_url, method=URLRequest.PATCH, args=self.convert_create_args_to_api_args(create_args), call_headers={"content-type": "application/json-patch+json"}) except APIError as err: raise AlmException('Encountered an error creating a new work item: %s' % err) tfs_task = self.get_task_object(task, work_item) if self.config['alm_standard_workflow'] and (task['status']['id'] in STATUS.DONE_SET or task['status']['id'] in STATUS.NA_SET): self.alm_update_task_status(tfs_task, task['status']['id']) return tfs_task
def alm_get_task_legacy(self, task): wiql_query = ('Select [Id] From WorkItems Where [System.IterationPath]=\'%s\' and [System.AreaPath]=\'%s\' ' 'and [Title] Contains \'%s\'' % (self.config['tfs_iterationpath'], self.config['alm_project'], task['alm_fixed_title'])) data = { "query": wiql_query } target_url = '%s/%s/_apis/wit/wiql?api-version=1.0' % \ (self.config['tfs_collection'], urlquote_str(self.config['alm_project'])) try: response = self.alm_plugin.call_api(target_url, method=URLRequest.POST, args=data) except APIError as err: raise AlmException('Encountered an error searching for task: %s' % err) if 'workItems' not in response or not response['workItems']: return None work_item_id = response['workItems'][0]['id'] work_item_url = self.get_work_item_url(work_item_id) try: work_item = self.alm_plugin.call_api(work_item_url) except APIError as err: raise AlmException('Unable to retrieve work item for %s: %s' % (task['task_id'], err)) return self.get_task_object(task, work_item)