def search_projects(self): """ Does a one-off ad-hoc search for strings in all cached fields for all cached JiraProjects. Keeping at scope of JiraManager as search is a meta-scoped search of all cached JiraProjects independent of JiraConnection :return: """ tinput = get_input('Search [o]pen issues only, [c]losed, or [a]ll?') substring = get_input('Search for what substring?') matches = [] jira_projects = self.get_all_cached_jira_projects() # cache list of seen columns for the query columns = {} for project in list(jira_projects.values()): results = project.get_matching_issues(substring, tinput) for r in results: matches.append(r) for k, v in r.items(): # This is going to blast out our ability to filter on reviewer or reviewer 2. For now. if 'custom' not in k: columns[k] = True original_list = JiraUtils.sort_custom_jiraissues_by_key(matches) display_list = original_list df = DisplayFilter.default() while True: df.display_and_return_sorted_issues(self, display_list) print_separator(30) cinput = get_input( '[#] to open an issue in browser, [c] to clear column filters, [f] to specify a specific field to match on, [q] to return to menu:' ) if str.lower(cinput) == 'f': col_name = pick_value('Filter on which column?', list(columns.keys()), False) newlist = [] for ji in display_list: if col_name in ji: if substring in ji[col_name]: newlist.append(ji) display_list = newlist elif str.lower(cinput) == 'c': display_list = original_list elif not str.lower(cinput) == 'q': try: jira_issue = display_list[int(cinput) - 1] JiraUtils.open_issue_in_browser( self._jira_connections[ jira_issue.jira_connection_name].url, jira_issue.issue_key) except ValueError: print('Bad input. Try again.') elif str.lower(cinput) == 'q': break
def report_fix_version(self) -> None: """ Creates a report of all tickets, including dependencies, to the input FixVersion. """ # Only support creating of this on a single JiraConnection, with the assumption that multiple projects on that # connection can share a FixVersion, but these won't straddle to exterior Jira instances target_connection = self.pick_jira_connection( 'FixVersion report for which JiraConnection?') if target_connection is None: return open_only = is_yes('Show only unresolved issues?') to_match = get_input('Input substring to search fixversions for:', False) available_versions = set() for jira_project in target_connection.cached_projects: for jira_issue in jira_project.jira_issues.values(): for fix in jira_issue['fixVersions'].split(','): if to_match in fix: available_versions.add(fix) report_version = pick_value('Generate report for which FixVersion?', list(available_versions)) if report_version is None: return print('Generating report on: {}'.format(report_version)) # Now find all "primary root" members on this FixVersion, generate a list of matching, then display w/dependency # chains enabled matching_issues = set() for jira_project in target_connection.cached_projects: for jira_issue in jira_project.jira_issues.values(): if jira_issue.has_fix_version(report_version): if (open_only and jira_issue.is_open) or not open_only: matching_issues.add(jira_issue) df = DisplayFilter.default() df.open_only = open_only df.include_column('fixVersions', 'FixVersion', 10, 2) # sort our keys by issuekey sorted_results = JiraUtils.sort_custom_jiraissues_by_key( list(matching_issues)) del matching_issues issues = df.display_and_return_sorted_issues(self, sorted_results, 1, None, True) while True: choice = get_input( '[#] to open an issue in browser, [p] to print report again, [q] to quit report: ' ) if choice == 'q': break elif choice == 'p': df.display_and_return_sorted_issues(self, sorted_results, 1, None, True) try: int_choice = int(choice) - 1 if int_choice < 0 or int_choice > len(issues) - 1: raise ValueError('oops') chosen_issue = issues[int_choice] if not chosen_issue.is_cached: print( 'Cannot open browser for non-cached issue (don\'t know url). Cache offline to inspect {}.' .format(chosen_issue.issue_key)) else: jira_conn = self._jira_connections[ chosen_issue.jira_connection_name] JiraUtils.open_issue_in_browser(jira_conn.url, chosen_issue.issue_key) except ValueError: print('Bad input. Try again.')