Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/sentry_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from __future__ import annotations

import base64
import logging
import os
from configparser import ConfigParser
from functools import lru_cache

import requests

LOGGING_LEVEL = os.environ.get("LOGGING_LEVEL", logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(LOGGING_LEVEL)

SENTRY_CONFIG_API_URL = (
"https://api.github.com/repos/{owner}/.sentry/contents/sentry_config.ini"
)
Expand All @@ -17,20 +23,26 @@
"Accept": "application/vnd.github+json",
"Authorization": f"token {token}",
}
api_url = SENTRY_CONFIG_API_URL.replace("{owner}", org)
# - Get meta about sentry_config.ini file
resp = requests.get(api_url, headers=headers)
resp.raise_for_status()
meta = resp.json()

if meta["type"] != "file":
# XXX: custom error
raise Exception(meta["type"])

assert meta["encoding"] == "base64", meta["encoding"]
file_contents = base64.b64decode(meta["content"]).decode()

# - Read ini file and assertions
cp = ConfigParser()
cp.read_string(file_contents)
return cp.get("sentry-github-actions-app", "dsn")
try:
api_url = SENTRY_CONFIG_API_URL.replace("{owner}", org)

# - Get meta about sentry_config.ini file
resp = requests.get(api_url, headers=headers)
resp.raise_for_status()
meta = resp.json()

if meta["type"] != "file":
# XXX: custom error
raise Exception(meta["type"])

assert meta["encoding"] == "base64", meta["encoding"]
file_contents = base64.b64decode(meta["content"]).decode()

# - Read ini file and assertions
cp = ConfigParser()
cp.read_string(file_contents)
return cp.get("sentry-github-actions-app", "dsn")

except Exception as e:
logger.exception(e)
raise e