Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # This script checks the git log for URLs to the QEMU launchpad bugtracker |
| 4 | # and optionally checks whether the corresponding bugs are not closed yet. |
| 5 | |
| 6 | show_help () { |
| 7 | echo "Usage:" |
| 8 | echo " -s <commit> : Start searching at this commit" |
| 9 | echo " -e <commit> : End searching at this commit" |
| 10 | echo " -c : Check if bugs are still open" |
| 11 | echo " -b : Open bugs in browser" |
| 12 | } |
| 13 | |
| 14 | while getopts "s:e:cbh" opt; do |
| 15 | case "$opt" in |
| 16 | s) start="$OPTARG" ;; |
| 17 | e) end="$OPTARG" ;; |
| 18 | c) check_if_open=1 ;; |
| 19 | b) show_in_browser=1 ;; |
| 20 | h) show_help ; exit 0 ;; |
| 21 | *) echo "Use -h for help." ; exit 1 ;; |
| 22 | esac |
| 23 | done |
| 24 | |
| 25 | if [ "x$start" = "x" ]; then |
Mao Zhongyi | aa2192b | 2018-10-15 17:17:36 +0800 | [diff] [blame] | 26 | start=$(git tag -l 'v[0-9]*\.[0-9]*\.0' | tail -n 2 | head -n 1) |
Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 27 | fi |
| 28 | if [ "x$end" = "x" ]; then |
Mao Zhongyi | aa2192b | 2018-10-15 17:17:36 +0800 | [diff] [blame] | 29 | end=$(git tag -l 'v[0-9]*\.[0-9]*\.0' | tail -n 1) |
Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 30 | fi |
| 31 | |
| 32 | if [ "x$start" = "x" ] || [ "x$end" = "x" ]; then |
| 33 | echo "Could not determine start or end revision ... Please note that this" |
| 34 | echo "script must be run from a checked out git repository of QEMU." |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | echo "Searching git log for bugs in the range $start..$end" |
| 39 | |
| 40 | urlstr='https://bugs.launchpad.net/\(bugs\|qemu/+bug\)/' |
Mao Zhongyi | aa2192b | 2018-10-15 17:17:36 +0800 | [diff] [blame] | 41 | bug_urls=$(git log $start..$end \ |
Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 42 | | sed -n '\,'"$urlstr"', s,\(.*\)\('"$urlstr"'\)\([0-9]*\).*,\2\4,p' \ |
Mao Zhongyi | aa2192b | 2018-10-15 17:17:36 +0800 | [diff] [blame] | 43 | | sort -u) |
Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 44 | |
| 45 | echo Found bug URLs: |
| 46 | for i in $bug_urls ; do echo " $i" ; done |
| 47 | |
| 48 | if [ "x$check_if_open" = "x1" ]; then |
| 49 | echo |
| 50 | echo "Checking which ones are still open..." |
| 51 | for i in $bug_urls ; do |
| 52 | if ! curl -s -L "$i" | grep "value status" | grep -q "Fix Released" ; then |
| 53 | echo " $i" |
| 54 | final_bug_urls="$final_bug_urls $i" |
| 55 | fi |
| 56 | done |
| 57 | else |
| 58 | final_bug_urls=$bug_urls |
| 59 | fi |
| 60 | |
| 61 | if [ "x$final_bug_urls" = "x" ]; then |
| 62 | echo "No open bugs found." |
| 63 | elif [ "x$show_in_browser" = "x1" ]; then |
| 64 | # Try to determine which browser we should use |
| 65 | if [ "x$BROWSER" != "x" ]; then |
| 66 | bugbrowser="$BROWSER" |
| 67 | elif command -v xdg-open >/dev/null 2>&1; then |
| 68 | bugbrowser=xdg-open |
| 69 | elif command -v gnome-open >/dev/null 2>&1; then |
| 70 | bugbrowser=gnome-open |
Mao Zhongyi | aa2192b | 2018-10-15 17:17:36 +0800 | [diff] [blame] | 71 | elif [ "$(uname)" = "Darwin" ]; then |
Thomas Huth | 6867783 | 2016-09-21 21:42:22 +0200 | [diff] [blame] | 72 | bugbrowser=open |
| 73 | elif command -v sensible-browser >/dev/null 2>&1; then |
| 74 | bugbrowser=sensible-browser |
| 75 | else |
| 76 | echo "Please set the BROWSER variable to the browser of your choice." |
| 77 | exit 1 |
| 78 | fi |
| 79 | # Now show the bugs in the browser |
| 80 | first=1 |
| 81 | for i in $final_bug_urls; do |
| 82 | "$bugbrowser" "$i" |
| 83 | if [ $first = 1 ]; then |
| 84 | # if it is the first entry, give the browser some time to start |
| 85 | # (to avoid messages like "Firefox is already running, but is |
| 86 | # not responding...") |
| 87 | sleep 4 |
| 88 | first=0 |
| 89 | fi |
| 90 | done |
| 91 | fi |