GitHub Repo Starred or Forked Notification #12592
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "GitHub Repo Starred or Forked Notification" | |
| on: | |
| # Runs your workflow when someone forks a repository. | |
| fork: | |
| # Runs your workflow when the workflow's repository is starred. | |
| # https://docs.github.com/cn/github-ae@latest/actions/using-workflows/events-that-trigger-workflows#watch | |
| watch: | |
| types: [started] | |
| jobs: | |
| bot: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - if: ${{ github.event_name == 'fork' }} | |
| run: | | |
| echo "🎉 triggered by a ${{ github.event_name }} event." | |
| echo "event_name=forked 🍴" >> $GITHUB_ENV | |
| - if: ${{ github.event_name == 'watch' }} | |
| run: | | |
| echo "🎉 triggered by a ${{ github.event_name }} event." | |
| echo "event_name=starred ✨" >> $GITHUB_ENV | |
| - name: Get repository information | |
| run: | | |
| result=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}") | |
| stars=$(echo $result | jq '.stargazers_count') | |
| forks=$(echo $result | jq '.forks_count') | |
| repo_name=$(echo $result | jq -r '.name') | |
| echo "Number of stars: $stars" | |
| echo "Number of forks: $forks" | |
| # Save the value to env | |
| echo "repo_stars=$stars" >> $GITHUB_ENV | |
| echo "repo_forks=$forks" >> $GITHUB_ENV | |
| echo "repo_name=$repo_name" >> $GITHUB_ENV | |
| - name: Get repo download count | |
| run: | | |
| download_count=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases" | jq '.[].assets[].download_count' | awk '{sum += $1} END {print sum}') | |
| echo "Number of downloads: $download_count" | |
| echo "download_count=$download_count" >> $GITHUB_ENV | |
| - name: Get user information | |
| id: check_conditions | |
| run: | | |
| # Fetch user's GitHub statistics | |
| earn_star_count=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.actor }}/repos?per_page=100&sort=pushed" | jq '[.[] | .stargazers_count] | add // 0') | |
| commit_count=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/search/commits?per_page=100&q=author:${{ github.actor }}" | jq -r '.total_count // 0') | |
| follower_count=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.actor }}" | jq '.followers // 0') | |
| echo "Star count: $earn_star_count" | |
| echo "Commit count: $commit_count" | |
| echo "Follower count: $follower_count" | |
| echo "earn_star_count=$earn_star_count" >> $GITHUB_ENV | |
| echo "commit_count=$commit_count" >> $GITHUB_ENV | |
| echo "follower_count=$follower_count" >> $GITHUB_ENV | |
| # Define threshold values for VIP-tiered notification filtering | |
| # Tier 1: Elite developers (any single condition triggers notification) | |
| ELITE_STARS=100 # Elite: User's repos have earned 100+ stars | |
| ELITE_COMMITS=5000 # Elite: User has made 5000+ commits | |
| ELITE_FOLLOWERS=500 # Elite: User has 500+ followers | |
| # Tier 2: Quality developers (must meet 2 conditions to trigger notification) | |
| QUALITY_STARS=20 # Quality: User's repos have earned 20+ stars | |
| QUALITY_COMMITS=1000 # Quality: User has made 1000+ commits | |
| QUALITY_FOLLOWERS=100 # Quality: User has 100+ followers | |
| # Check if user meets notification criteria using VIP-tiered system | |
| user_conditions_met=false | |
| notification_reason="" | |
| # Tier 1: Elite developers - single condition is enough | |
| if [[ $earn_star_count -ge $ELITE_STARS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Elite developer: Stars ($earn_star_count) >= $ELITE_STARS" | |
| elif [[ $commit_count -gt $ELITE_COMMITS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Elite developer: Commits ($commit_count) > $ELITE_COMMITS" | |
| elif [[ $follower_count -ge $ELITE_FOLLOWERS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Elite developer: Followers ($follower_count) >= $ELITE_FOLLOWERS" | |
| # Tier 2: Quality developers - must meet 2 out of 3 conditions | |
| elif [[ $earn_star_count -ge $QUALITY_STARS && $follower_count -ge $QUALITY_FOLLOWERS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Quality developer: Stars ($earn_star_count) >= $QUALITY_STARS AND Followers ($follower_count) >= $QUALITY_FOLLOWERS" | |
| elif [[ $earn_star_count -ge $QUALITY_STARS && $commit_count -gt $QUALITY_COMMITS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Quality developer: Stars ($earn_star_count) >= $QUALITY_STARS AND Commits ($commit_count) > $QUALITY_COMMITS" | |
| elif [[ $follower_count -ge $QUALITY_FOLLOWERS && $commit_count -gt $QUALITY_COMMITS ]]; then | |
| user_conditions_met=true | |
| notification_reason="Quality developer: Followers ($follower_count) >= $QUALITY_FOLLOWERS AND Commits ($commit_count) > $QUALITY_COMMITS" | |
| fi | |
| # Output result | |
| if [[ $user_conditions_met == true ]]; then | |
| echo "✅ User meets notification criteria" | |
| echo "📊 Reason: $notification_reason" | |
| echo "user_conditions_met=true" >> $GITHUB_ENV | |
| echo "notification_reason=$notification_reason" >> $GITHUB_ENV | |
| else | |
| echo "❌ User does not meet notification criteria" | |
| echo "📊 Stats: Stars=$earn_star_count, Commits=$commit_count, Followers=$follower_count" | |
| echo "user_conditions_met=false" >> $GITHUB_ENV | |
| echo "notification_reason=Does not meet criteria" >> $GITHUB_ENV | |
| fi | |
| - name: Convert body to HTML | |
| run: | | |
| html_body="" | |
| html_body+="<h3>🎉 New Stargazer</h3>" | |
| html_body+="User: <b><a href='${{ github.server_url }}/${{ github.actor }}'>${{ github.actor }}</a></b><br><br>" | |
| html_body+="<h4>👤 User Statistics:</h4>" | |
| html_body+="⭐ Earned Stars: <b>${{ env.earn_star_count }}</b><br>" | |
| html_body+="💻 Commits: <b>${{ env.commit_count }}</b><br>" | |
| html_body+="👥 Followers: <b>${{ env.follower_count }}</b><br><br>" | |
| html_body+="<h4>✅ Notification Reason:</h4>" | |
| html_body+="<span style='color: green; font-weight: bold;'>${{ env.notification_reason }}</span><br><br>" | |
| html_body+="<h4>📊 Repository Statistics:</h4>" | |
| html_body+="⭐ Stars: <b>${{ env.repo_stars }}</b><br>" | |
| html_body+="🍴 Forks: <b>${{ env.repo_forks }}</b><br>" | |
| html_body+="📥 Downloads: <b>${{ env.download_count }}</b><br><br>" | |
| html_body+="<h4>🔗 Links:</h4>" | |
| html_body+="Repo: <a href='${{ github.server_url }}/${{ github.repository }}'>${{ github.repository }}</a><br>" | |
| html_body+="Stargazers: <a href='${{ github.server_url }}/${{ github.repository }}/stargazers'>${{ github.repository }}/stargazers</a><br><br>" | |
| html_body+="<h4>📈 User GitHub Stats:</h4>" | |
| html_body+='<img align="center" src="https://github-readme-stats.vercel.app/api/top-langs/?username=${{ github.actor }}&layout=normal&theme=algolia"><br>' | |
| html_body+='<img align="center" src="https://github-readme-stats.vercel.app/api?username=${{ github.actor }}&theme=algolia&show_icons=true"><br>' | |
| echo "html_body=$html_body" >> $GITHUB_ENV | |
| - name: "Send mail" | |
| if: env.user_conditions_met == 'true' | |
| uses: dawidd6/action-send-mail@v3 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 465 | |
| username: ${{ secrets.GMAIL_BOT_USERNAME }} | |
| password: ${{ secrets.GMAIL_BOT_PASSWORD }} | |
| subject: ${{ github.actor }} ${{ env.event_name }} ${{ env.repo_name }} | |
| # List stargazers https://github.com/tisfeng/Easydict/stargazers | |
| html_body: ${{ env.html_body }} | |
| to: ${{ secrets.RECEIVER_EMAIL }} | |
| from: GitHub Actions |