App-TimeTracker-Command-Jira
view release on metacpan or search on metacpan
lib/App/TimeTracker/Command/Jira.pm view on Meta::CPAN
package App::TimeTracker::Command::Jira;
use strict;
use warnings;
use 5.010;
# ABSTRACT: App::TimeTracker Jira plugin
use App::TimeTracker::Utils qw(error_message warning_message);
our $VERSION = '1.1';
use Moose::Role;
use JIRA::REST ();
use JSON::XS qw(encode_json decode_json);
use Path::Class;
use Try::Tiny;
use Unicode::Normalize ();
has 'jira_client' => (
is => 'ro',
isa => 'Maybe[JIRA::REST]',
lazy_build => 1,
traits => ['NoGetopt'],
predicate => 'has_jira_client'
);
has 'jira_ticket' => (
is => 'ro',
isa => 'Maybe[HashRef]',
lazy_build => 1,
traits => ['NoGetopt'],
);
has 'jira_ticket_transitions' => (
is => 'rw',
isa => 'Maybe[ArrayRef]',
traits => ['NoGetopt'],
);
sub _build_jira_ticket {
my ($self) = @_;
if ( my $ticket = $self->_init_jira_ticket( $self->_current_task ) ) {
return $ticket;
}
}
sub _build_jira_client {
my $self = shift;
my $config = $self->config->{jira};
unless ($config) {
error_message('Please configure Jira in your TimeTracker config');
return;
}
my $jira_client;
try {
my %auth_cfg = ( url => $config->{server_url}, );
if ( my $token = $config->{token} ) {
$auth_cfg{pat} = $token;
}
elsif ( defined $config->{username} ) {
$auth_cfg{username} = $config->{username};
$auth_cfg{password} = $config->{password};
}
elsif ( $config->{anonymous} ) {
$auth_cfg{anonymous} = 1;
}
$jira_client = JIRA::REST->new( \%auth_cfg );
}
catch {
error_message("Could not build JIRA client.\nEither configure token, anonymous, username/password in your tracker config, .netrc or via Config::Identity, see perldoc JIRA::REST.\nError was:\n'%s'", $_ );
return;
};
return $jira_client;
}
( run in 1.078 second using v1.01-cache-2.11-cpan-39bf76dae61 )