Exemplo n.º 1
0
    def display_view(self, jira_manager):
        # type: (JiraManager) -> None
        df = DisplayFilter.default()

        working_issues = list(self.get_issues().values())
        while True:
            try:
                issues = df.display_and_return_sorted_issues(
                    jira_manager, working_issues)
                print_separator(60)
                print('[JiraView operations for {}]'.format(self.name))
                custom = get_input(
                    '[f] to manually enter a substring to regex issues in the view'
                    + os.linesep + '[c] to clear all regex filtering' +
                    os.linesep +
                    '[#] Integer value to open ticket in browser ' +
                    os.linesep + '[q] to quit' + os.linesep + ':')
                if custom == 'q':
                    return
                elif custom == 'f':
                    string = get_input('substring to match:', lowered=False)
                    new_issues = []
                    for jira_issue in working_issues:
                        if jira_issue.matches(self.jira_connection, string):
                            new_issues.append(jira_issue)
                    working_issues = new_issues
                elif custom == 'c':
                    working_issues = list(self.get_issues().values())
                else:
                    try:
                        JiraUtils.open_issue_in_browser(
                            self.jira_connection.url,
                            issues[int(custom) - 1].issue_key)
                    except ValueError:
                        print('Bad input. Try again.')
            except JIRAError as je:
                print('Caught an error: {}'.format(je))
                traceback.print_exc()
                return
Exemplo n.º 2
0
    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.')
Exemplo n.º 3
0
    def _run_report(jira_manager, team, report_filter):
        # type: (JiraManager, Team, ReportFilter) -> None
        # We prompt for a new 'since' on each iteration of the loop
        if report_filter.needs_duration:
            report_filter.since = time_utils.since_now(
                ReportFilter.get_since())

        try:
            sorted_member_issues = sorted(
                team.members, key=lambda s: s.primary_name.user_name)

            while True:
                # Print out a menu of the meta information for each team member
                print_separator(40)
                print('[{}]'.format(report_filter.header))
                print(report_filter.column_headers())

                count = 1

                for member_issues in sorted_member_issues:
                    report_filter.clear()
                    # We perform pre-processing and one-off prompting for time duration in .process call
                    report_filter.process_issues(member_issues)
                    print('{:5}: {}'.format(
                        count,
                        report_filter.print_all_counts(
                            member_issues.primary_name.user_name)))
                    count += 1

                print_separator(40)
                cmd = get_input(
                    '[#] Integer value to see a detailed breakdown by category. [q] to return to menu:'
                )
                if cmd == 'q':
                    break

                # Received detailed breakdown input
                try:
                    c_input = int(cmd) - 1

                    # Pull out the MemberIssuesByStatus object for the chosen member for detailed printing
                    # We need to re-populate this report filter with this user for matching logic to work
                    full_member_issues = sorted_member_issues[c_input]
                    report_filter.clear()
                    report_filter.process_issues(full_member_issues)
                    displayed_issues = full_member_issues.display_member_issues(
                        jira_manager, report_filter)

                    while True:
                        cmd = get_input(
                            '[#] Integer value to open JIRA issue in browser. [q] to return to report results:'
                        )
                        if cmd == 'q':
                            break
                        try:
                            jira_issue = displayed_issues[int(cmd) - 1]
                            jira_connection = jira_manager.get_jira_connection(
                                jira_issue.jira_connection_name)
                            JiraUtils.open_issue_in_browser(
                                jira_connection.url, jira_issue.issue_key)
                        except ValueError as ve:
                            print('Bad input. Try again.')
                            print('ValueError : {}'.format(ve))
                            pause()
                except ValueError:
                    break
        except JIRAError as je:
            print(
                'Caught a JIRAError attempting to run a query: {}'.format(je))
            pause()