From 88a44459afeb3f0e5f3da78b9acbc721cb8099dc Mon Sep 17 00:00:00 2001 From: Vamsi Krishna Kolli <11007620+vamc-k@users.noreply.github.com> Date: Wed, 22 May 2024 11:01:16 +0530 Subject: [PATCH] Add workflow to update contributors list in README.md (#30) * add workflow to update contributors list in README.md * Update contributors * Updated workflow to trigger only if commits to main * Add check to skip commit if no changes --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/update-contributors.yml | 38 ++++++++++++++++ README.md | 21 +++++++++ update_contributors.py | 54 +++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 .github/workflows/update-contributors.yml create mode 100644 update_contributors.py diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml new file mode 100644 index 0000000..4d6fd5c --- /dev/null +++ b/.github/workflows/update-contributors.yml @@ -0,0 +1,38 @@ +name: Update Contributors + +on: + push: + branches: + - main + workflow_dispatch: # Allows manual trigger of the workflow + +jobs: + update-contributors: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Install dependencies + run: pip install requests + + - name: Update README.md with contributors + run: python update_contributors.py + + - name: Check for changes and commit + run: | + if git diff --quiet; then + echo "No changes to commit"; + else + git config --global user.name 'github-actions[bot]' + git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add README.md + git commit -m 'Update contributors' + git push + fi diff --git a/README.md b/README.md index b25ad65..300af94 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,24 @@ npx @11ty/eleventy --serve --port=8080 ## License [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](LICENSE.md) + +## Contributors + + + + + + + + + + + + + + + + + +
Bharat Saraswat
Bharat Saraswat
Ani
Ani
Ayush Jain
Ayush Jain
Techiezy
Techiezy
Subroto Banerjee
Subroto Banerjee
Vamsi Krishna Kolli
Vamsi Krishna Kolli
Priyanshu
Priyanshu
Abhishek
Abhishek
Aditi Juneja
Aditi Juneja
Praveen (Gnovi)
Praveen (Gnovi)
+ diff --git a/update_contributors.py b/update_contributors.py new file mode 100644 index 0000000..713afac --- /dev/null +++ b/update_contributors.py @@ -0,0 +1,54 @@ +import os +import requests + +REPO_OWNER = "pythonindia" +REPO_NAME = "inpycon2024" +API_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/contributors" + +def get_contributors(): + response = requests.get(API_URL) + response.raise_for_status() + return response.json() + +def get_contributor_details(username): + url = f"https://api.github.com/users/{username}" + response = requests.get(url) + response.raise_for_status() + return response.json() + +def update_readme(contributors): + readme_path = "./README.md" + with open(readme_path, "r") as file: + readme_content = file.read() + + start_marker = "" + end_marker = "" + start = readme_content.index(start_marker) + len(start_marker) + end = readme_content.index(end_marker) + + rows_per_column = 6 + new_contributors_section = "\n " + for i, contributor in enumerate(contributors): + contributor_details = get_contributor_details(contributor['login']) + name = contributor_details['name'] or contributor_details['login'] + avatar_url = contributor_details['avatar_url'] + html_url = contributor_details['html_url'] + + new_contributors_section += f"""\n """ + + if (i + 1) % rows_per_column == 0: + new_contributors_section += "\n \n " + + # Close the last table row + new_contributors_section += "\n \n
{name}
{name}
" + new_readme_content = f"{readme_content[:start]}\n{new_contributors_section}\n{readme_content[end:]}" + + with open(readme_path, "w") as file: + file.write(new_readme_content) + +def main(): + contributors = get_contributors() + update_readme(contributors) + +if __name__ == "__main__": + main() \ No newline at end of file