Skip to content

Commit

Permalink
1.3 version, update to return full name if available
Browse files Browse the repository at this point in the history
  • Loading branch information
SeverusYixin committed Oct 11, 2024
1 parent 49ccc5e commit f0a5956
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions scripts/auto-add-github-resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def complete_github_data(github_repo_url):
- github_repo_url (str): The URL of the GitHub repository to retrieve metadata from.
Returns:
- entry (dict): A dictionary containing the repository metadata.
- entry (dict): A dictionary containing the repository metadata in the correct order.
"""
token = os.getenv("GITHUB_API_KEY")
if not token:
Expand All @@ -71,14 +71,15 @@ def complete_github_data(github_repo_url):

entry = {}

# Authors (Contributors)
# Contributors (Full name if available, otherwise username)
try:
contributors = repo.get_contributors()
if contributors.totalCount > 0:
entry['author'] = ", ".join([contrib.login for contrib in contributors])
# Use the contributor's full name if available, otherwise use the username
entry['author'] = ", ".join([contrib.name if contrib.name else contrib.login for contrib in contributors])
else:
entry['author'] = ""
except GithubException as e: # Correct exception reference
except GithubException as e:
if e.status == 403:
print(f"403 error: Cannot access contributors for {repo.full_name}. Skipping this step.")
entry['author'] = "Contributors not accessible"
Expand All @@ -101,11 +102,11 @@ def complete_github_data(github_repo_url):
# Publication date (first release date or creation date)
entry['publication_date'] = get_publication_date(repo)

# Tags (topics?):So how should we define the tags of the github resource?
# Tags (topics): should we use the repository topics or the README.md file?
topics = repo.get_topics()
entry['tags'] = ", ".join(topics) if topics else ""

# Type: So how should we define the type of the github resource?
# Typehow should we determine this for a GitHub repository?
entry['type'] = ""

# Repository URL
Expand All @@ -114,6 +115,7 @@ def complete_github_data(github_repo_url):
return entry



def get_publication_date(repo):
"""
Retrieves the publication date of the repository. If the repository has releases,
Expand All @@ -135,4 +137,4 @@ def get_publication_date(repo):


if __name__ == "__main__":
main()
main()

0 comments on commit f0a5956

Please sign in to comment.