def _python_identify_repo(self, homepage):
     """Returns code repository dict filled with homepage, if homepage is GH repo
     (None otherwise)
     """
     if parse_gh_repo(homepage):
         return {'url': homepage, 'type': 'git'}
     return None
예제 #2
0
 def _get_repo_name(self, url):
     """Retrieve GitHub repo from a preceding Mercator scan"""
     parsed = parse_gh_repo(url)
     if not parsed:
         self.log.debug('Could not parse Github repo URL %s', url)
     else:
         self._repo_url = 'https://github.com/' + parsed
     return parsed
def isGhRepo(message, key):
    try:
        val = reduce(lambda m, k: m[k], key if isinstance(key, list) else [key], message)
        if parse_gh_repo(val):
            return True
        else:
            return False
    except:
        return False
예제 #4
0
    def _get_github_readme(self, url):
        repo_tuple = parse_gh_repo(url)
        project, repo = repo_tuple.split('/')

        for readme_type, extensions in self.README_TYPES.items():
            for extension in extensions:
                if extension:
                    extension = '.' + extension
                url = self._GITHUB_README_PATH.format(project=project,
                                                      repo=repo,
                                                      extension=extension)
                response = requests.get(url)
                if response.status_code != 200:
                    self.log.debug('No README%s found for type "%s" at "%s"',
                                   extension, readme_type, url)
                    continue

                self.log.debug('README%s found for type "%s" at "%s"',
                               extension, readme_type, url)
                return {'type': readme_type, 'content': response.text}
 def _query_repo_name(self):
     """Retrieve GitHub repo from a preceding Mercator scan"""
     # Fridolin: most of the checks can be removed since Dispatcher schedules this task iff we have github.com
     wr = self.parent_task_result('metadata')
     if wr is None:
         self.log.error(
             "No repo_name provided, and no Mercator scan result")
         return None
     code_repos =\
         [m.get("code_repository") for m in wr.get('details', []) if m.get("code_repository")]
     repo_details = code_repos[0] if code_repos else None
     if repo_details is None:
         self.log.debug("No repo_name provided, and no repo metadata found")
         return None
     repo_name = repo_details.get("url")
     if repo_name is None:
         self.log.debug('No repo name extracted, nothing to do')
         return None
     parsed = parse_gh_repo(repo_name)
     if not parsed:
         self.log.debug('Could not parse Github repo URL %s', repo_name)
     else:
         self._repo_url = 'https://github.com/' + parsed
     return parsed
예제 #6
0
 def test_parse_gh_repo_nok(self, url):
     assert parse_gh_repo(url) is None
예제 #7
0
 def test_parse_gh_repo_ok(self, url):
     assert parse_gh_repo(url) == 'foo/bar'
 def _get_github_repo_tuple(self):
     repo_url = self.parent_task_result(
         'metadata')['details'][0]['code_repository']['url']
     repo_tuple = parse_gh_repo(repo_url)
     return repo_tuple.split('/')