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