]> git.wh0rd.org - home.git/blame - .bin/er-close
support OWNERS in subdirs
[home.git] / .bin / er-close
CommitLineData
ef325790
MF
1#!/bin/bash
2
3. ~/.profile.d/gentoo.sh
4
5op=${0##*/}
6op=${op%-close}
7tdir="${HOME}/.cache/bugz"
8mkdir -p "${tdir}"
9find "${tdir}" -mmin +30 -type f -delete
10
11usage() {
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
21bugs=()
22comments=()
23cl_msg=
24while [[ $# -ne 0 ]] ; do
25 bug=$1
26 reason=$2
f2f69886 27 shift 2 || usage "invalid args"
ef325790
MF
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
79d03612 44 if [[ ! -s $xml ]] ; then
ef325790
MF
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}."
58done
59
60run() {
61 local opt=$1; shift
62 printf "'%s' " "$@"
63 echo
64 case $opt in
65 -g) "$@" ;;
66 esac
67}
68
69doit() {
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 "\
76should be all set now in the tree; thanks for the report!
77
78Commit message: $c$(printf '\n%s' ${urls})"
79 done
80 echo
81}
82
83cvs=$(cvs up)
84files=$(echo "$cvs" | awk '$1 ~ /^[MA]/ { print $NF }' | grep -v '^Manifest$')
8e8b3581 85unk_files=$(echo "$cvs" | awk '$1 !~ /^[MARU]/')
ef325790
MF
86if [[ -n ${unk_files} ]] ; then
87 echo "unknown files:"
88 echo "${unk_files}"
89 exit 1
90fi
91urls=$(cvs_gentoo_url ${files} | LC_ALL=C sort -V)
92
93cmds=$(doit -p)
94echo
95echo "${cmds}"
96printf "\nOk to go? [Y/n/e] "
97read g
98case ${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 ;;
113esac