MCPcopy Create free account
hub / github.com/ClangBuiltLinux/boot-utils / get_gh_json

Function get_gh_json

utils.py:143–170  ·  view source on GitHub ↗

Query a GitHub API endpoint. Parameters: endpoint (str): The URL of the endpoint to query. Returns: A JSON object from the result of the query.

(endpoint: str)

Source from the content-addressed store, hash-verified

141
142
143def get_gh_json(endpoint: str) -> dict[str, Any]:
144 """
145 Query a GitHub API endpoint.
146
147 Parameters:
148 endpoint (str): The URL of the endpoint to query.
149
150 Returns:
151 A JSON object from the result of the query.
152 """
153 curl_cmd = ['curl', '-LSs']
154 if 'GITHUB_TOKEN' in os.environ:
155 # https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api
156 curl_cmd += [
157 '-H',
158 'Accept: application/vnd.github+json',
159 '-H',
160 f"Authorization: Bearer {os.environ['GITHUB_TOKEN']}",
161 ]
162 curl_cmd.append(endpoint)
163
164 try:
165 curl_out = subprocess.run(curl_cmd, capture_output=True, check=True, text=True).stdout
166 except subprocess.CalledProcessError as err:
167 msg = f"Failed to query GitHub API at {endpoint}: {err.stderr}"
168 raise RuntimeError(msg) from err
169
170 return json.loads(curl_out)
171
172
173def green(string: str) -> None:

Callers 1

prepare_initrdFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected