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.")
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.")
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)
def test_github_issues_no_token(self, mock_get_all_github_data, mock_github, mock_issue_from_github): """ This function tests 'github_issues' function where we have no github token and no comments """ # Set up return values self.mock_config['sync2jira']['github_token'] = None self.mock_github_issue_raw['comments'] = 0 mock_github.return_value = self.mock_github_client mock_get_all_github_data.return_value = [self.mock_github_issue_raw] mock_issue_from_github.return_value = 'Successful Call!' # Call the function response = list(u.github_issues( upstream='org/repo', config=self.mock_config )) # Assert that calls were made correctly try: mock_get_all_github_data.assert_called_with( 'https://api.github.com/repos/org/repo/issues?labels=custom_tag&filter1=filter1', {} ) except AssertionError: mock_get_all_github_data.assert_called_with( 'https://api.github.com/repos/org/repo/issues?filter1=filter1&labels=custom_tag', {} ) self.mock_github_client.get_user.assert_any_call('mock_login') self.mock_github_client.get_user.assert_any_call('mock_assignee_login') mock_issue_from_github.assert_called_with( 'org/repo', {'labels': ['some_label'], 'number': '1234', 'comments': [], 'assignees': [{'fullname': 'mock_name'}], 'user': {'login': '******', 'fullname': 'mock_name'}, 'milestone': 'mock_milestone'}, self.mock_config ) self.assertEqual(response[0], 'Successful Call!') self.mock_github_client.get_repo.assert_not_called() self.mock_github_repo.get_issue.assert_not_called() self.mock_github_issue.get_comments.assert_not_called()
def test_github_issues(self, mock_get_all_github_data, mock_github, mock_issue_from_github): """ This function tests 'github_issues' function """ # Set up return values mock_github.return_value = self.mock_github_client mock_get_all_github_data.return_value = [self.mock_github_issue_raw] mock_issue_from_github.return_value = 'Successful Call!' # Call the function response = list(u.github_issues( upstream='org/repo', config=self.mock_config )) # Assert that calls were made correctly try: mock_get_all_github_data.assert_called_with( 'https://api.github.com/repos/org/repo/issues?labels=custom_tag&filter1=filter1', {'Authorization': 'token mock_token'} ) except AssertionError: mock_get_all_github_data.assert_called_with( 'https://api.github.com/repos/org/repo/issues?filter1=filter1&labels=custom_tag', {'Authorization': 'token mock_token'} ) self.mock_github_client.get_user.assert_any_call('mock_login') self.mock_github_client.get_user.assert_any_call('mock_assignee_login') mock_issue_from_github.assert_called_with( 'org/repo', {'labels': ['some_label'], 'number': '1234', 'comments': [ {'body': 'mock_body', 'name': 'mock_user_login', 'author': 'mock_username', 'changed': None, 'date_created': 'mock_created_at', 'id': 'mock_id'}], 'assignees': [{'fullname': 'mock_name'}], 'user': {'login': '******', 'fullname': 'mock_name'}, 'milestone': 'mock_milestone'}, self.mock_config ) self.mock_github_client.get_repo.assert_called_with('org/repo') self.mock_github_repo.get_issue.assert_called_with(number='1234') self.mock_github_issue.get_comments.assert_any_call() self.assertEqual(response[0], 'Successful Call!')