Skip to content

Commit

Permalink
moved some assignments outside of the try block when rawifying github…
Browse files Browse the repository at this point in the history
… urls
  • Loading branch information
jspaaks committed Sep 5, 2023
1 parent ca47fdd commit 6b73841
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/cffconvert/cli/rawify_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ def rawify_url(url):
assert reponame is not None, "URL should include the name of the repository."
if refvalue is None:
default_branch = None
repos_api = f"https://api.github.com/repos/{ownername}/{reponame}"
headers = github_api_version_header
headers.update({"Accept": "application/vnd.github+json"})
token = os.environ.get("CFFCONVERT_API_TOKEN")
if token is None:
# Proceed with making the call without authenticating -- stricter rate limits apply
pass
else:
headers.update({"Authorization": f"Bearer { token }"})

try:
repos_api = f"https://api.github.com/repos/{ownername}/{reponame}"
headers = github_api_version_header
headers.update({"Accept": "application/vnd.github+json"})
token = os.environ.get("CFFCONVERT_API_TOKEN")
if token is None:
# Proceed with making the call without authenticating -- stricter rate limits apply
pass
else:
headers.update({"Authorization": f"Bearer { token }"})
response = requests.get(repos_api, headers=headers, timeout=10)
if response.ok:
default_branch = response.json().get("default_branch")
finally:
refvalue = default_branch or "main"

if filename == "":
filename = "CITATION.cff"

return f"https://raw.githubusercontent.com/{ownername}/{reponame}/{refvalue}/{filename}"

# return unrecognized URLs as-is
Expand Down

0 comments on commit 6b73841

Please sign in to comment.