Skip to content

Commit

Permalink
contributors_logo_change
Browse files Browse the repository at this point in the history
  • Loading branch information
vrunda2005 committed Dec 26, 2024
1 parent 86f6802 commit 4aa2c93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
52 changes: 33 additions & 19 deletions .github/workflows/contributors_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ on:
push:
branches:
- main
schedule:
- cron: "*/30 * * * *" # Runs every 30 minutes
workflow_dispatch:

permissions:
contents: write

jobs:
update-readme:
runs-on: ubuntu-latest
Expand All @@ -16,39 +21,48 @@ jobs:

- name: Fetch Contributors and Update README
env:
REPO_NAME: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CONTRIBUTORS_IMAGE_URL="https://contrib.rocks/preview?repo=Programming-Club-Ahmedabad-University%2FWOC-2024"
# Automatically get the repository name
REPO_NAME="${{ github.repository }}"
README_PATH="README.md"
# File to update
README_PATH="README.md"
if [ -f "$README_PATH" ]; then
README_CONTENT=$(cat "$README_PATH")
else
echo "README.md not found!"
# Fetch top 4 contributors from GitHub API
CONTRIBUTORS=$(curl -H "Authorization: token $GH_TOKEN" -s "https://api.github.com/repos/${REPO_NAME}/contributors?per_page=4" | \
jq -r '.[] | "- [![@\(.login)](\(.avatar_url)?size=50)](https://github.com/\(.login)) [@\(.login)](https://github.com/\(.login))"')
# Check if contributors were fetched successfully
if [ -z "$CONTRIBUTORS" ]; then
echo "No contributors found"
exit 1
fi
#contributors' markdown section
CONTRIBUTORS_SECTION="<!-- CONTRIBUTORS START -->\n"
CONTRIBUTORS_SECTION+="<div align=\"center\">\n"
CONTRIBUTORS_SECTION+=" <a href=\"https://github.com/${REPO_NAME}/graphs/contributors\">\n"
CONTRIBUTORS_SECTION+=" <img src=\"${CONTRIBUTORS_IMAGE_URL}\" />\n"
CONTRIBUTORS_SECTION+=" </a>\n"
CONTRIBUTORS_SECTION+="</div>\n"
CONTRIBUTORS_SECTION+="<!-- CONTRIBUTORS END -->"
# Get the current timestamp in IST
LAST_UPDATED=$(TZ='Asia/Kolkata' date '+%Y-%m-%d %I:%M:%S %p IST')
# Generate contributors section
CONTRIBUTORS_SECTION="## 👥 Contributors\n\n"
CONTRIBUTORS_SECTION+="<a href=\"https://github.com/${REPO_NAME}/graphs/contributors\">\n"
CONTRIBUTORS_SECTION+=" <img src=\"https://contrib.rocks/image?repo=${REPO_NAME}\" alt=\"Contributors Group Image\" />\n"
CONTRIBUTORS_SECTION+="</a>\n\n"
CONTRIBUTORS_SECTION+="### Top Contributors\n"
CONTRIBUTORS_SECTION+="${CONTRIBUTORS}\n\n"
CONTRIBUTORS_SECTION+="<p><i>Last updated: ${LAST_UPDATED}</i></p>\n"
# updating readme.md
UPDATED_README=$(echo "$README_CONTENT" | sed -e '/<!-- CONTRIBUTORS START -->/,/<!-- CONTRIBUTORS END -->/c\'"$CONTRIBUTORS_SECTION")
# Replace the relevant section in the README
UPDATED_README=$(sed -e '/### Top Contributors/,/<!-- END -->/c\'"$CONTRIBUTORS_SECTION" "$README_PATH")
# Write changes back to README.md
echo "$UPDATED_README" > "$README_PATH"
# Checking if the file has changed
# Commit and push changes if there's a difference
if ! git diff --exit-code "$README_PATH"; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add "$README_PATH"
git commit -m "Update contributors section in README.md using contrib.rocks"
git commit -m "Update contributors section in README.md"
git push
else
echo "No changes detected in README.md"
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ Read our [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) to ensure a respectful and inc

## 👥 Contributors

<!-- CONTRIBUTORS START -->
<div align="center">
<a href="https://github.com/Programming-Club-Ahmedabad-University/WOC-2024/graphs/contributors">
<img src="https://contrib.rocks/preview?repo=Programming-Club-Ahmedabad-University%2FWOC-2024" />
</a>
</div>
<!-- CONTRIBUTORS END -->
<a href="https://github.com/Programming-Club-Ahmedabad-University/WOC-2024/graphs/contributors">
<img src="https://contrib.rocks/image?repo=Programming-Club-Ahmedabad-University/WOC-2024" alt="Contributors Group Image" />
</a>

### Top Contributors

<!-- START -->
<!-- END -->

## 🆘 Need Help?

Expand Down

0 comments on commit 4aa2c93

Please sign in to comment.