Skip to content

Commit

Permalink
Ensure exit on expected failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
danielebra committed Mar 5, 2024
1 parent 1a2d1b7 commit 46c0f1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions release_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class InfoFilter(logging.Filter):
def filter(self, record):
return record.levelno == logging.INFO

class SimpleReleaseNotesError(Exception):
pass


# Only route info logs to stdout, the rest goes to stderr
LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,11 +67,12 @@ def create_release(
response = requests.post(url, json=data, headers=self._headers)
if response.status_code == 201:
LOGGER.debug(f"Release created for tag: {release_tag}")
return response.json()
else:
LOGGER.error(
f"Failed to create release for {release_tag}: {response.content}"
)
return response.json()
raise SimpleReleaseNotesError("Failed to create release")

def update_release(
self,
Expand Down Expand Up @@ -105,6 +109,7 @@ def update_release(
LOGGER.error(
f"Failed to update release for {release_id}: {response.json()}"
)
raise SimpleReleaseNotesError("Failed to update release")
return response.json()

def generate_release_notes(
Expand All @@ -119,7 +124,7 @@ def generate_release_notes(
response = requests.post(url, json=data, headers=self._headers)
if response.status_code != 200:
LOGGER.error(f"Failed to generate release notes for {release_tag}")
return None
raise SimpleReleaseNotesError("Failed to generate release notes")
payload = response.json()
return {"title": payload["name"], "body": payload["body"]}

Expand Down

0 comments on commit 46c0f1e

Please sign in to comment.