-
Notifications
You must be signed in to change notification settings - Fork 383
93 lines (80 loc) · 4.67 KB
/
star_fork_notification.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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.READ_REPO_STAR_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.READ_REPO_STAR_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: |
earn_star_count=$(curl -s -H "Authorization: token ${{ secrets.READ_REPO_STAR_TOKEN }}" "https://api.github.com/users/${{ github.actor }}/repos" | jq '[.[] | .stargazers_count] | add // 0')
commit_count=$(curl -s -H "Authorization: token ${{ secrets.READ_REPO_STAR_TOKEN }}" "https://api.github.com/search/commits?q=author:${{ github.actor }}" | jq -r '.total_count // 0')
follower_count=$(curl -s -H "Authorization: token ${{ secrets.READ_REPO_STAR_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
if [[ $commit_count -ge 0 ]]; then
echo "user_conditions_met=true" >> $GITHUB_ENV
else
echo "user_conditions_met=false" >> $GITHUB_ENV
fi
- name: Convert body to HTML
run: |
html_body=""
html_body+="Stargazer: <b><a href='${{ github.server_url }}/${{ github.actor }}'>${{ github.actor }}</a></b> (Earn stars: ${{ env.earn_star_count }}, Commits: ${{ env.commit_count }}, Followers: ${{ env.follower_count }})<br><br>"
html_body+="Stars: <b>${{ env.repo_stars }}</b><br><br>"
html_body+="Forks: <b>${{ env.repo_forks }}</b><br><br>"
html_body+="Downloads: <b>${{ env.download_count }}</b><br><br>"
html_body+="Repo: <a href='${{ github.server_url }}/${{ github.repository }}'>${{ github.repository }}</a><br><br>"
html_body+="Stargazers list: <a href='${{ github.server_url }}/${{ github.repository }}/stargazers'>${{ github.repository }}/stargazers</a><br><br>"
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
echo "html body: ${{ env.html_body }}"
- 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