qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] scripts: Add a script to check for bug URLs


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2] scripts: Add a script to check for bug URLs in the git log
Date: Tue, 13 Sep 2016 10:48:46 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 09/13/2016 08:20 AM, Thomas Huth wrote:
> Basic idea of this script is to check the git log for URLs
> to the QEMU bugtracker at launchpad.net and to figure out
> whether the related bug has been marked there as "Fix released"
> (i.e. closed) already. So this script can e.g. be used after
> each public release of QEMU to check whether there are any
> bug tickets that could be moved from "Fix committed" (or another
> state if the author of the patch forgot to update the bug ticket)
> to "Fix released".
> 
> Signed-off-by: Thomas Huth <address@hidden>
> ---
>  v2:
>  - Use xdg-open and friends to open the URLs in a browser
>  - Some cosmetics
> 
>  scripts/show-fixed-bugs.sh | 91 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 91 insertions(+)
>  create mode 100755 scripts/show-fixed-bugs.sh
> 
> diff --git a/scripts/show-fixed-bugs.sh b/scripts/show-fixed-bugs.sh
> new file mode 100755
> index 0000000..89847bd
> --- /dev/null
> +++ b/scripts/show-fixed-bugs.sh
> @@ -0,0 +1,91 @@
> +#!/bin/sh
> +
> +# This script checks the git log for URLs to the QEMU launchpad bugtracker
> +# and optionally checks whether the corresponding bugs are not closed yet.
> +
> +function show_help {
> +    echo "Usage:"
> +    echo "  -s <commit>  : Start searching at this commit"
> +    echo "  -e <commit>  : End searching at this commit"
> +    echo "  -c           : Check if bugs are still open"
> +    echo "  -b           : Open bugs in browser"
> +}
> +
> +while [ $# -ge 1 ]; do
> +   case "$1" in
> +    -s)  START="$2" ; shift ;;

POSIX recommends that short options with arguments be parseable both as
'-s foo' and '-sfoo'.  I don't care that you aren't POSIX compliant, but
using getopt(1) or getopts(1) may make it easier to comply.

Using ALL_CAPS variables in a shell script risks collisions with
environment variables that might have other uses.  It may be better to
use lower case variables to make it obvious that they are for internal use.

> +    -e)  END="$2" ; shift ;;
> +    -c)  CHECK_IF_OPEN=1 ;;
> +    -b)  SHOW_IN_BROWSER=1 ;;
> +    -h)  show_help ; exit 0 ;;
> +    *)   echo "Unkown option $1 ... use -h for help." ; exit 1 ;;

s/Unkown/Unknown/

> +   esac
> +   shift
> +done
> +
> +if [ "x$START" = "x" ]; then
> +    START=`git tag | grep 'v[0-9]*\.[0-9]*.0$' | tail -n 2 | head -n 1`

You can shorten 'git tag | grep' via:

git tag -l 'v[0-9]*.[0-9]*.0'

> +fi
> +if [ "x$END" = "x" ]; then
> +    END=`git tag | grep 'v[0-9]*\.[0-9]*.0$' | tail -n 1`

and again

> +fi
> +
> +if [ "x$BROWSER" != "x" ]; then
> +    BUGBROWSER = "$BROWSER"
> +elif which xdg-open > /dev/null; then

'which' is not portable; it may not exist.  It looks like you are trying
to redirect to /dev/null to avoid shell messages when it does not exist,
but to properly do that, you'd need:

(which xdg-open) >/dev/null 2>&1

(the subshell is necessary, since some shells don't shut up without it).

> +    BUGBROWSER=xdg-open
> +elif which gnome-open > /dev/null; then
> +    BUGBROWSER=gnome-open

and again

> +elif [ `uname` = "Darwin" ]; then
> +    BUGBROWSER=open

Improperly quoted.  You want "`uname`" to make sure that random spaces
don't cause the wrong number of arguments to '['.

> +elif which sensible-browser > /dev/null; then
> +    BUGBROWSER=sensible-browser

another nonportable which.

> +else
> +    echo "Please set the BROWSER variable to the browser of your choice."
> +    exit 1
> +fi
> +
> +if [ "x$START" = "x" -o "x$END" = "x" ]; then

[ ... -o ... ] is not portable.  POSIX itself recommends that you use:

[ "x$START" = "x" ] || [ "x$END" = "x" ]

> +    echo "Could not determine start or end revision ... Please note that 
> this"
> +    echo "script must be run from a checked out git repository of QEMU!"
> +    exit 1
> +fi
> +
> +echo "Searching git log for bugs in the range $START..$END"
> +
> +BUG_URLS=`git log $START..$END \
> +  | grep 'https://bugs.launchpad.net/\(bugs\|qemu/+bug\)/' \
> +  | sed 
> 's,\(.*\)\(https://bugs.launchpad.net/\(bugs\|qemu/+bug\)/\)\([0-9]*\).*,\2\4,'
>  \

'grep | sed' can usually be shortened to just 'sed'.  Here, it could be:

str='https://bugs.launchpad.net,\(bugs\|qemu/+bug\)'
sed -n '\,'"$str"', s,\(.*\)\('"$str"'/\)\([0-9]*\).*,\2\4,p'

> +  | sort -u`
> +
> +echo Found bug URLs:
> +for i in $BUG_URLS ; do echo " $i" ; done
> +
> +if [ "x$CHECK_IF_OPEN" = "x1" ]; then
> +    echo
> +    echo "Checking which ones are still opened..."
> +    for i in $BUG_URLS ; do
> +        if ! curl -s -L "$i" | grep "value status" | grep -q "Fix Released" 
> ; then
> +            echo " $i"
> +            FINAL_BUG_URLS="$FINAL_BUG_URLS $i"
> +        fi
> +    done
> +else
> +    FINAL_BUG_URLS=$BUG_URLS
> +fi
> +
> +if [ "x$FINAL_BUG_URLS" = "x" ]; then
> +    echo "No open bugs found."
> +elif [ "x$SHOW_IN_BROWSER" = "x1" ]; then
> +    FIRST=1
> +    for i in $FINAL_BUG_URLS; do
> +        "$BUGBROWSER" "$i"
> +        if [ $FIRST = 1 ]; then
> +            # if it is the first entry, give the browser some time to start
> +            # (to avoid messages like "Firefox is already running, but is
> +            # not responding...")
> +            sleep 4
> +            FIRST=0
> +        fi
> +    done
> +fi
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]