Skip to content

Commit 4ca3e2b

Browse files
committed
Make priority_poll.sh send multiple issues at once
1 parent 9ad3bb5 commit 4ca3e2b

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

bin/priority_poll.sh

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ From=${EMAIL}
1818

1919
usage()
2020
{
21-
echo "Usage: $0 [--help] [--to=<address>] [--from=<address>] ISSUE-NUMBER" ;
21+
echo "Usage: $0 [--help] [--to=<address>] [--from=<address>] ISSUE-NUMBER..."
22+
echo
23+
echo "ISSUE-NUMBER can be a single number or a range, e.g. 4321 or 4321-4325"
2224
exit $1
2325
}
2426

@@ -35,8 +37,6 @@ do
3537
shift
3638
done
3739

38-
[ $# -eq 1 ] || usage 1 >&2
39-
4040
if [ -z "$From" ]; then
4141
if From="$(git config user.email)"; then
4242
if name="$(git config user.name)"; then
@@ -48,27 +48,67 @@ fi
4848

4949
[ -n "$From" ] || die 'address not set, use --from or $EMAIL'
5050

51+
issues=''
52+
53+
# Get list of issues
54+
for i
55+
do
56+
if [[ $i =~ [[:digit:]]+-[[:digit:]]+ ]]
57+
then
58+
range=$(seq ${i/-/ })
59+
[ "$range" == '' ] && die "$0: Invalid argument: $i"
60+
issues="$issues $range"
61+
elif [[ $i =~ [[:digit:]]+ ]]
62+
then
63+
issues="$issues $i"
64+
fi
65+
done
66+
67+
[ "$issues" == '' ] && usage 1 >&2
68+
69+
# Make unique, sorted list of issue numbers
70+
issues=$(for i in $issues; do echo $i ; done | sort -u -n)
71+
72+
if [ -n "$DO_NOT_SEND" ] # define in the environment to test the script
73+
then
74+
echo 'Not sending email due to $DO_NOT_SEND in the environment' >&2
75+
fi
76+
77+
send_email()
78+
{
5179
issue=$1
80+
5281
if ! xml=$(printf "xml/issue%04d.xml" $issue) || [ ! -f "$xml" ]
5382
then
5483
die "No such issue: $issue"
5584
fi
5685

57-
if [ $(xpath -q -e '/issue/priority/text()' $xml) != 99 ]
58-
then
59-
die "Priority already set: $issue"
60-
elif [ "$(xpath -q -e '/issue/@status' $xml)" != ' status="New"' ]
86+
if [ "$(xpath -q -e '/issue/@status' $xml)" != ' status="New"' ]
6187
then
6288
die "Status is not \"New\": $issue"
6389
fi
6490

91+
if ! prio=$(xpath -q -e '/issue/priority/text()' $xml) || [ -z "$prio" ]
92+
then
93+
die "Issue has no priority element: $issue"
94+
elif [ "$prio" != 99 ]
95+
then
96+
die "Priority already set: $issue [priority=$prio]"
97+
fi
98+
6599
# Convert HTML to plain text (specifically, replace entities).
66100
# html2txt() { w3m -dump -T text/html -cols 1000 ; }
67101
# title=$(xpath -q -s '' -e '/issue/title//text()' $xml | html2txt)
68102

69103
# Use xpath to select text content of <title> element, with entities replaced.
70104
title=$(xpath -q -e 'normalize-space(/issue/title)' $xml)
71105

106+
if [ -n "$DO_NOT_SEND" ]
107+
then
108+
echo "Not Sent: Issue $issue: $title"
109+
return 1
110+
fi
111+
72112
draft=`mktemp /tmp/draft.prio.mail.XXXXXX` || exit
73113

74114
subject="Issue $issue: $title"
@@ -112,3 +152,13 @@ fi
112152
echo "Sent: Issue $issue: $title"
113153

114154
rm $draft
155+
}
156+
157+
delay=0
158+
159+
# Send the emails
160+
for i in $issues
161+
do
162+
sleep $delay
163+
send_email $i && delay=1
164+
done

0 commit comments

Comments
 (0)