MCPcopy
hub / github.com/psf/black / http_get

Function http_get

scripts/diff_shades_gha_helper.py:62–82  ·  view source on GitHub ↗
(url: str, *, is_json: bool = True, **kwargs: Any)

Source from the content-addressed store, hash-verified

60
61
62def 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
85def get_latest_revision(ref: str) -> str:

Callers 4

get_latest_revisionFunction · 0.85
get_pr_branchesFunction · 0.85
get_pypi_versionFunction · 0.85
comment_bodyFunction · 0.85

Calls 1

loadsMethod · 0.80

Tested by

no test coverage detected