43 # When I consider an issue is fulfilled, I negate its priority. |
43 # When I consider an issue is fulfilled, I negate its priority. |
44 # 6. Delete an issue |
44 # 6. Delete an issue |
45 # bug delete <ID> |
45 # bug delete <ID> |
46 # Do that whenever you will not need the issue anymore. |
46 # Do that whenever you will not need the issue anymore. |
47 # |
47 # |
|
48 # |
|
49 # Contributions: |
|
50 # -------------- |
|
51 # |
|
52 # pancake <pancake@youterm.com> |
|
53 # - drop bashisms |
|
54 # - implement -h flag |
|
55 # - error messages to stderr |
|
56 # - more checks and help on BUG_PROJECT environ |
|
57 # |
|
58 # TODO: |
|
59 # Support for an array of bug report files ?? readonly |
|
60 # Check BUG_PROJECT file format before processing |
|
61 # |
48 |
62 |
49 PNAME=`basename "$0"` |
63 PNAME=`basename "$0"` |
50 CMD="$1" |
64 CMD="$1" |
51 |
65 |
52 if [ "x$EDITOR" == "x" ]; then |
66 if [ -z "$EDITOR" ]; then |
53 EDITOR=vim |
67 EDITOR=vim |
54 fi |
68 fi |
55 |
69 |
56 function usage |
70 function usage |
57 { |
71 { |
58 echo "usage: $PNAME <add | list | view | edit | delete | create | project>" |
72 echo "Usage: $PNAME [ add | list | view | edit | delete | create | project ]" |
59 } |
73 } |
60 |
74 |
61 function create |
75 function create |
62 { |
76 { |
63 if [ ! -f "$BUG_PROJECT" ]; then |
77 if [ ! -f "$BUG_PROJECT" ]; then |
122 ID=`grep "^Id:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
136 ID=`grep "^Id:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
123 SUBJECT=`grep "^Subject:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
137 SUBJECT=`grep "^Subject:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
124 STATE=`grep "^State:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
138 STATE=`grep "^State:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
125 PRIORITY=`grep "^Priority:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
139 PRIORITY=`grep "^Priority:" $1 | head -n 1 | cut -d : -f 2- | string2db` |
126 |
140 |
127 if ( [ "x$SUBJECT" == "" ] || [ "x$PRIORITY" == "" ] ); then |
141 if [ -z "$PRIORITY" ]; then |
128 echo "Error in ticket: subject or priority." 2>&1 |
142 echo "Error in ticket: subject or priority." > /dev/stderr |
|
143 return 1 |
|
144 fi |
|
145 |
|
146 if [ -z "$SUBJECT" ]; then |
|
147 echo "Error in ticket: subject or priority." > /dev/stderr |
129 return 1 |
148 return 1 |
130 fi |
149 fi |
131 |
150 |
132 LINES=`cat $1 | wc -l` |
151 LINES=`cat $1 | wc -l` |
133 |
152 |
134 # Substract Id, Subject, State and Priority |
153 # Substract Id, Subject, State and Priority |
135 TOTAIL=$(( LINES - 5 )) |
154 #TOTAIL=$(( LINES - 5 )) |
|
155 let TOTAIL=LINES-5 |
136 DESCRIPTION=`tail -n $TOTAIL $1 | text2db | trimlastdbNL` |
156 DESCRIPTION=`tail -n $TOTAIL $1 | text2db | trimlastdbNL` |
137 |
157 |
138 echo "$ID $PRIORITY $STATE $SUBJECT $DESCRIPTION" >> $BUG_PROJECT |
158 echo "$ID $PRIORITY $STATE $SUBJECT $DESCRIPTION" >> $BUG_PROJECT |
139 |
159 |
140 # Update the next ID number |
160 # Update the next ID number |
158 { |
178 { |
159 ID=$1 |
179 ID=$1 |
160 |
180 |
161 LINE=`catlist | grep "^$ID "` |
181 LINE=`catlist | grep "^$ID "` |
162 |
182 |
163 if [ "x$LINE" != "x" ]; then |
183 if [ -n "$LINE" ]; then |
164 PRIORITY=`echo "$LINE" | cut -f 2` |
184 PRIORITY=`echo "$LINE" | cut -f 2` |
165 STATE=`echo "$LINE" | cut -f 3` |
185 STATE=`echo "$LINE" | cut -f 3` |
166 SUBJECT=`echo "$LINE" | cut -f 4` |
186 SUBJECT=`echo "$LINE" | cut -f 4` |
167 DESCRIPTION=`echo "$LINE" | cut -f 5` |
187 DESCRIPTION=`echo "$LINE" | cut -f 5` |
168 |
188 |
278 rm "$FILE" |
298 rm "$FILE" |
279 fi |
299 fi |
280 |
300 |
281 } |
301 } |
282 |
302 |
283 if [ "x$BUG_PROJECT" == "x" ]; then |
303 if [ -z "$BUG_PROJECT" ]; then |
284 echo "\$BUG_PROJECT is not set" |
304 echo "\$BUG_PROJECT is not set." |
285 exit 1 |
305 exit 1 |
286 fi |
306 fi |
287 |
307 |
288 if [ "x$CMD" == "x" ]; then |
308 if [ ! "`echo $BUG_PROJECT | cut -c 1`" = "/" ]; then |
|
309 echo "Do not use relative paths in BUG_PROJECT environ." |
|
310 exit 1 |
|
311 fi |
|
312 |
|
313 if [ ! "$CMD" = "create" ]; then |
|
314 if [ ! -f "$BUG_PROJECT" ]; then |
|
315 echo "BUG_PROJECT file does not exist. Type 'bug create'" |
|
316 exit 0 |
|
317 fi |
|
318 fi |
|
319 |
|
320 if [ -z "$CMD" ]; then |
289 usage |
321 usage |
290 exit 1 |
322 exit 1 |
291 fi |
323 fi |
292 |
324 |
293 case "$CMD" in |
325 case "$CMD" in |
|
326 -h) |
|
327 echo "Usage: bug [[alvpe] [del] [create]] [args]" |
|
328 exit 1 |
|
329 ;; |
294 a*) |
330 a*) |
295 add || exit 1 |
331 add || exit 1 |
296 ;; |
332 ;; |
297 l*) |
333 l*) |
298 list || exit 1 |
334 list || exit 1 |