Skip to content

Instantly share code, notes, and snippets.

@milmazz
Created November 17, 2010 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milmazz/704082 to your computer and use it in GitHub Desktop.
Save milmazz/704082 to your computer and use it in GitHub Desktop.
Trac tickets queries
#!/usr/bin/perl
use warnings;
use strict;
use Net::Trac;
use Class::CSV;
# Estableciendo la conexion a la instancia remota de Trac
my $trac = Net::Trac::Connection->new(
url => 'http://trac.example.com/project',
user => 'user',
password => 'password'
);
# Construccion del objecto CSV y definicion de opciones
my $csv = Class::CSV->new(
fields => [qw/ticket sumario estado responsable/],
line_separator => "\r\n",
csv_xs_options => { binary => 1, } # Manejo de caracteres non-ASCII
);
# Nos aseguramos que el inicio de sesion haya sido exitoso
if ( $trac->ensure_logged_in ) {
my $ticket = Net::Trac::Ticket->new( connection => $trac );
# Consultamos cada uno de los tickets indicados en el fichero de entrada
while ( my $line = <> ) {
chomp($line);
if ( $line =~ m/^#\d+$/ ) {
$line =~ s/^#(\d+)$/$1/;
$ticket->load($line);
$csv->add_line(
{
ticket => $ticket->id,
sumario => $ticket->summary,
estado => $ticket->status,
responsable => $ticket->owner
}
);
}
else {
print "[INFO] La linea no cumple el formato requerido: $line\n";
}
}
$csv->print();
}
else {
print "No se pudieron asegurar las credenciales";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment