Skip to content

Commit

Permalink
Support that the SECURITY.md is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 18, 2024
1 parent 2ca2b71 commit 280e32b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions tag_publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tag_publish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 280e32b

Please sign in to comment.