def eval(self): if not self.args.issue_project: raise UsageError( 'project must be specified when creating an issue') if not (self.args.issue_parent or self.args.issue_type): self.args.issue_type = 'bug' if self.args.issue_type and not self.args.issue_type.lower( ) in self.jira.get_issue_types().keys( ) + self.jira.get_subtask_issue_types().keys(): raise UsageError( "invalid issue type: %s (try using jira-cli " "list issue_types or jira-cli list subtask_types)" % self.args.issue_type) if self.args.issue_parent: if not self.args.issue_type: self.args.issue_type = 'sub-task' if not self.args.issue_type in self.jira.get_subtask_issue_types(): raise UsageError( "issues created with parents must be one of {%s}" % ",".join(self.jira.get_subtask_issue_types())) description = self.args.issue_description or get_text_from_editor() print_output( self.jira.format_issue( self.jira.create_issue(self.args.issue_project, self.args.issue_type, self.args.title, description, self.args.issue_priority, self.args.issue_parent)))
def eval(self): extras = {} if self.args.extra_fields: extras = self.extract_extras() if not self.args.issue_project: raise UsageError( 'project must be specified when creating an issue') if not (self.args.issue_parent or self.args.issue_type): self.args.issue_type = 'bug' if self.args.issue_type and not self.args.issue_type.lower() in list( self.jira.get_issue_types().keys()) + list( self.jira.get_subtask_issue_types().keys()): raise UsageError( "invalid issue type: %s (try using jira-cli " "list issue_types or jira-cli list subtask_types)" % self.args.issue_type) if self.args.issue_parent: if not self.args.issue_type: self.args.issue_type = 'sub-task' if self.args.issue_type not in self.jira.get_subtask_issue_types(): raise UsageError( "issues created with parents must be one of {%s}" % ",".join(self.jira.get_subtask_issue_types())) components = {} if self.args.issue_components: valid_components = dict( (k["name"], k["id"]) for k in self.jira.get_components(self.args.issue_project)) if not set(self.args.issue_components).issubset(valid_components): raise UsageError( "components for project %s should be one of {%s}" % (self.args.issue_project, ",".join(valid_components))) else: components = { k: valid_components[k] for k in self.args.issue_components } if self.args.issue_description is not None: description = self.args.issue_description else: description = get_text_from_editor() print_output( self.jira.format_issue( self.jira.create_issue( self.args.issue_project, self.args.issue_type, self.args.title, description, self.args.issue_priority, self.args.issue_parent, self.args.issue_assignee, self.args.issue_reporter, self.args.labels, components, **extras)))
def get_issues_by_filter(self, *filters): issues = [] for filter in filters: try: fid = self.get_filters()[filter]["id"] issues.extend(self.service.getIssuesFromFilter(self.token, fid)) except KeyError: raise UsageError("filter %s not found" % filter) return [soap_recursive_dict(k) for k in issues]
def eval(self): mappers = { "issue_types": (self.jira.get_issue_types, ), 'subtask_types': (self.jira.get_subtask_issue_types, ), 'projects': (self.jira.get_projects, ), 'priorities': (self.jira.get_priorities, ), 'statuses': (self.jira.get_statuses, ), 'resolutions': (self.jira.get_resolutions, ), 'components': (self.jira.get_components, 'project'), 'versions': (self.jira.list_versions, 'project'), 'transitions': (self.jira.get_available_transitions, 'issue'), 'filters': (self.jira.get_filters, ), 'aliases': (lambda: [{ "name": k, "description": v } for k, v in list(Config(section='alias').items()).items()], ) } func, arguments = mappers[self.args.type][0], mappers[ self.args.type][1:] _ = [] _k = {} for earg in arguments: if isinstance(earg, tuple): if getattr(self.args, earg[0]): _k.update({earg[0]: getattr(self.args, earg[0])}) else: _k[earg[0]] = earg[1] else: if not getattr(self.args, earg): raise UsageError("'--%s' is required for listing '%s'" % (earg, self.args.type)) _.append(getattr(self.args, earg)) found = False data = func(*_, **_k) data_dict = OrderedDict() if type(data) == type([]): for item in data: data_dict[item['name']] = item else: data_dict = data for item in list(data_dict.values()): found = True val = item if type(item) == type({}): val = colorfunc(item['name'], 'white') if 'key' in item and item['key']: val += " [" + colorfunc(item['key'], 'magenta') + "]" if 'description' in item and item['description']: val += " [" + colorfunc(item['description'], 'green') + "]" print_output(colorfunc(val, 'white')) if not found: raise UsageWarning("No %s found." % self.args.type)
def add_versions(self, issue, versions, type): project_versions = self.get_versions(issue) ids = [] issue_obj = self.get_issue(issue) for version in versions: if version not in project_versions: raise UsageError("%s is not a valid version for issue %s" % (version, issue)) ids.append(project_versions[version]['id']) [ ids.append(v['id']) for v in issue_obj.get( 'fixVersions' if type == 'fix' else 'affectsVersions', []) ] args = {} if type == 'fix': args = {'fixVersions': ids} elif type == 'affects': args = {'versions': ids} return self.update_issue(issue, **args)