# Path: f8a_worker/workers/golangcvepredictor.py
# class GitIssuesPRsTask(BaseTask):
#     """Computes various Issues and PRS for Golang Packages/repositories."""
# 
#     _analysis_name = 'GitIssuesPRsTask'
#     GITHUB_API_URL = 'https://api.github.com/repos/'
#     GITHUB_URL = 'https://github.com/'
#     GITHUB_TOKEN = ''
# 
#     def get_response_issues(self, url, headers=None, sleep_time=2, retry_count=10):
#         """Wrap requests which tries to get response.
# 
#         :param url: URL where to do the request
#         :param headers: additional headers for request
#         :param sleep_time: sleep time between retries
#         :param retry_count: number of retries
#         :return: content of response's json
#         """
#         try:
#             for _ in range(retry_count):
#                 response = requests.get(url, headers=headers,
#                                         params={'access_token': self.GITHUB_TOKEN})
#                 response.raise_for_status()
#                 if response.status_code == 204:
#                     # json() below would otherwise fail with JSONDecodeError
#                     raise HTTPError('No content')
#                 response = response.json()
#                 if response:
#                     return response
#                 time.sleep(sleep_time)
#             else:
#                 raise NotABugTaskError("Number of retries exceeded")
#         except HTTPError as err:
#             message = "Failed to get results from {url} with {err}".format(url=url, err=err)
#             raise NotABugTaskError(message) from err
# 
#     def _processJSonIssuePR(self, result, repository, event, package, URL):
# 
#         comments = ""
#         finaldata = {}
#         finaldata['source'] = 'github'
#         finaldata['package'] = package
#         finaldata['link'] = URL
#         finaldata['type'] = event
# 
#         # Fetching Comments section
#         comments_json = self.get_response_issues(result['comments_url'])
#         for entry in comments_json:
#             comments = comments + '\n' + entry['body']
# 
#         description = result['title'] + '\n' + result['body'] + comments
#         finaldata['content'] = description
#         return finaldata
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
# 
#         """
#         result_data = {'status': 'unknown',
#                        'package': '',
#                        'summary': [],
#                        'details': {}}
#         # self._strict_assert(arguments.get('package'))
#         # self._strict_assert(arguments.get('repository'))
#         # self._strict_assert(arguments.get('event'))
#         # self._strict_assert(arguments.get('number'))
#         event = ''
#         package = arguments.get('package')
#         repository = arguments.get('repository')
#         if arguments.get('event'):
#             event = arguments.get('event').split('-')[0]
#         isprnumber = arguments.get('id')
# 
#         # For testing purposes
#         if package is None:
#             return result_data
# 
#         try:
#             token, header = self.configuration.select_random_github_token()
#             self.GITHUB_TOKEN = token
#         except F8AConfigurationException as e:
#             self.log.error(e)
#             raise FatalTaskError from e
#         except Exception as e:
#             self.log.error(e)
#             raise FatalTaskError from e
# 
#         # Generating Request URL to fetch Data
#         url_path = repository + '/' + event + 's/' + isprnumber
#         url_template = urllib.parse.urljoin(self.GITHUB_API_URL, url_path)
# 
#         # Call the GitHub APIs to get the data
#         try:
#             result = self.get_response_issues(url_template.format())
#         except NotABugTaskError as e:
#             self.log.error(e)
#             raise NotABugFatalTaskError from e
# 
#         # Process the received data
#         result_data['status'] = 'success'
#         result_data['package'] = package
#         finaldata = self._processJSonIssuePR(result, repository, event,
#                                              package, url_template.format())
#         result_data['details'] = finaldata
#         return result_data


import pytest
from f8a_worker.workers import GitIssuesPRsTask as gocve
from unittest import mock
from selinon import FatalTaskError
        "comments_url": "https://api.github.com/repos/kubeup/archon/issues/4/comments",
        "number": 4,
        "title": "how to generate types.generated.go",
        "created_at": "2017-03-27T12:52:28Z",
        "updated_at": "2017-03-27T14:03:20Z",
        "body": "could u support a script for generate *.generated.go in this project?",
    }

    _processJSonIssuePR = mock.Mock()
    _processJSonIssuePR.return_value = {
        "githublink": "https://github.com/kubeup/archon",
        "issue": "how to generate types.generated.go\ncould u "
                 "support a script for generate *.generated.go in this "
                 "project?",
        "number": 4,
        "package": "kubeup/archon"
    }

    log = mock.Mock()

    def test_execute_noarg(self):
        """Tests for the Golang CVE ingestion worker with no argument."""
        results = gocve.execute(self, arguments={})
        assert results is not None
        assert isinstance(results, dict)
        assert set(results.keys()) == {'package', 'details', 'status', 'summary'}
        assert results['status'] == 'unknown'

    def test_execute(self):
        """Tests for the Golang CVE ingestion worker with argument."""

