From d8debf0ab77346f2c05c5e08ff96a19c87ab92e3 Mon Sep 17 00:00:00 2001 From: kailinxGitHub <67965369+kailinxGitHub@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:06:39 +0000 Subject: [PATCH 1/5] new contributor added --- source/contrib/contributors.md | 1 + 1 file changed, 1 insertion(+) 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 From 0f82072394e8f57cd4aa4d2e56dfb76148c6a9d7 Mon Sep 17 00:00:00 2001 From: kailinxGitHub <67965369+kailinxGitHub@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:06:58 +0000 Subject: [PATCH 2/5] PyGithub requirement added --- source/requirements.txt | 1 + 1 file changed, 1 insertion(+) 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 From 4d65063a4b81d0ca166f9b4fbb1f94c1771138b4 Mon Sep 17 00:00:00 2001 From: kailinxGitHub <67965369+kailinxGitHub@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:07:27 +0000 Subject: [PATCH 3/5] automated contributors python script added --- source/contrib/automated_contributors.py | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source/contrib/automated_contributors.py diff --git a/source/contrib/automated_contributors.py b/source/contrib/automated_contributors.py new file mode 100644 index 00000000..633278a9 --- /dev/null +++ b/source/contrib/automated_contributors.py @@ -0,0 +1,47 @@ +from github import Github +from github import Auth + +access_token = "YOUR_ACCESS_TOKEN" + +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", + "cryos/avogadro", +] + +unique_contributors = set() + +with open("contributors.md", "w") as contributors_file: + for repo_name in repositories: + repo = g.get_repo(repo_name) + contributors = repo.get_contributors() + + for contributor in contributors: + username = contributor.login + unique_contributors.add(username) + contributors_file.write(f"- {username}\n") + +sorted_contributors = sorted(unique_contributors) + +with open("credits.md", "r") as credits_file: + credits_content = credits_file.read() + +updated_credits_content = credits_content.replace( + "```{include} contributors.md```", + f"```{{include}} contributors.md\n\n" + "\n".join(sorted_contributors) + "\n```" +) + +with open("credits.md", "w") as credits_file: + credits_file.write(updated_credits_content) + +print("Contributors have been updated in contributors.md and credits.md.") From e40f4fbb1c310397885248c2482842a46d1104c5 Mon Sep 17 00:00:00 2001 From: ASK-03 Date: Tue, 5 Mar 2024 13:53:41 +0530 Subject: [PATCH 4/5] Added reviewed changes --- source/contrib/automated_contributors.py | 32 +++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/contrib/automated_contributors.py b/source/contrib/automated_contributors.py index 633278a9..79784acc 100644 --- a/source/contrib/automated_contributors.py +++ b/source/contrib/automated_contributors.py @@ -1,10 +1,14 @@ +import os from github import Github from github import Auth -access_token = "YOUR_ACCESS_TOKEN" +# get access token from environment variable in github actions +access_token = os.environ.get("GITHUB_TOKEN") -auth = Auth.Token(access_token) +if not access_token: + raise ValueError("GITHUB_TOKEN environment variable not set") +auth = Auth.Token(access_token) g = Github(auth=auth) repositories = [ @@ -16,7 +20,6 @@ "openchemistry/avogenerators", "openchemistry/avogadro-commands", "openchemistry/avogadro-cclib", - "cryos/avogadro", ] unique_contributors = set() @@ -28,20 +31,15 @@ for contributor in contributors: username = contributor.login - unique_contributors.add(username) - contributors_file.write(f"- {username}\n") - -sorted_contributors = sorted(unique_contributors) - -with open("credits.md", "r") as credits_file: - credits_content = credits_file.read() -updated_credits_content = credits_content.replace( - "```{include} contributors.md```", - f"```{{include}} contributors.md\n\n" + "\n".join(sorted_contributors) + "\n```" -) + if username not in unique_contributors: + user = g.get_user(username) -with open("credits.md", "w") as credits_file: - credits_file.write(updated_credits_content) + # 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_file.write(f"- [{user.name}]({user.html_url})\n") + else: + contributors_file.write(f"- [{username}](https://github.com/{username})\n") + unique_contributors.add(username) -print("Contributors have been updated in contributors.md and credits.md.") +print("Contributors have been updated in contributors.md") From bf32bd55e5401a036ab233883f0b6d4243ec0939 Mon Sep 17 00:00:00 2001 From: ASK-03 Date: Sun, 10 Mar 2024 02:02:23 +0530 Subject: [PATCH 5/5] Sort the contributors list --- source/contrib/automated_contributors.py | 39 ++++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/source/contrib/automated_contributors.py b/source/contrib/automated_contributors.py index 79784acc..1a21e30c 100644 --- a/source/contrib/automated_contributors.py +++ b/source/contrib/automated_contributors.py @@ -23,23 +23,30 @@ ] 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 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_file.write(f"- [{user.name}]({user.html_url})\n") - else: - contributors_file.write(f"- [{username}](https://github.com/{username})\n") - unique_contributors.add(username) + 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")