]> git.wh0rd.org - home.git/blob - .bin/er-close
cros-board: update
[home.git] / .bin / er-close
1 #!/bin/bash
2
3 . ~/.profile.d/gentoo.sh
4 . ~/.profile.d/aliases.sh
5
6 op=${0##*/}
7 ops=( ${op//-/ } )
8 op=${ops[0]}
9 [[ ${op} == "er" ]] && op+=" -q"
10 tdir="${HOME}/.cache/bugz"
11 mkdir -p "${tdir}"
12 find "${tdir}" -mmin +30 -type f -delete
13
14 usage() {
15 cat <<-EOF
16 Usage: ${0##*/} <bugid> <reason> [<bugid> <reason> ...]
17 EOF
18 if [[ $# -gt 0 ]] ; then
19 printf '\nerror: %s\n' "$*"
20 fi
21 exit
22 }
23
24 bugs=()
25 comments=()
26 cl_msg=
27 while [[ $# -ne 0 ]] ; do
28 bug=$1
29 reason=$2
30 shift 2 || usage "invalid args"
31
32 if [[ -z ${bug} || -n ${bug//[0-9#]} ]] ; then
33 usage "invalid bug"
34 fi
35
36 case ${bug} in
37 *#*) c=${bug##*#} ;;
38 *) c=0 ;;
39 esac
40 : $(( ++c ))
41 b=${bug%%#*}
42 bugs=( "${bugs[@]}" ${b} )
43 comments=( "${comments[@]}" "${reason}" )
44
45 xml="${tdir}/${b}.xml"
46 # server doesn't support timestamps, so cannot use -N
47 if [[ ! -s $xml ]] ; then
48 wget -q -O $xml https://bugs.gentoo.org/${b}?ctype=xml
49 fi
50 name=$(xml sel -E utf8 -t -m bugzilla/bug/long_desc -c who -n $xml | \
51 head -${c} | tail -1 | grep -o 'name=".*">' | cut -d\" -f2)
52 if [[ -z ${name} ]] ; then
53 name=$(xml sel -E utf8 -t -m bugzilla/bug/long_desc -v who -n $xml | \
54 head -${c} | tail -1 | cut -d@ -f1)
55 fi
56 new_name=$(echo "${name}" | scrub_html | sed "s: [(\"'][^()\"']*[)\"']::g")
57 if [[ ${new_name} != "${name}" ]] ; then
58 echo "Normalizing '${name}' to '${new_name}'"
59 name=${new_name}
60 fi
61
62 if [[ -n ${cl_msg} ]] ; then
63 cl_msg+=" "
64 fi
65 cl_msg+="${reason} #${bug} by ${name}."
66 done
67
68 run() {
69 local opt=$1; shift
70 printf "'%s' " "$@"
71 echo
72 case $opt in
73 -g) "$@" ;;
74 esac
75 }
76
77 doit() {
78 run "$@" $op "${cl_msg}" || exit 1
79 echo
80 for (( n=0; n < ${#bugs[@]}; ++n )) ; do
81 b=${bugs[$n]}
82 c=${comments[$n]}
83 local msg="Commit message: $c$(printf '\n%s' ${urls})"
84
85 case ${ops[1]} in
86 close)
87 run "$@" gbugz -q modify ${b} --fixed -c "\
88 should be all set now in the tree; thanks for the report!
89
90 ${msg}"
91 ;;
92 comment)
93 run "$@" gbugz -q modify ${b} -c "${msg}"
94 ;;
95 esac
96 done
97 echo
98 }
99
100 cvs=$(cvs up)
101 files=$(echo "$cvs" | awk '$1 ~ /^[MA]/ { print $NF }' | grep -v '^Manifest$')
102 unk_files=$(echo "$cvs" | awk '$1 !~ /^[MARU]/')
103 if [[ -n ${unk_files} ]] ; then
104 echo "unknown files:"
105 echo "${unk_files}"
106 exit 1
107 fi
108 urls=$(cvs_gentoo_url ${files} | LC_ALL=C sort -V)
109
110 cmds=$(doit -p)
111 echo
112 echo "${cmds}"
113 printf "\nOk to go? [Y/n/e] "
114 read g
115 case ${g} in
116 e)
117 t=$(mktemp)
118 echo "${cmds}" > "${t}"
119 ${EDITOR:-nano} "${t}" || rm "${t}"
120 set -e
121 . "${t}"
122 rm "${t}"
123 ;;
124 ""|y)
125 echo
126 doit -g
127 ;;
128 *)
129 exit 1
130 ;;
131 esac