11from __future__ import annotations
22
33import base64
4+ import logging
5+ import os
46from configparser import ConfigParser
57from functools import lru_cache
68
79import requests
810
11+ LOGGING_LEVEL = os .environ .get ("LOGGING_LEVEL" , logging .INFO )
12+ logger = logging .getLogger (__name__ )
13+ logger .setLevel (LOGGING_LEVEL )
14+
915SENTRY_CONFIG_API_URL = (
1016 "https://api.github.com/repos/{owner}/.sentry/contents/sentry_config.ini"
1117)
@@ -17,20 +23,26 @@ def fetch_dsn_for_github_org(org: str, token: str) -> str:
1723 "Accept" : "application/vnd.github+json" ,
1824 "Authorization" : f"token { token } " ,
1925 }
20- api_url = SENTRY_CONFIG_API_URL .replace ("{owner}" , org )
21- # - Get meta about sentry_config.ini file
22- resp = requests .get (api_url , headers = headers )
23- resp .raise_for_status ()
24- meta = resp .json ()
25-
26- if meta ["type" ] != "file" :
27- # XXX: custom error
28- raise Exception (meta ["type" ])
29-
30- assert meta ["encoding" ] == "base64" , meta ["encoding" ]
31- file_contents = base64 .b64decode (meta ["content" ]).decode ()
32-
33- # - Read ini file and assertions
34- cp = ConfigParser ()
35- cp .read_string (file_contents )
36- return cp .get ("sentry-github-actions-app" , "dsn" )
26+ try :
27+ api_url = SENTRY_CONFIG_API_URL .replace ("{owner}" , org )
28+
29+ # - Get meta about sentry_config.ini file
30+ resp = requests .get (api_url , headers = headers )
31+ resp .raise_for_status ()
32+ meta = resp .json ()
33+
34+ if meta ["type" ] != "file" :
35+ # XXX: custom error
36+ raise Exception (meta ["type" ])
37+
38+ assert meta ["encoding" ] == "base64" , meta ["encoding" ]
39+ file_contents = base64 .b64decode (meta ["content" ]).decode ()
40+
41+ # - Read ini file and assertions
42+ cp = ConfigParser ()
43+ cp .read_string (file_contents )
44+ return cp .get ("sentry-github-actions-app" , "dsn" )
45+
46+ except Exception as e :
47+ logger .exception (e )
48+ raise e
0 commit comments