Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #70 Add automated contributors #73

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions source/contrib/automated_contributors.py
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cryos/avogadro repository is now closed, so I moved the contributors to a separate list already. That way we don't continue to query for the same response.

]

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to get the full name if available .. something like:

    user = g.get_user(username)
    if user.name is not None:
        contributors_file.write(f"- [{user.name}](https://github.com/{username})")
    else:
        contributors_file.write(f"- [{username}](https://github.com/{username})")


sorted_contributors = sorted(unique_contributors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you already wrote the contributors_file .. so you want to write the file after sorting.


with open("credits.md", "r") as credits_file:
credits_content = credits_file.read()

updated_credits_content = credits_content.replace(
"```{include} contributors.md```",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this - the Sphinx / Myst build will include the credits.md file automatically - here's the built file:

https://two.avogadro.cc/contrib/credits.html

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.")
1 change: 1 addition & 0 deletions source/contrib/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@
- yavgech
- yuri@FreeBSD
- Ondřej Čertík
- Kailin Xing
1 change: 1 addition & 0 deletions source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pydata-sphinx-theme
sphinx-design
sphinx-copybutton
linkify-it-py
PyGithub