Ejemplo n.º 1
0
 def open_issue_in_browser(base_url, issue_key):
     issue_url = '{}/browse/{}'.format(base_url.rstrip('/'), issue_key)
     Popen([browser(), issue_url])
     print('Opened {}. Press enter to continue.'.format(issue_url))
Ejemplo n.º 2
0
    def display_dashboard(self, jira_manager: 'JiraManager',
                          jira_views: Dict[str, JiraView]) -> None:
        df = DisplayFilter.default()

        matching_issues = []
        for jira_view in list(self._jira_views.values()):
            matching_issues.extend(list(jira_view.get_issues().values()))

        filters = {}  # type: Dict[Column, str]
        while True:
            filtered_issues = df.display_and_return_sorted_issues(
                jira_manager, matching_issues, 1, filters)
            print_separator(60)
            prompt = 'Input [#] integer value to open ticket in browser, [f] to filter column by string, [c] to clear filters, [q] to quit'
            custom = get_input(prompt)
            if custom == 'q':
                return
            elif custom == 'f':
                column_name = pick_value(
                    'Filter against which column?',
                    [column.name for column in df.included_columns], True)
                if column_name is None:
                    continue
                to_match = get_input('Filter for what string?', False)

                # For now, we convert the string name to the Column object as we key by a mapping of Column to filter regex for matching
                # TODO: This should be changed to a Dict[str, List[ColumnFilter]] objects going forward and made consistent across all users
                # This will both tidy up this abstraction but also allow matching against multiple regexes per Column rather than the current one,
                # as well as enforce the 1:many relationship we're going for on filtering instead of the suboptimal many:1 our
                # data structures currently give us.
                column_list = [
                    col for col in df.included_columns
                    if col.name == column_name
                ]
                assert len(
                    column_list
                ) == 1, 'Expected only 1 match with column name {}, got {}'.format(
                    column_name, len(column_list))
                filters[column_list[0]] = to_match
            elif custom == 'c':
                filters = {}
            elif custom.isdigit():
                intval = int(custom) - 1
                issue = filtered_issues[intval]

                # As we cache JiraProject data on a JiraConnection basis, we need to reach into the JiraView, to their
                # contained JiraConnections, and check for presence of the owning JiraProject for this issuekey
                # in order to determine our base url to open a browser to this issue. I'm not in love with this.
                base_url = 'unknown'
                for jira_view in list(jira_views.values()):
                    jira_connection = jira_view.jira_connection
                    for jira_project in jira_connection.cached_projects:
                        if jira_project.owns_issue(issue):
                            base_url = jira_connection.url
                if base_url == 'unknown':
                    print(
                        'Failed to find JiraConnection for issuekey: {}. Something went wrong.'
                        .format(issue.issue_key))
                else:
                    issue_url = '{}browse/{}'.format(base_url, issue)
                    try:
                        Popen([browser(), issue_url])
                        print('Opened {}. Press enter to continue.'.format(
                            issue_url))
                        pause()
                    except OSError as oe:
                        print(
                            'Failed to open browser [{}]. Probably need to configure your environment or update from main menu. Exception: {}'
                            .format(browser(), oe))
            else:
                print('Oops... Unrecognized input. Please try again.')
                pause()