bug
changeset 6 0193c946ee18
parent 5 131f3e87f9bf
child 7 17fff740794c
equal deleted inserted replaced
5:131f3e87f9bf 6:0193c946ee18
    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 
   180 }
   200 }
   181 
   201 
   182 function catlist
   202 function catlist
   183 {
   203 {
   184 	LINES=`cat $BUG_PROJECT | wc -l`
   204 	LINES=`cat $BUG_PROJECT | wc -l`
   185 	TOTAIL=$(( LINES - 1 ))
   205 	let TOTAIL=LINES-1
       
   206 	#TOTAIL=$(( LINES - 1 ))
   186 	tail -n $TOTAIL $BUG_PROJECT | grep -v "^#"
   207 	tail -n $TOTAIL $BUG_PROJECT | grep -v "^#"
   187 }
   208 }
   188 
   209 
   189 function searchline
   210 function searchline
   190 {	
   211 {	
   191 	ID=$1
   212 	ID=$1
   192 
   213 
   193 	LINE=`cat $BUG_PROJECT | grep -n "^$ID	" | cut -d : -f 1`
   214 	LINE=`cat $BUG_PROJECT | grep -n "^$ID	" | cut -d : -f 1`
   194 	if [ "x$LINE" != "x" ]; then
   215 	if [ -n "$LINE" ]; then
   195 		echo $LINE
   216 		echo $LINE
   196 		return 0
   217 		return 0
   197 	else
   218 	else
   198 		return 1
   219 		return 1
   199 	fi
   220 	fi
   243 		fi
   264 		fi
   244 	else
   265 	else
   245 		echo "Id not found."
   266 		echo "Id not found."
   246 		rm "$FILE"
   267 		rm "$FILE"
   247 	fi
   268 	fi
   248 
       
   249 }
   269 }
   250 
   270 
   251 function add
   271 function add
   252 {	
   272 {	
   253 	# Get a random file
   273 	# Get a random file
   258 	
   278 	
   259 	ID=`getnext`
   279 	ID=`getnext`
   260 
   280 
   261 	cat > "$FILE" << TEMPLATE
   281 	cat > "$FILE" << TEMPLATE
   262 Id: $ID
   282 Id: $ID
   263 Priority: 
   283 Priority:
   264 State: 
   284 State:
   265 Subject: 
   285 Subject: 
   266 -- Description below --
   286 -- Description below --
   267 TEMPLATE
   287 TEMPLATE
   268 	MD5=`md5sum "$FILE"`
   288 	MD5=`md5sum "$FILE"`
   269 
   289 
   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