# Path: f8a_worker/workers/golangcvepredictor.py
# class GitIssuesPRsTask(BaseTask):
#     """Computes various Issues and PRS for Golang Packages/repositories."""
# 
#     _analysis_name = 'GitIssuesPRsTask'
#     GITHUB_API_URL = 'https://api.github.com/repos/'
#     GITHUB_URL = 'https://github.com/'
#     GITHUB_TOKEN = ''
# 
#     def get_response_issues(self, url, headers=None, sleep_time=2, retry_count=10):
#         """Wrap requests which tries to get response.
# 
#         :param url: URL where to do the request
#         :param headers: additional headers for request
#         :param sleep_time: sleep time between retries
#         :param retry_count: number of retries
#         :return: content of response's json
#         """
#         try:
#             for _ in range(retry_count):
#                 response = requests.get(url, headers=headers,
#                                         params={'access_token': self.GITHUB_TOKEN})
#                 response.raise_for_status()
#                 if response.status_code == 204:
#                     # json() below would otherwise fail with JSONDecodeError
#                     raise HTTPError('No content')
#                 response = response.json()
#                 if response:
#                     return response
#                 time.sleep(sleep_time)
#             else:
#                 raise NotABugTaskError("Number of retries exceeded")
#         except HTTPError as err:
#             message = "Failed to get results from {url} with {err}".format(url=url, err=err)
#             raise NotABugTaskError(message) from err
# 
#     def _processJSonIssuePR(self, result, repository, event, package, URL):
# 
#         comments = ""
#         finaldata = {}
#         finaldata['source'] = 'github'
#         finaldata['package'] = package
#         finaldata['link'] = URL
#         finaldata['type'] = event
# 
#         # Fetching Comments section
#         comments_json = self.get_response_issues(result['comments_url'])
#         for entry in comments_json:
#             comments = comments + '\n' + entry['body']
# 
#         description = result['title'] + '\n' + result['body'] + comments
#         finaldata['content'] = description
#         return finaldata
# 
#     def execute(self, arguments):
#         """Task code.
# 
#         :param arguments: dictionary with task arguments
#         :return: {}, results
# 
#         """
#         result_data = {'status': 'unknown',
#                        'package': '',
#                        'summary': [],
#                        'details': {}}
#         # self._strict_assert(arguments.get('package'))
#         # self._strict_assert(arguments.get('repository'))
#         # self._strict_assert(arguments.get('event'))
#         # self._strict_assert(arguments.get('number'))
#         event = ''
#         package = arguments.get('package')
#         repository = arguments.get('repository')
#         if arguments.get('event'):
#             event = arguments.get('event').split('-')[0]
#         isprnumber = arguments.get('id')
# 
#         # For testing purposes
#         if package is None:
#             return result_data
# 
#         try:
#             token, header = self.configuration.select_random_github_token()
#             self.GITHUB_TOKEN = token
#         except F8AConfigurationException as e:
#             self.log.error(e)
#             raise FatalTaskError from e
#         except Exception as e:
#             self.log.error(e)
#             raise FatalTaskError from e
# 
#         # Generating Request URL to fetch Data
#         url_path = repository + '/' + event + 's/' + isprnumber
#         url_template = urllib.parse.urljoin(self.GITHUB_API_URL, url_path)
# 
#         # Call the GitHub APIs to get the data
#         try:
#             result = self.get_response_issues(url_template.format())
#         except NotABugTaskError as e:
#             self.log.error(e)
#             raise NotABugFatalTaskError from e
# 
#         # Process the received data
#         result_data['status'] = 'success'
#         result_data['package'] = package
#         finaldata = self._processJSonIssuePR(result, repository, event,
#                                              package, url_template.format())
#         result_data['details'] = finaldata
#         return result_data


# Path: tests/workers/test_gocvecollector.py
import pytest
from f8a_worker.workers import GitIssuesPRsTask as gocve
from unittest import mock
from selinon import FatalTaskError

        "comments_url": "https://api.github.com/repos/kubeup/archon/issues/4/comments",
        "number": 4,
        "title": "how to generate types.generated.go",
        "created_at": "2017-03-27T12:52:28Z",
        "updated_at": "2017-03-27T14:03:20Z",
        "body": "could u support a script for generate *.generated.go in this project?",
    }

    _processJSonIssuePR = mock.Mock()
    _processJSonIssuePR.return_value = {
        "githublink": "https://github.com/kubeup/archon",
        "issue": "how to generate types.generated.go\ncould u "
                 "support a script for generate *.generated.go in this "
                 "project?",
        "number": 4,
        "package": "kubeup/archon"
    }

    log = mock.Mock()

    def test_execute_noarg(self):
        """Tests for the Golang CVE ingestion worker with no argument."""
        results = gocve.execute(self, arguments={})
        assert results is not None
        assert isinstance(results, dict)
        assert set(results.keys()) == {'package', 'details', 'status', 'summary'}
        assert results['status'] == 'unknown'

    def test_execute(self):
        """Tests for the Golang CVE ingestion worker with argument."""

        results = gocve.execute(self, arguments={'event': 'issue', 'id': '4',