From 280e32b6f54926b6980193e956cc4a956ee64b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 18 Nov 2024 12:42:43 +0100 Subject: [PATCH] Support that the SECURITY.md is absent --- tag_publish/__init__.py | 13 ++++++++++--- tag_publish/cli.py | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tag_publish/__init__.py b/tag_publish/__init__.py index 97de100..b5f7592 100644 --- a/tag_publish/__init__.py +++ b/tag_publish/__init__.py @@ -67,9 +67,16 @@ def get_security_md(gh: GH) -> security_md.Security: gh: The GitHub helper """ - security_file = gh.repo.get_contents("SECURITY.md") - assert isinstance(security_file, github.ContentFile.ContentFile) - return security_md.Security(security_file.decoded_content.decode("utf-8")) + try: + security_file = gh.repo.get_contents("SECURITY.md") + assert isinstance(security_file, github.ContentFile.ContentFile) + return security_md.Security(security_file.decoded_content.decode("utf-8")) + except github.GithubException as exception: + if exception.status == 404: + print("No security file in the repository") + return security_md.Security("") + else: + raise exception def merge(default_config: Any, config: Any) -> Any: diff --git a/tag_publish/cli.py b/tag_publish/cli.py index 4720732..61afb66 100644 --- a/tag_publish/cli.py +++ b/tag_publish/cli.py @@ -267,9 +267,12 @@ def _handle_docker_publish( ) security_text = "" if local: - with open("SECURITY.md", encoding="utf-8") as security_file: - security_text = security_file.read() - security = security_md.Security(security_text) + if os.path.exists("SECURITY.md"): + with open("SECURITY.md", encoding="utf-8") as security_file: + security_text = security_file.read() + security = security_md.Security(security_text) + else: + security = security_md.Security("") else: security = tag_publish.get_security_md(github)