Exemplo n.º 1
0
 def coverage(
     self, vcs: str, user: str, repo: str, api: API, branch: str = None
 ) -> Optional[float]:
     api.add(vcs, user, repo)
     if branch:
         api.add("branches", branch)
     return float(get(api.get(), "commit.totals.c"))
Exemplo n.º 2
0
 def status(self, instance: str, api: API) -> bool:
     try:
         api.base_url = self.base_url.format(instance)
         stats = api.add("statistics").get()
         return True if stats else False
     except RequestException:
         return False
Exemplo n.º 3
0
 def downloads(self, crate: str, api: API, version: str = None) -> Optional[int]:
     if version:
         crate_info = api.add(crate, version).get()
         return get(crate_info, "version.downloads")
     else:
         crate_info = api.add(crate).get()
         return get(crate_info, "crate.downloads")
Exemplo n.º 4
0
 def build(self,
           user: str,
           repo: str,
           api: API,
           branch: str = None) -> Optional[str]:
     api.add(user, repo)
     if branch:
         api.add("branch", branch)
     details = api.get()
     return get(details, "build.status")
Exemplo n.º 5
0
 def pull_requests(self, owner: str, repo: str, state: str, token: str, api: API):
     state_map = {"open": "+is:open", "closed": "+is:closed", "all": ""}
     query = f"?q=repo:{owner}/{repo}+is:pr{state_map.get(state, state)}"
     api.suffix = query
     issues = api.add("search", "issues").get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return issues.get("total_count")
Exemplo n.º 6
0
 def downloads(self,
               gem: str,
               api: API,
               version: str = None) -> Optional[int]:
     if version:
         gem_versions = api.add("versions", gem).get()
         for v in gem_versions:
             if v.get("number") == version:
                 return v.get("downloads_count")
     else:
         gem_info = api.add("gems", gem).get()
         return gem_info.get("downloads")
     return None
Exemplo n.º 7
0
 def build(self,
           vcs: str,
           user: str,
           repo: str,
           api: API,
           branch: str = None) -> Optional[str]:
     api.add(vcs, user, repo)
     if branch:
         api.add("tree", branch)
     details = api.get(params={"filter": "completed", "limit": 1})
     if len(details) == 0:
         return None
     return details[0].get("status")
Exemplo n.º 8
0
 def downloads(
     self, owner: str, repo: str, token: str, api: API, tag=None, asset=None
 ):
     releases = api.add("repos", owner, repo, "releases").get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     download_count = 0
     for release in releases:
         if tag and release.get("tag_name") == tag:
             for a in release.get("assets"):
                 if asset and a.get("name") == asset:
                     return a.get("download_count")
                 elif not asset:
                     download_count += a.get("download_count")
             if asset:
                 return None
             return download_count
         elif not tag:
             for asset in release.get("assets"):
                 download_count += asset.get("download_count")
     if tag:
         return None
     return download_count
Exemplo n.º 9
0
 def pgp(self, username: str, api: API) -> Optional[str]:
     search_results = api.add("user",
                              "lookup").get(params={"usernames": username})
     keybase_user = search_results.get("them", [None])[0]
     if not keybase_user:
         return None
     return (keybase_user.get("public_keys",
                              {}).get("primary", {}).get("key_fingerprint"))
Exemplo n.º 10
0
 def followers(self, username: str, token: str, api: API) -> Optional[int]:
     user_info = api.add("users", username).get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return user_info.get("followers")
Exemplo n.º 11
0
 def license(self, owner: str, repo: str, token: str, api: API) -> Optional[str]:
     repo_info = api.add("repos", owner, repo).get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return get(repo_info, "license.name")
Exemplo n.º 12
0
 def downloads(self, plugin_id: str, api: API) -> Optional[int]:
     details: Document = api.add("list").get(params={"pluginId": plugin_id})
     repo = details.getElementsByTagName("plugin-repository")[0]
     category = repo.getElementsByTagName("category")
     if len(category) == 0:
         return None
     plugin: Element = category[0].getElementsByTagName("idea-plugin")[0]
     return int(plugin.getAttribute("downloads"))
Exemplo n.º 13
0
 def version(self, plugin_id: str, api: API) -> Optional[str]:
     details: Document = api.add("list").get(params={"pluginId": plugin_id})
     repo = details.getElementsByTagName("plugin-repository")[0]
     category = repo.getElementsByTagName("category")
     if len(category) == 0:
         return None
     plugin: Element = category[0].getElementsByTagName("idea-plugin")[0]
     return plugin.getElementsByTagName("version")[0].firstChild.nodeValue
Exemplo n.º 14
0
 def tests(self,
           user: str,
           repo: str,
           api: API,
           branch: str = None) -> Optional[TestResults]:
     total, passed, failed = 0, 0, 0
     api.add(user, repo)
     if branch:
         api.add("branch", branch)
     jobs = get(api.get(), "build.jobs")
     for job in jobs:
         total += job.get("testsCount")
         passed += job.get("passedTestsCount")
         failed += job.get("failedTestsCount")
     return TestResults(passed=passed,
                        failed=failed,
                        skipped=total - passed - failed)
Exemplo n.º 15
0
 def downloads(self, project: str, api: API) -> Optional[int]:
     try:
         doc: Document = api.add(project).get()
         if type(doc) != Document:
             return None
         return doc.getElementsByTagName("text")[-1].firstChild.nodeValue.upper()
     except ExpatError:
         return None
