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

Callers 1

prepare_initrdFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected