]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/make-countdown-announcement.sh
Issue 4051: Improve make-countdown-announcement.sh.
[lilypond.git] / scripts / auxiliar / make-countdown-announcement.sh
1 #!/bin/bash
2
3 # convert a Google code CSV file into a countdown announcement
4 #
5 # USAGE:
6 #   make-countdown-announcement.sh NEXT_DEADLINE_DATE [PATCH-MEISTER]
7 #     OR
8 #   make-countdown-announcement.sh NEXT_DEADLINE_DATE [PATCH-MEISTER] > OUTPUT-FILE
9 #
10 # EXAMPLES:
11 #   make-countdown-announcement.sh "Jan 1, 2001" "John Doe"
12 #   make-countdown-announcement.sh "Jan 1, 2001" John
13 #   make-countdown-announcement.sh "Jan 1, 2001" > countdown.txt
14
15
16 CSV_FILE=lilypond-issues.csv # comma-separated values
17 TSV_FILE=lilypond-issues.tsv # tab-separated values
18 URL_BASE="https://code.google.com/p/lilypond/issues"
19 QUERY_STR="q=Patch%3Apush%2Ccountdown%2Creview%2Cnew%2Cwaiting&colspec=Patch%20Owner%20ID%20Summary&sort=patch"
20 DEADLINE=$1
21 PATCH_MEISTER=${2:-"The Patch Meister"}
22 MAILMAP='
23 "adam.spiers","Adam Spiers"
24 "aleksandr.andreev","Aleksandr Andreev"
25 "benko.pal","Benkő Pál"
26 "bordage.bertrand","Bertrand Bordage"
27 "brownian.box","Dmytro O. Redchuk"
28 "Carl.D.Sorensen","Carl Sorensen"
29 "carlopeterson","Carl Peterson"
30 "colinghall","Colin Hall"
31 "ColinPKCampbell","Colin Campbell"
32 "d8valily","Mark Mathias"
33 "dak@gnu.org","David Kastrup"
34 "david.nalesnik","David Nalesnik"
35 "dschudy","Devon Schudy"
36 "Eluzew","Eluze W"
37 "erlenda","Erlend Aasland"
38 "fedelogy","Federico Bruni"
39 "frederic.bron.1995@polytechnique.org","Frédéric Bron"
40 "graham@percival-music.ca","Graham Percival"
41 "hanwenn","Han-Wen Nienhuys"
42 "hjunes","Heikki Junes"
43 "ht.lilypond.development","Heikki Tauriainen"
44 "ianhulin44","Ian Hulin"
45 "idragosani","Brett McCoy"
46 "jameselihubailey","James E. Bailey"
47 "janek.lilypond","Janek Warchoł"
48 "jan.nieuwenhuizen","Jan Nieuwenhuizen"
49 "joeneeman","Joe Neeman"
50 "john.mandereau","John Mandereau"
51 "joseph.wakeling","Joseph Wakeling"
52 "julien.rioux","Julien Rioux"
53 "kieren@alumni.rice.edu","Kieren MacMillan"
54 "k-ohara5a5a@oco.net","Keith OHara"
55 "lemzwerg","Werner Lemberg"
56 "lilyliska","Urs Liska"
57 "lilypond.patchy.graham","Graham Percival"
58 "mandolaerik","Erik Sandberg"
59 "marc@hohlart.de","Marc Hohl"
60 "marek@gregoriana.sk","Marek Klein"
61 "markpolesky","Mark Polesky"
62 "milimetr88","Łukasz Czerwiński"
63 "mtsolo","Mike Solomon"
64 "neziap","Janek Warchoł"
65 "nicolas.sceaux","Nicolas Sceaux"
66 "n.puttock","Neil Puttock"
67 "paconet.org","Francisco Vila"
68 "PhilEHolmes","Phil Holmes"
69 "pkx166h","James Lowe"
70 "plroskin","Pavel Roskin"
71 "pnorcks","Patrick McCarty"
72 "RalphBugList","Ralph Palmer"
73 "reinhold.kainhofer","Reinhold Kainhofer"
74 "rzedeler","Rune Zedeler"
75 "schilke.60","Derek Klinge"
76 "shingarov","Boris Shingarov"
77 "tdanielsmusic","Trevor Daniels"
78 "thomasmorley65","Thomas Morley"
79 "v.villenave","Valentin Villenave"
80 '
81
82
83 usage() {
84   cat << EOF >&2
85 USAGE:
86   `basename $0` NEXT_DEADLINE_DATE [PATCH-MEISTER]
87     OR
88   `basename $0` NEXT_DEADLINE_DATE [PATCH-MEISTER] > OUTPUT-FILE
89
90 EXAMPLES:
91   `basename $0` "Jan 1, 2001" "John Doe"
92   `basename $0` "Jan 1, 2001" John
93   `basename $0` "Jan 1, 2001" > countdown.txt
94 EOF
95   exit 1
96 }
97
98
99 # display USAGE
100 case $# in
101   1|2) case $1 in
102          -h|--help) usage ;;
103          *) ;;
104        esac ;;
105   *) usage ;;
106 esac
107
108
109 # clean up in case of a previous interrupt
110 remove-if-exists() {
111   if [ -e $1 ]; then rm $1; fi
112 }
113 remove-if-exists push.tmp
114 remove-if-exists countdown.tmp
115 remove-if-exists review.tmp
116 remove-if-exists new.tmp
117 remove-if-exists waiting.tmp
118 remove-if-exists $TSV_FILE
119
120
121 # show initial instructions
122 read -p "First, in your web browser, make sure you're logged in to:
123
124   $URL_BASE/list
125
126 Then save the following link as a file called \"$CSV_FILE\"
127 (save it to this directory -- $PWD/):
128
129   $URL_BASE/csv?$QUERY_STR
130
131 Then press enter"
132
133
134 if [ ! -e $CSV_FILE ]; then
135   echo -e "\nError: can't find \`$CSV_FILE': No such file or directory" >&2
136   exit 1
137 fi
138
139
140 # If the user wasn't logged in when downloading $CSV_FILE, the emails will
141 # appear truncated, e.g. "abc...@gmail.com", and won't be properly replaced by
142 # the author names later on.  This code block complains if the string "...@" is
143 # found anywhere in the email field.
144 if [ "`cut -d, -f2 $CSV_FILE | grep -o '\.\.\.@'`" ]; then
145     read -p "
146 It looks like you were not logged in to Google code when you downloaded
147 $CSV_FILE.  Continue anyway (y/n)? "
148   while :
149   do
150     case "$REPLY" in
151       y) break ;;
152       n) exit 1 ;;
153       *) read -p "Enter \`y' to continue; \`n' to quit and try again: "
154     esac
155   done
156 fi
157
158
159 # change the quoted, comma-separated file
160 # into an unquoted, tab-separated file
161 # and keep only the first 4 fields: Patch,Owner,ID,Summary
162 sed '{
163 1d
164 /^$/d
165 s/\t/ /g
166 s/^"//
167 s/","/\t/g
168 s/",*$//
169 s/""/"/g
170 }' $CSV_FILE | cut -sf1-4 > $TSV_FILE
171
172
173 ISSUES_WITH_MISSING_FIELDS=`sed -n '/\t\t\|\t$/p' $TSV_FILE |
174                             awk -F"\t" '{ print $3 }'`
175
176 if [ "$ISSUES_WITH_MISSING_FIELDS" ]; then
177   COUNT=`wc --lines <(echo "$ISSUES_WITH_MISSING_FIELDS") | sed 's/ .*//'`
178   LINKS_WITH_MISSING_FIELDS=`echo "$ISSUES_WITH_MISSING_FIELDS" |
179                              sed "s!^!  $URL_BASE/detail?id=!"`
180   if [ $COUNT -eq 1 ]; then
181     echo -e "\nError: The following issue is missing an OWNER or SUMMARY:" >&2
182   else
183     echo -e "\nError: Each of the following issues is missing an OWNER or SUMMARY:" >&2
184   fi
185   echo "$LINKS_WITH_MISSING_FIELDS" >&2
186   echo "Please add the missing information in the tracker and start over." >&2
187   remove-if-exists $TSV_FILE
188   exit 1
189 fi
190
191
192 EMAILS_USED=`awk -F"\t" '{ print $2 }' $TSV_FILE | sort --unique`
193 KNOWN_EMAILS=`
194 IFS=$'\n'
195 for i in $MAILMAP; do
196   echo "$i" | sed 's/^"\(.*\)",".*/\1/'
197 done | sort --unique`
198 UNKNOWN_EMAILS=`comm -23 <(echo "$EMAILS_USED") <(echo "$KNOWN_EMAILS")`
199
200
201 # Unknown emails/usernames usually mean new contributors.
202 # If any are found, the user is prompted to add the new
203 # authors' names to the MAILMAP list above.
204 if [ "$UNKNOWN_EMAILS" ]; then
205   COUNT=`wc --lines <(echo "$UNKNOWN_EMAILS") | sed 's/ .*//'`
206   if [ $COUNT -eq 1 ]; then
207     echo -e "\nError: The following email/username needs to be associated with a name:" >&2
208     echo "$UNKNOWN_EMAILS" | sed 's/^/  /' >&2
209     echo -e "Please add it to the MAILMAP list in\n  $0" >&2
210   else
211     echo -e "\nError: The following emails/usernames need to be associated with names:" >&2
212     echo "$UNKNOWN_EMAILS" | sed 's/^/  /' >&2
213     echo -e "Please add them to the MAILMAP list in\n  $0" >&2
214   fi
215   echo "using the following form:" >&2
216   echo "$UNKNOWN_EMAILS" | sed 's/.*/  "&","author name"/' >&2
217   echo "and commit your changes to the main git repository." >&2
218   remove-if-exists $TSV_FILE
219   exit 1
220 fi
221
222
223 EMAIL_REPLACEMENTS=`
224 IFS=$'\n'
225 for i in $MAILMAP; do
226   echo "$i" | sed 's/^"\(.*\)","\(.*\)"$/s\/\1\/\2\/g/'
227 done`
228
229
230 # replace emails/usernames with author names
231 # and separate the issues by patch type
232 sed -n "{
233 $EMAIL_REPLACEMENTS
234 /^push/w push.tmp
235 /^countdown/w countdown.tmp
236 /^review/w review.tmp
237 /^new/w new.tmp
238 /^waiting/w waiting.tmp
239 }" $TSV_FILE
240
241
242 # clean up; $TSV_FILE is no longer needed
243 remove-if-exists $TSV_FILE
244
245
246 format-entry() {
247   TYPE=$1
248   FILE="$1.tmp"
249   if [ -s $FILE ]; then
250     echo -e "$TYPE:\n" | tr 'a-z' 'A-Z'
251     awk -v UB=$URL_BASE -F"\t" \
252       '{ printf("%s: %s\n%s/detail?id=%d\n\n"), $2, $4, UB, $3 }' $FILE
253     echo -e "____________________\n\n"
254   fi
255   remove-if-exists $FILE
256 }
257
258 echo >&2
259
260
261 # display the countdown announcement
262 echo "Hello,
263
264 Here is the current patch countdown list.
265 The next countdown will be on $DEADLINE.
266
267 You can always view the most current countdown list here:
268 $URL_BASE/list?$QUERY_STR
269
270 ____________________
271
272 "
273
274 format-entry push
275 format-entry countdown
276 format-entry review
277 format-entry new
278 format-entry waiting
279
280 echo -e "Thank you,\n$PATCH_MEISTER"