コード例 #1
0
def close_duplicates():
    """
    Function to close duplicate functions. Uses downstream:close_duplicates.

    :return: Nothing
    """
    config = load_config()
    logging.basicConfig(level=logging.INFO)
    log.info("Testing flag is %r", config['sync2jira']['testing'])
    mapping = config['sync2jira']['map']
    warnings.simplefilter("ignore")

    for upstream in mapping.get('pagure', {}).keys():
        for issue in u_issue.pagure_issues(upstream, config):
            try:
                d_issue.close_duplicates(issue, config)
            except Exception:
                log.error("Failed on %r", issue)
                raise
    log.info("Done with pagure duplicates.")

    for upstream in mapping.get('github', {}).keys():
        for issue in u_issue.github_issues(upstream, config):
            try:
                d_issue.close_duplicates(issue, config)
            except Exception:
                log.error("Failed on %r", issue)
                raise
    log.info("Done with github duplicates.")
コード例 #2
0
    def test_pagure_issues(self,
                           mock_requests,
                           mock_issue_from_pagure):
        """
        This function tests 'pagure_issues' function
        """
        # Set up return values
        get_return = MagicMock()
        get_return.json.return_value = {
            'issues': [
                {'assignee': 'mock_assignee'}
            ]

        }
        get_return.request.url = 'mock_url'
        mock_requests.get.return_value = get_return
        mock_issue_from_pagure.return_value = 'Successful Call!'

        # Call the function
        response = list(u.pagure_issues(
            upstream='org/repo',
            config=self.mock_config
        ))

        # Assert everything was called correctly
        self.assertEqual(response[0], 'Successful Call!')
        mock_requests.get.assert_called_with(
            'https://pagure.io/api/0/org/repo/issues',
            params={'filter1': 'filter1', 'tags': ['custom_tag']}
        )
        mock_issue_from_pagure.assert_called_with(
            'org/repo',
            {'assignee': ['mock_assignee']},
            self.mock_config
        )
コード例 #3
0
    def test_pagure_issues_error(self,
                                 mock_requests,
                                 mock_issue_from_pagure):
        """
        This function tests 'pagure_issues' function where we get an IOError
        """
        # Set up return values
        get_return = MagicMock()
        get_return.__bool__ = mock.Mock(return_value=False)
        get_return.__nonzero__ = get_return.__bool__
        get_return.json.side_effect = Exception()
        get_return.text.return_value = {
            'issues': [
                {'assignee': 'mock_assignee'}
            ]

        }
        mock_requests.get.return_value = get_return

        # Call the function
        with self.assertRaises(IOError):
            list(u.pagure_issues(
                upstream='org/repo',
                config=self.mock_config
            ))

        # Assert everything was called correctly
        mock_requests.get.assert_called_with(
            'https://pagure.io/api/0/org/repo/issues',
            params={'filter1': 'filter1', 'tags': ['custom_tag']}
        )
        mock_issue_from_pagure.assert_not_called()
コード例 #4
0
def initialize_issues(config, testing=False, repo_name=None):
    """
    Initial initialization needed to sync any upstream \
    repo with JIRA. Goes through all issues and \
    checks if they're already on JIRA / Need to be \
    created.

    :param Dict config: Config dict for JIRA
    :param Bool testing: Flag to indicate if we are testing. Default false
    :param String repo_name: Optional individual repo name. If defined we will only sync the provided repo
    :returns: Nothing
    """
    log.info("Running initialization to sync all issues from upstream to jira")
    log.info("Testing flag is %r", config['sync2jira']['testing'])
    mapping = config['sync2jira']['map']
    for upstream in mapping.get('pagure', {}).keys():
        if 'issue' not in mapping.get('pagure', {}).get(upstream, {}).get('sync', []):
            continue
        if repo_name is not None and upstream != repo_name:
            continue
        for issue in u_issue.pagure_issues(upstream, config):
            try:
                d_issue.sync_with_jira(issue, config)
            except Exception as e:
                log.error(f"Failed on {issue}\nException: {e}")
                raise
    log.info("Done with pagure issue initialization.")

    for upstream in mapping.get('github', {}).keys():
        if 'issue' not in mapping.get('github', {}).get(upstream, {}).get('sync', []):
            continue
        if repo_name is not None and upstream != repo_name:
            continue
        # Try and except for github API limit
        try:
            for issue in u_issue.github_issues(upstream, config):
                try:
                    d_issue.sync_with_jira(issue, config)
                except Exception:
                    log.error("   Failed on %r", issue)
                    raise
        except Exception as e:
            if "API rate limit exceeded" in e.__str__():
                # If we've hit out API limit:
                # Sleep for 1 hour and call our function again
                log.info("Hit Github API limit. Sleeping for 1 hour...")
                sleep(3600)
                if not testing:
                    initialize_issues(config)
                return
            else:
                if not config['sync2jira']['develop']:
                    # Only send the failure email if we are not developing
                    report_failure(config)
                    raise
    log.info("Done with github issue initialization.")
コード例 #5
0
def list_managed():
    """
    Function to list URL for issues under map in config.

    :return: Nothing
    """
    config = load_config()
    mapping = config['sync2jira']['map']
    warnings.simplefilter("ignore")

    for upstream in mapping.get('pagure', {}).keys():
        for issue in u_issue.pagure_issues(upstream, config):
            print(issue.url)

    for upstream in mapping.get('github', {}).keys():
        for issue in u_issue.github_issues(upstream, config):
            print(issue.url)