view translate.pl @ 7:29309bc8d932

initial objects to work with bugzilla web service
author cin
date Fri, 04 Sep 2015 19:41:28 +0300
parents 2a5f38eb25a9
children cc7244ab1b9f
line wrap: on
line source

#!/usr/bin/perl -w

use JSON;
use YAML::XS qw(LoadFile Dump);
use URI;
use XML::Writer;
use IPC::Run qw(start finish);

our @ClassPath = qw(
  /usr/share/java/xalan-j2-serializer.jar
  /usr/share/java/xalan-j2.jar
  /usr/share/java/xerces-j2.jar
  /usr/share/java/xml-commons-resolver.jar
  .
);

my $config = LoadFile("config.yaml");

if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) {
	$config->{bugzilla}{url} .= "/";
}

my $bz = BzRest->new(
	url    => $config->{bugzilla}{url},
	apikey => $config->{bugzilla}{apikey}
);

my @fields = qw(
  id
  summary
  creation_time
  last_change_time
  creator
  assigned_to

  status
  resolution

  priority
  severity
  url

  blocks
  depends_on
  cc

  component
  product
  classification
  version

  actual_time
  estimated_time
  remainig_time
  deadline
);

my %fieldsMap = (
	summary          => 'short_desc',
	id               => 'bug_id',
	creator          => 'reporter',
	status           => 'bug_status',
	severity         => 'bug_severity',
	blocks           => 'blocked',
	depends_on       => 'dependson',
	creation_time    => 'creation_ts',
	last_change_time => 'delta_ts'
);

local (*HIN);

my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
	'<pipe', \*HIN, '>', \*STDOUT )
  or die "failed to create pipe: $!";

my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' );

$writer->xmlDecl("UTF-8");
$writer->startTag("bugzilla");

my %visited;
my @queue = (283);

while (@queue) {
	@queue = grep not( $visited{$_}++ ), @queue;

	last unless @queue;

	print "#Fetching: ", join( ', ', @queue ), "\n";

	my $bugs = $bz->GetBugs( { ids => \@queue } );

	@queue = ();

	foreach my $bug (@$bugs) {

		push @queue, @{ $bug->{depends_on} }
		  if ( $bug->{depends_on} );

		$writer->startTag("bug");
		foreach my $field (@fields) {
			next unless $bug->{$field};

			my $tagName = $fieldsMap{$field} || $field;
			my @values =
			     ref( $bug->{$field} )
			  && ref( $bug->{$field} ) eq 'ARRAY'
			  ? @{ $bug->{$field} }
			  : $bug->{$field};

			foreach my $v (@values) {
				$writer->dataElement( $tagName, $v );
			}
		}
		$writer->endTag();

	}
}

$writer->endTag();

close HIN;
finish($proc);

package BzRest;



__END__

=pod

=head1 NAME

C<translate.pl> - translates bugzilla xml buglist to TaskJuggler format

=head1 METHODS

=head2 xalan(%args)

=over

=item * -IN

Input file

=item * -OUT

Output file

=item * -XSL

XSLT file

=back

=cut