#!/usr/bin/perl ########### # # fbtcmd.pl # Version 0.5 (See NOTE) # July 26, 2004. # Copyright Alcea Technologies Inc. 2004, # All rights reserved. # # NOTE: This is a beta SOAP commandline interface to Alcea Fast BugTrack # and will be changing over the next couple of months. # Visit www.fastbugtrack.com to get the latest copy. # # Update DEFAULT.HOSTNAME.COM to your FBT server name # # Command line interface for Alcea Fast BugTrack... # Uses FBT's soap interface to query, create, and update... # # Syntax: # fbtcmd.pl [options] # # Where # is one of getId, getList, update, or create # [options] is zero or more of: # --service=http://hostname:10000/fastbugtrack.wsdl # --mColumn=columnName # (where column name is one of the columns within the system... it can # be repeated multiple times...) # --output=[xml|plain|table] # --= # (where column is one of mId, mSubject, mDescription, mEnteredBy, XXX) # --infile= # (where filename is a filename containing ": # ########### # use strict; use Getopt::Long; use SOAP::Lite; # +trace => qw(debug); use Data::Dumper; ### # Set a default service here... ### my $SERVICE = "http://DEFAULT.HOSTNAME.COM:10000/fastbugtrack.wsdl"; my $function; # getId,update,newbug,search my ($id, $assignto, $status, $connection); my ($infile); my (@cmd); my (@mColumn); my (%hash); ####### # Process Command line options... ####### $function = shift(@ARGV); if (!defined($function)) { bad_call(); } GetOptions(\%hash, "mEnteredBy:s","mId:s","mSubject:s","mStatus:s","mAssignedTo:s","service:s","loginid:s","password:s", "stdin:s@"=>\@cmd, "infile:s"=>$infile, "mColumn:s@"=>\@mColumn); if (defined($ENV{FBTSERVICE})) { $SERVICE = $ENV{FBTSERVICE}; } if ($function eq "getId" && $#ARGV >= 0) { # set id... $hash{mId} = shift(@ARGV); } if (defined($hash{service})) { $SERVICE = $hash{service}; } if (defined($env{FBTOPTS})) { # tack on additional arguments as if they were passed from the commandline... @ARGV = qw($env{FBTOPTS}); GetOptions(\%hash, "mEnteredBy:s","mId:s","mSubject:s","mStatus:s","mAssignedTo:s","service:s","loginid:s","password:s", "stdin:s@"=>\@cmd, "infile:s"=>$infile, "mColumn:s@"=>\@mColumn); } my ($key, $data, $newkey, $newdata); if (defined($infile)) { open(IN,$infile); while($line = ) { if ($line =~ /^(m[A-Za-z0-9\-]*):(.*)/) { ($newkey,$newdata) = ($1,$2); if (defined($key)) { chomp($data); $hash{$key} = $data; } $key = $newkey; $data = $newdata; } else { $data .= $line; } } close(IN); } my $myService = SOAP::Lite->service($SERVICE); ## Read data from stdin if required... foreach $key (@cmd) { $next = 0; $all = ""; while($next == 0 && ($line = <>)) { chop($line); if ($line =~ /^\.$/) { $hash{$key} = $all; $next = 1; } else { $all .= $line . "\r\n"; } } if ($next == 0) { $hash{$key} = $all; } } # here make sure function is one of the four available if ($function eq "update") { update(); } elsif ($function eq "getList") { getList(); } elsif ($function eq "getId") { getId($hash{mId}); } elsif ($function eq "new") { createNew(); } else { bad_call(); } print "The following arguments were not evaluated:\n" if $ARGV[0]; foreach (@ARGV) { print "$_\n"; } ######## # Get a list of bugs ... (like Filter and/or MainMenu...) ######## sub getList { my (@parms); foreach $key ("mAssignedTo","mStatus","mEnteredBy","mId") { if ($hash{$key}) { push @parms, SOAP::Data->name($key => $hash{$key}); } } if ($#mColumn >= 0) { push @parms, SOAP::Data->name("mColumn" => @mColumn); } $myService -> getBugList(@parms); if (checkError()) { return; } # Plain text display... my $som = $myService->call; if ($som->match('/Envelope/Body/bugList/bugStruct')) { @results = $som->valueof(); $t = new Text::ASCIITable; $t->setCols(@mColumn); foreach $result (@results) { @row = (); foreach $col (@mColumn) { push @row, %$result->{$col}; } $t->addRow(@row); } if ($t->getTableWidth() > 79) { $t->setOptions('outputWidth',79); } print $t->drawPage(0); } else { # HMMM! } } ########## # getId - Get all of the details for a single bug... ########## sub getId { my($id) = @_; my (@parms); foreach $key ("loginid","password") { if ($hash{$key}) { push @parms, SOAP::Data->name($key => $hash{$key}); } } $myService -> getId("$id",@parms); if (checkError()) { return; } $som= $myService->call; print Data::Dumper->Dump([$som], [qw(som)]); } ########### # Create a new bug... ########### sub createNew { my (@parms); foreach $key ("mAssignedTo","mStatus","mEnteredBy","mId") { if ($hash{$key}) { push @parms, SOAP::Data->name($key => $hash{$key}); } } $myService -> newBug(@parms); if (checkError()) { return; } } ########### # Update an existing bug... ########### sub update { my (@parms); foreach $key ("mAssignedTo","mStatus","mEnteredBy","mId","mDescription","mSubject") { if ($hash{$key}) { push @parms, SOAP::Data->name($key => $hash{$key}); } } $myService -> updateBug(@parms); if (checkError()) { return; } } sub checkError() { $som = $myService->call; if ($som->match('/Envelope/Body/errorMessage')) { print "ERROR: " . $som->valueof(); return 1; } return 0; } sub bad_call { print "Invalid function. Valid functions are:\n"; print " get -- Returns the details of a single bug.\n"; print " update -- Updates a bug.\n"; print " new -- Creates a new bug.\n"; print " getList -- Returns a list of bugs found by a search.\n"; exit; }