(url: str, *, is_json: bool = True, **kwargs: Any)
| 60 | |
| 61 | |
| 62 | def http_get(url: str, *, is_json: bool = True, **kwargs: Any) -> Any: |
| 63 | headers = kwargs.get("headers") or {} |
| 64 | headers["User-Agent"] = USER_AGENT |
| 65 | if "github" in url: |
| 66 | if GH_API_TOKEN: |
| 67 | headers["Authorization"] = f"token {GH_API_TOKEN}" |
| 68 | headers["Accept"] = "application/vnd.github.v3+json" |
| 69 | kwargs["headers"] = headers |
| 70 | |
| 71 | r = http.request("GET", url, **kwargs) |
| 72 | if is_json: |
| 73 | data = json.loads(r.data.decode("utf-8")) |
| 74 | else: |
| 75 | data = r.data |
| 76 | print(f"[INFO]: issued GET request for {r.geturl()}") |
| 77 | if not (200 <= r.status < 300): |
| 78 | pprint.pprint(dict(r.info())) |
| 79 | pprint.pprint(data) |
| 80 | raise RuntimeError(f"unexpected status code: {r.status}") |
| 81 | |
| 82 | return data |
| 83 | |
| 84 | |
| 85 | def get_latest_revision(ref: str) -> str: |
no test coverage detected