diff --git a/source/contrib/automated_contributors.py b/source/contrib/automated_contributors.py new file mode 100644 index 00000000..1a21e30c --- /dev/null +++ b/source/contrib/automated_contributors.py @@ -0,0 +1,52 @@ +import os +from github import Github +from github import Auth + +# get access token from environment variable in github actions +access_token = os.environ.get("GITHUB_TOKEN") + +if not access_token: + raise ValueError("GITHUB_TOKEN environment variable not set") + +auth = Auth.Token(access_token) +g = Github(auth=auth) + +repositories = [ + "openchemistry/avogadrolibs", + "openchemistry/avogadroapp", + "openchemistry/fragments", + "openchemistry/molecules", + "openchemistry/crystals", + "openchemistry/avogenerators", + "openchemistry/avogadro-commands", + "openchemistry/avogadro-cclib", +] + +unique_contributors = set() +contributors_list = [] + + +for repo_name in repositories: + repo = g.get_repo(repo_name) + contributors = repo.get_contributors() + + for contributor in contributors: + username = contributor.login + + if username not in unique_contributors: + user = g.get_user(username) + + # check if the user has a full name and if so, use it else use username + if user is not None and user.name is not None: + contributors_list.append((user.name, username)) + else: + contributors_list.append((username, username)) + unique_contributors.add(username) + +contributors_list.sort() + +with open("contributors.md", "w") as contributors_file: + for real_name, username in contributors_list: + contributors_file.write(f"- [{real_name}](https://github.com/{username})\n") + +print("Contributors have been updated in contributors.md") diff --git a/source/contrib/contributors.md b/source/contrib/contributors.md index 81957d6e..94134183 100644 --- a/source/contrib/contributors.md +++ b/source/contrib/contributors.md @@ -138,3 +138,4 @@ - yavgech - yuri@FreeBSD - Ondřej Čertík +- Kailin Xing \ No newline at end of file diff --git a/source/requirements.txt b/source/requirements.txt index cf44fbec..1344f439 100644 --- a/source/requirements.txt +++ b/source/requirements.txt @@ -5,3 +5,4 @@ pydata-sphinx-theme sphinx-design sphinx-copybutton linkify-it-py +PyGithub \ No newline at end of file