App-JIRAPrint
view release on metacpan or search on metacpan
This script relies on configuration files and on command line options for its configuration.
This will attempt to load three configuration files: `$PWD/.jiraprint.conf` , `$HOME/.jiraprint.conf` and `/etc/jiraprint.conf`.
Each configuration files in in Perl format and can contain the following keys:
{
url => 'https://yourjira.domain.net/',
username => 'jirausername',
password => 'jirapassword',
project => 'PROJ',
}
url, username and password have to be defined in config files.
project can be specified in a config file, but overriden by the command line switch `--project`
Note that each level (going from /etc/, to $HOME, to $PWD) will override the precedent level.
This allows you to define properties (like project) at project, user or global level. A typical setup is to define your project specific stuff
in your project directory, your personnal login details in your `$HOME/.jiraprint.conf` and the organisation wide URL at machine level (in /etc/jiraprint.conf).
# OPTIONS
lib/App/JIRAPrint.pm view on Meta::CPAN
has 'config' => ( is => 'ro', isa => 'HashRef', lazy_build => 1);
has 'config_files' => ( is => 'ro' , isa => 'ArrayRef[Str]' , lazy_build => 1);
has 'shared_directory' => ( is => 'ro', isa => 'Str', lazy_build => 1);
has 'template_file' => ( is => 'ro', isa => 'Str', lazy_build => 1);
# Operation properties
has 'url' => ( is => 'ro', isa => 'Str', lazy_build => 1 );
has 'username' => ( is => 'ro', isa => 'Str' , lazy_build => 1);
has 'password' => ( is => 'ro', isa => 'Str' , lazy_build => 1);
has 'project' => ( is => 'ro', isa => 'Str' , lazy_build => 1 );
has 'sprint' => ( is => 'ro', isa => 'Str' , lazy_build => 1 );
has 'maxissues' => ( is => 'ro', isa => 'Int' , lazy_build => 1);
has 'jql' => ( is => 'ro', isa => 'Str', lazy_build => 1);
has 'fields' => ( is => 'ro', isa => 'ArrayRef[Str]', lazy_build => 1 );
# Objects
has 'jira' => ( is => 'ro', isa => 'JIRA::REST', lazy_build => 1);
has 'tt' => ( is => 'ro', isa => 'Template', lazy_build => 1);
sub _build_jira{
my ($self) = @_;
$log->info("Accessing JIRA At ".$self->url()." as '".$self->username()."' (+password)");
return JIRA::REST->new( $self->url() , $self->username() , $self->password() );
}
sub _build_fields{
my ($self) = @_;
return $self->config()->{fields} // [ qw/key status summary assignee issuetype/ ];
}
sub _build_maxissues{
my ($self) = @_;
return $self->config()->{maxissues} // 100;
lib/App/JIRAPrint.pm view on Meta::CPAN
sub _build_url{
my ($self) = @_;
return $self->config()->{url} // die "Missing url ".$self->config_place()."\n";
}
sub _build_username{
my ($self) = @_;
return $self->config()->{username} // die "Missing username ".$self->config_place()."\n";
}
sub _build_password{
my ($self) = @_;
return $self->config()->{password} // die "Missing password ".$self->config_place()."\n";
}
sub _build_project{
my ($self) = @_;
return $self->config()->{project} // die "Missing project ".$self->config_place()."\n";
}
sub _build_sprint{
my ($self) = @_;
return $self->config()->{sprint} // die "Missing sprint ".$self->config_place()."\n";
lib/App/JIRAPrint.pm view on Meta::CPAN
my $stash = $self->fetch_issues();
my $fio = IO::File->new($self->template_file(), "r");
my $output = '';
$self->tt()->process( $fio , $stash , \$output ) || die $self->tt()->error();
return $output;
}
=head2 fetch_fields
Returns the list of available fiels at this (url, username, password, project)
Usage:
my $fields = $this->fetch_fields();
=cut
sub fetch_fields{
my ($self) = @_;
return $self->jira->GET('/field');
}
=head2 fetch_issues
Fetches issues from JIRA Using this object properties (url, username, password, project, maxissues, fields)
Usage:
my $issues = $this->fetch_issues();
=cut
sub fetch_issues{
my ($self) = @_;
my $issues = $self->jira()->POST('/search', undef , {
scripts/jiraprint view on Meta::CPAN
This script relies on configuration files and on command line options for its configuration.
This will attempt to load three configuration files: C<$PWD/.jiraprint.conf> , C<$HOME/.jiraprint.conf> and C</etc/jiraprint.conf>.
Each configuration files in in Perl format and can contain the following keys:
{
url => 'https://yourjira.domain.net/',
username => 'jirausername',
password => 'jirapassword',
project => 'PROJ',
}
url, username and password have to be defined in config files.
project can be specified in a config file, but overriden by the command line switch C<--project>
Note that each level (going from /etc/, to $HOME, to $PWD) will override the precedent level.
This allows you to define properties (like project) at project, user or global level. A typical setup is to define your project specific stuff
in your project directory, your personnal login details in your C<$HOME/.jiraprint.conf> and the organisation wide URL at machine level (in /etc/jiraprint.conf).
=head1 OPTIONS
{
my $j = App::JIRAPrint->new({ config => {} });
is( $j->config_place() , 'in memory config' );
}
{
my $j = App::JIRAPrint->new({ config_files => [ 't/fullconfig.conf' ]});
ok( $j->config() );
ok( $j->url() );
ok( $j->username() );
ok( $j->password() );
ok( $j->project() );
ok( $j->sprint() );
ok( $j->jql() );
is_deeply( $j->fields() , [ 'a', 'b' ]);
is( $j->maxissues() , 314 );
}
done_testing();
#! perl -w
use Test::More;
use Test::MockModule;
use App::JIRAPrint;
# use Log::Any::Adapter qw/Stderr/;
my $j = App::JIRAPrint->new({ url => 'https://something.atlassian.net', username => 'blabla', password => 'blablabla', project => 'BLA', 'sprint' => '123' });
ok( $j->jira() , "Ok got jira client");
{
my $jira = Test::MockModule->new('JIRA::REST');
$jira->mock( GET => sub{ return [ { bla => 1 , foo => 'bar' }] ; } );
ok( $j->fetch_fields() , "Ok got fields");
}
done_testing();
t/fullconfig.conf view on Meta::CPAN
{
url => 'https://www.donkeyp.com',
username => 'charlie',
password => 'brown',
project => 'PROJ',
sprint => '123',
fields => [ 'a', 'b' ],
maxissues => 314,
}
#! perl -w
use Test::More;
use Test::MockModule;
use App::JIRAPrint;
# use Log::Any::Adapter qw/Stderr/;
my $j = App::JIRAPrint->new({ url => 'https://something.atlassian.net', username => 'blabla', password => 'blablabla', project => 'BLA', 'sprint' => '123' });
ok( $j->jira() , "Ok got jira client");
{
my $jira = Test::MockModule->new('JIRA::REST');
$jira->mock( POST => sub{ return { issues => [ { foo => 1 , bar => 'a' , key => 'whatever' } ] } ; } );
ok( $j->fetch_issues() , "Ok got issues");
}
done_testing();
#! perl -w
use Test::More;
use App::JIRAPrint;
my $j = App::JIRAPrint->new({ url => 'https://something.atlassian.net', username => 'blabla', password => 'blablabla' });
ok( $j->jira() , "Ok got jira client");
done_testing();
t/template.t view on Meta::CPAN
#! perl -w
use Test::More;
use Test::MockModule;
use App::JIRAPrint;
# use Log::Any::Adapter qw/Stderr/;
my $j = App::JIRAPrint->new({ url => 'https://something.atlassian.net', username => 'blabla', password => 'blablabla', project => 'BLA', 'sprint' => '123' });
ok( $j->jira() , "Ok got jira client");
{
my $jira = Test::MockModule->new('JIRA::REST');
$jira->mock( POST => sub{ return { issues => [ { foo => 1 , bar => 'a' , key => 'whatever', fields => { summary => 'blablaHAHAHA',
issuetype => { name => 'Story' }
} } ] } ; } );
like( $j->process_template() , qr /blablaHAHAHA/);
}
( run in 0.920 second using v1.01-cache-2.11-cpan-49f99fa48dc )