-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·207 lines (156 loc) · 3.67 KB
/
build.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh
set -e
output_file="README.md"
graph_out="graph.png"
api_endpoint="https://api.github.com/graphql"
email="[email protected]"
#telegram=""
pop_repos_q="
query {
viewer {
repositories(
first: 5,
isFork: false,
orderBy: {field: STARGAZERS, direction: DESC},
privacy: PUBLIC
) {
nodes {
name
url
}
}
}
}
"
langs_q="
query {
viewer {
topRepositories(first: 100, orderBy: {field: STARGAZERS, direction: ASC}) {
nodes {
languages(first: 2) {
nodes {
name
}
}
}
}
}
}
"
yesterday=$(date --date="-1 day" -u +"%Y-%m-%d" 2> /dev/null || \
date -v -1d -u +"%Y-%m-%d")
total_contribs_q="
query {
viewer {
contributionsCollection(
from: \"${yesterday}T00:00:00\",
to: \"${yesterday}T23:59:59\"
) {
contributionCalendar {
totalContributions
}
}
}
}
"
starred_q="
query {
viewer {
starredRepositories(
first: 5,
orderBy: {field: STARRED_AT, direction: DESC}
) {
nodes {
name
url
}
}
}
}
"
load_dotenv() {
local dotenv=./.env
if [ -e "$dotenv" ]; then
. "$dotenv"
echo ".env loaded"
fi
}
perform_request() {
local q=$1 # query
local filter=$2
local processed=$(echo "$q" | perl -pe 's/\n/\\n/g' | perl -pe 's/"/\\"/g')
local req="{\"query\": \"$processed\"}"
local result=$(curl -H "Authorization: bearer $ACCESS_TOKEN" -X POST \
-d "$req" "$api_endpoint")
sleep 0.1
echo "$result" | jq -c -r "$filter"
}
# generate list of top repos
pop_repos() {
local data=$(perform_request \
"$pop_repos_q" '.data.viewer.repositories.nodes[]')
local result=""
for obj in $data; do
local name=$(printf '%s' "$obj" | jq -r '.name')
local url=$(printf '%s' "$obj" | jq -r '.url')
result+="- [$name]($url)"
result+=$'\n'
done
echo "$result"
}
languages() {
local data=$(perform_request "$langs_q" \
'.data.viewer.topRepositories.nodes[].languages.nodes[].name')
data=$(echo "$data" | tr -d '[:blank:]' | sort | uniq -c | sort -nr)
data=$(echo "$data" | tr -d '[:digit:][:blank:]')
data=$(echo "$data" | perl -pe 's/\n/, /g' | sed 's/,.$/\./')
echo "$data"
}
total() {
local data=$(perform_request "$total_contribs_q" \
'.data.viewer.contributionsCollection.contributionCalendar.totalContributions')
echo "$data"
}
starred() {
local data=$(perform_request "$starred_q" \
'.data.viewer.starredRepositories.nodes[]')
local result=""
for obj in $data; do
local name=$(echo "$obj" | jq -r '.name')
local url=$(echo "$obj" | jq -r '.url')
result+="- [$name]($url)"
result+=$'\n'
done
echo "$result"
}
plot_contributions() {
graph contributions.csv -f '' --fontsize 7 --width 3 --marker '' \
--style='-,-' --xscale 5 -o "$1"
}
load_dotenv
pops=$(pop_repos)
langs=$(languages)
total=$(total)
starred=$(starred)
plot_contributions "$graph_out"
echo "
# Hello
I'm an Open Source Software maintainer and evangalist.
## Contact
- [e-mail](mailto:$email)
- [Telegram]($telegram)
I spend my time working on OSS projects. If you liked any of
my contributions and my work helped you, sponsor me [ko-fi](https://ko-fi.com/askb23).
## Stats
Daily stats:
![contributions graph]($graph_out)
***Languages by contributions***
$langs
Number of contributions yesterday: **$total**.
***Most popular***
$pops
***Recently starred***
$starred
***GITHUB Metrics***
![Metrics](https://github.com/askb/askb/blob/main/github-metrics.svg)
" > "$output_file"