]> git.wh0rd.org - home.git/blame - .bin/er-close
test.py: use py3 by default
[home.git] / .bin / er-close
CommitLineData
ef325790
MF
1#!/bin/bash
2
3. ~/.profile.d/gentoo.sh
57e154df 4. ~/.profile.d/aliases.sh
ef325790
MF
5
6op=${0##*/}
5079bf1f
MF
7ops=( ${op//-/ } )
8op=${ops[0]}
369dd755 9[[ ${op} == "er" ]] && op+=" -q"
ef325790
MF
10tdir="${HOME}/.cache/bugz"
11mkdir -p "${tdir}"
12find "${tdir}" -mmin +30 -type f -delete
13
14usage() {
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
24bugs=()
25comments=()
26cl_msg=
27while [[ $# -ne 0 ]] ; do
28 bug=$1
29 reason=$2
f2f69886 30 shift 2 || usage "invalid args"
ef325790
MF
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
79d03612 47 if [[ ! -s $xml ]] ; then
ef325790
MF
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
33a25f00 56 new_name=$(echo "${name}" | scrub_html | sed "s: [(\"'][^()\"']*[)\"']::g")
57e154df
MF
57 if [[ ${new_name} != "${name}" ]] ; then
58 echo "Normalizing '${name}' to '${new_name}'"
59 name=${new_name}
60 fi
ef325790
MF
61
62 if [[ -n ${cl_msg} ]] ; then
63 cl_msg+=" "
64 fi
65 cl_msg+="${reason} #${bug} by ${name}."
66done
67
68run() {
69 local opt=$1; shift
70 printf "'%s' " "$@"
71 echo
72 case $opt in
73 -g) "$@" ;;
74 esac
75}
76
77doit() {
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]}
5079bf1f
MF
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 "\
ef325790
MF
88should be all set now in the tree; thanks for the report!
89
5079bf1f
MF
90${msg}"
91 ;;
92 comment)
93 run "$@" gbugz -q modify ${b} -c "${msg}"
94 ;;
95 esac
ef325790
MF
96 done
97 echo
98}
99
100cvs=$(cvs up)
101files=$(echo "$cvs" | awk '$1 ~ /^[MA]/ { print $NF }' | grep -v '^Manifest$')
8e8b3581 102unk_files=$(echo "$cvs" | awk '$1 !~ /^[MARU]/')
ef325790
MF
103if [[ -n ${unk_files} ]] ; then
104 echo "unknown files:"
105 echo "${unk_files}"
106 exit 1
107fi
108urls=$(cvs_gentoo_url ${files} | LC_ALL=C sort -V)
109
110cmds=$(doit -p)
111echo
112echo "${cmds}"
113printf "\nOk to go? [Y/n/e] "
114read g
115case ${g} in
116 e)
117 t=$(mktemp)
118 echo "${cmds}" > "${t}"
119 ${EDITOR:-nano} "${t}" || rm "${t}"
93dce0ac 120 set -e
ef325790
MF
121 . "${t}"
122 rm "${t}"
123 ;;
124 ""|y)
125 echo
126 doit -g
127 ;;
128 *)
129 exit 1
130 ;;
131esac