Exemplo n.º 16
0
 def rating(self, app: str, api: API) -> Optional[float]:
     soup = api.add(app).get(params={"hl": "en-GB"})
     rating_string = soup.find("meta",
                               itemprop="ratingValue").get("content")
     if rating_string is None:
         return None
     else:
         return round(float(rating_string), 1)
Exemplo n.º 17
0
 def stars(self, owner: str, repo: str, token: str, api: API) -> Optional[int]:
     repo_info = api.add("repos", owner, repo).get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return repo_info.get("stargazers_count")
Exemplo n.º 18
0
 def grade(self, language: str, owner: str, repo: str,
           api: API) -> Optional[str]:
     lgtm_details = api.add("projects", "g", owner, repo).get()
     grade = None
     for l in lgtm_details.get("languages", []):
         if l.get("language") == language:
             grade = l.get("grade")
             break
     return grade
Exemplo n.º 19
0
 def build_status(
     self, user: str, project: str, token: str, api: API, branch: str = None
 ) -> Optional[str]:
     state_map = {"passed": "pass", "started": "building", "failed": "fail"}
     branch = "master" if branch is None else branch
     travis_project = api.add("repos", user, project, "branches", branch).get(
         headers={"Authorization": "token {}".format(token)}
     )
     return state_map.get(get(travis_project, "branch.state"))
Exemplo n.º 20
0
 def votes(self, package: str, api: API) -> Optional[str]:
     package_info = api.get(params={
         "v": "5",
         "type": "info",
         "arg[]": package
     })
     if len(package_info["results"]) == 0:
         return None
     return package_info["results"][0].get("NumVotes")
Exemplo n.º 21
0
 def build_status(self, user: str, project: str, api: API) -> Optional[str]:
     latest_builds = api.add("repositories", user, project,
                             "buildhistory").get()
     latest_build_result = latest_builds["results"][0]["status"]
     if latest_build_result == 10:
         return "pass"
     elif latest_build_result < 0:
         return "fail"
     else:
         return "building"
Exemplo n.º 22
0
 def language_count(
     self, owner: str, repo: str, token: str, api: API
 ) -> Optional[int]:
     languages = api.add("repos", owner, repo, "languages").get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return len(languages)
Exemplo n.º 23
0
 def latest_release(
     self, owner: str, repo: str, token: str, api: API
 ) -> Optional[str]:
     release_info = api.add("repos", owner, repo, "releases", "latest").get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     return release_info.get("tag_name")
Exemplo n.º 24
0
 def installs(self,
              plugin: str,
              api: API,
              version: str = None) -> Optional[int]:
     plugin_installs = api.add("plugin-installation-trend", plugin).get()
     installations = plugin_installs.get("installationsPerVersion", {})
     if version:
         return installations.get(version)
     else:
         return reduce(lambda x, v: x + v, installations.values(), 0)
Exemplo n.º 25
0
 def workflow_status(
     self, owner: str, repo: str, workflow: str, token: str, api: API
 ):
     try:
         doc: Document = api.add(owner).add(repo).add("workflows").add(workflow).add(
             "badge.svg"
         ).get()
         if not isinstance(doc, Document):
             return None
         return doc.getElementsByTagName("tspan")[3].firstChild.nodeValue
     except ExpatError:
         return None
Exemplo n.º 26
0
 def build_status(self,
                  project: str,
                  api: API,
                  version: str = None) -> Optional[str]:
     if version is None:
         version = "latest"
     versions = api.add("version").get(params={
         "project__slug": project,
         "active": True
     })
     for result in versions.get("results", []):
         if result.get("slug") == version:
             return "pass" if result.get("built") else "fail"
     return None
Exemplo n.º 27
0
 def top_language(
     self, owner: str, repo: str, token: str, api: API
 ) -> Optional[Dict]:
     languages = api.add("repos", owner, repo, "languages").get(
         headers={
             "accept": "application/vnd.github.v3+json",
             "Authorization": f"token {token}",
         }
     )
     top_lang = None
     top_size, total = 0, 0
     for lang, size in languages.items():
         if size > top_size:
             top_lang = lang
             top_size = size
         total += size
     if top_lang is None:
         return None
     else:
         return {"lang": top_lang, "percentage": round((top_size / total) * 100, 1)}
Exemplo n.º 28
0
 def wrapper(*args, **kwargs):
     try:
         api = API(
             base_url=args[0].base_url,
             deserializer=args[0].deserializer,
             suffix=args[0].suffix,
         )
         return func(*args, **kwargs, api=api)
     except HttpNotFoundException:
         return None
     except (HttpClientException, HttpServerException) as e:
         LOGGER.error(f"Unexpected Error: Target {e.target}")
         LOGGER.error(f"Code: {e.code}")
         LOGGER.error(f"Response: {e.response}")
         return None
     except exceptions.RequestException as e:
         LOGGER.error(f"Unexpected Requests Error!")
         LOGGER.error(str(e))
         return None
     except AssertionError:
         return None
Exemplo n.º 29
0
 def alerts(self, owner: str, repo: str, api: API) -> Optional[int]:
     lgtm_details = api.add("projects", "g", owner, repo).get()
     alerts = 0
     for language in lgtm_details.get("languages", []):
         alerts += language.get("alerts", 0)
     return alerts
Exemplo n.º 30
0
 def version(self, crate: str, api: API) -> Optional[str]:
     crate_info = api.add(crate).get()
     return get(crate_info, "crate.max_version")