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