Skip to content

Commit

Permalink
Add workflow to update contributors list in README.md (#30)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
vamc-k and github-actions[bot] authored May 22, 2024
1 parent 78c7950 commit 88a4445
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/update-contributors.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@ npx @11ty/eleventy --serve --port=8080

## License
[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](LICENSE.md)

## Contributors

<!-- CONTRIBUTORS_START -->
<table>
<tr>
<td align="center"><a href="https://github.com/bhansa"><img src="https://avatars.githubusercontent.com/u/9723884?v=4" width="100px" alt="Bharat Saraswat"/><br /><sub><b>Bharat Saraswat</b></sub></a></td>
<td align="center"><a href="https://github.com/anistark"><img src="https://avatars.githubusercontent.com/u/5357586?v=4" width="100px" alt="Ani"/><br /><sub><b>Ani</b></sub></a></td>
<td align="center"><a href="https://github.com/ayushjain01"><img src="https://avatars.githubusercontent.com/u/67141217?v=4" width="100px" alt="Ayush Jain"/><br /><sub><b>Ayush Jain</b></sub></a></td>
<td align="center"><a href="https://github.com/Techiezy"><img src="https://avatars.githubusercontent.com/u/37692230?v=4" width="100px" alt="Techiezy"/><br /><sub><b>Techiezy</b></sub></a></td>
<td align="center"><a href="https://github.com/TeeWrath"><img src="https://avatars.githubusercontent.com/u/117584718?v=4" width="100px" alt="Subroto Banerjee"/><br /><sub><b>Subroto Banerjee</b></sub></a></td>
<td align="center"><a href="https://github.com/vamc-k"><img src="https://avatars.githubusercontent.com/u/11007620?v=4" width="100px" alt="Vamsi Krishna Kolli"/><br /><sub><b>Vamsi Krishna Kolli</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/devom-glitch"><img src="https://avatars.githubusercontent.com/u/50795140?v=4" width="100px" alt="Priyanshu"/><br /><sub><b>Priyanshu</b></sub></a></td>
<td align="center"><a href="https://github.com/abhishekmishragithub"><img src="https://avatars.githubusercontent.com/u/38150419?v=4" width="100px" alt="Abhishek"/><br /><sub><b>Abhishek</b></sub></a></td>
<td align="center"><a href="https://github.com/Schefflera-Arboricola"><img src="https://avatars.githubusercontent.com/u/91629733?v=4" width="100px" alt="Aditi Juneja"/><br /><sub><b>Aditi Juneja</b></sub></a></td>
<td align="center"><a href="https://github.com/wavicles"><img src="https://avatars.githubusercontent.com/u/7612306?v=4" width="100px" alt="Praveen (Gnovi)"/><br /><sub><b>Praveen (Gnovi)</b></sub></a></td>
</tr>
</table>
<!-- CONTRIBUTORS_END -->
54 changes: 54 additions & 0 deletions update_contributors.py
Original file line number Diff line number Diff line change
@@ -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 = "<!-- CONTRIBUTORS_START -->"
end_marker = "<!-- CONTRIBUTORS_END -->"
start = readme_content.index(start_marker) + len(start_marker)
end = readme_content.index(end_marker)

rows_per_column = 6
new_contributors_section = "<table>\n <tr>"
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 <td align="center"><a href="{html_url}"><img src="{avatar_url}" width="100px" alt="{name}"/><br /><sub><b>{name}</b></sub></a></td>"""

if (i + 1) % rows_per_column == 0:
new_contributors_section += "\n </tr>\n <tr>"

# Close the last table row
new_contributors_section += "\n </tr>\n</table>"
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()

0 comments on commit 88a4445

Please sign in to comment.