-
Notifications
You must be signed in to change notification settings - Fork 4
/
update_contributor.sh
executable file
·82 lines (70 loc) · 2.43 KB
/
update_contributor.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
#!/usr/bin/env bash
# set -e -x
# Target file
TARGET=README.md
# Markers
START=start_contributors
END=end_contributors
LEAD="^<!-- ${START} .*-->$"
TAIL="^<!-- ${END} .*-->$"
# Leave blank for no backup.
# *.bak, *.back, *.backup, *.copy, *.tmp, *.previous are git ignored
BACKUP_SUFFIX=.previous
# Target URL
# TODO: get these from the current repo
USER=epfl-si
REPO=wp-ops
# When mode:something is used
get_list_mode () {
MODE=$(sed -n "s/^<\!-- ${START}\s.*mode:\s*\(\S*\).*$/\1/p" $TARGET)
# default MODE is "bullet"
[ -z "$MODE" ] && MODE="bullet"
}
# Fetch the contributors list
fetch_contributors_as_a_bullet_list () {
CONTRIBUTORS_LIST=$(curl -s https://api.github.com/repos/${USER}/${REPO}/contributors | jq -r '.[] | " * [@\(.login)](\(.html_url))"'| grep -v dependabot); \
echo "${CONTRIBUTORS_LIST}" > tmp_data
}
# Trombinoscope
fetch_contributors_as_images_list () {
CONTRIBUTORS_LIST=$(curl -s https://api.github.com/repos/epfl-si/wp-ops/contributors | jq -r '.[] | "<a href=\"\(.html_url)\"><img src=\"\(.avatar_url)\" title=\"\(.login)´s profile\" width=\"50px\" /></a> "'| grep -v dependabot); \
echo "${CONTRIBUTORS_LIST}" > tmp_data
}
# Bubble
fetch_contributors_as_bubble_images_list () {
CONTRIBUTORS_LIST=$(curl -s https://api.github.com/repos/epfl-si/wp-ops/contributors | jq -r '.[] | "![@\(.login) avatar](https://images.weserv.nl/?url=\(.avatar_url)&h=84&w=84&fit=cover&mask=circle&maxage=7d)"' | grep -v dependabot); \
echo "${CONTRIBUTORS_LIST}" > tmp_data
}
# HTML figure
fetch_contributors_as_HTML_figures () {
echo "HELLO AGAIN"
CONTRIBUTORS_LIST=$(curl -s https://api.github.com/repos/epfl-si/wp-ops/contributors | \
jq -r '.[] | "<figure><img src=\"\(.avatar_url)\" alt=\"\(.login)´s profile\" width=\"250px\" /><figcaption><a href=\"\(.html_url)\">@\(.login)</a></figcaption></figure>"' | grep -v dependabot); \
echo "${CONTRIBUTORS_LIST}" > tmp_data
}
# Insert the contributors list between the markers
update_contributors_in_file () {
sed -i$BACKUP_SUFFIX -e "/$LEAD/,/$TAIL/{ /$LEAD/{p; r tmp_data
}; /$TAIL/p; d }" $TARGET
}
get_list_mode
case $MODE in
[bB]ullet)
fetch_contributors_as_a_bullet_list
;;
[tT]rombinoscope)
fetch_contributors_as_images_list
;;
[bB]ubble)
fetch_contributors_as_bubble_images_list
;;
[fF]igure)
fetch_contributors_as_HTML_figures
;;
*)
fetch_contributors_as_a_bullet_list
;;
esac
update_contributors_in_file
# Output the resulting file
cat $TARGET