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