App-Gitc

 view release on metacpan or  search on metacpan

lib/App/Gitc/Its/Jira.pm  view on Meta::CPAN

package App::Gitc::Its::Jira;
use strict;
use warnings;

# ABSTRACT: Support for Atlassian JIRA ITS (Issue Tracking System)
our $VERSION = '0.60'; # VERSION


use JIRA::Client;
use JIRA::Client::REST;
use Try::Tiny;
use List::MoreUtils qw( any );
use YAML;

use App::Gitc::Util qw(
    project_config
    command_name
    current_branch
);


sub label_service { return 'JIRA'; }
sub label_issue   { return 'Issue'; }

our $default_jira_user     = 'someuser';
our $default_jira_password = 'somepassword';
our $jira_conf;

sub lookup_jira_user {
    my $self = shift;
    if (not $jira_conf and -e "$ENV{HOME}/.gitc/jira.conf") {
        $jira_conf = YAML::LoadFile("$ENV{HOME}/.gitc/jira.conf");
    } else {
        $jira_conf = {};
    }
    my $jira_user     = $jira_conf->{user} || $default_jira_user;
    my $jira_password = $jira_conf->{password} || $default_jira_password;
    return ($jira_user, $jira_password);
}

sub lookup_status_strings
{
    my $self = shift;

    my $jira = $self->get_jira_object or return;

    my $statuses = $jira->getStatuses();
    return unless $statuses;

    return { map { $_->{id} => $_->{name} } @{$statuses} };
}

sub get_jira_object
{
    my $self = shift;

    # to find an JIRA issue, we need a number and URI
    my $uri = project_config()->{'jira_uri'} or return;

    # build and return the Issue object
    our %jira;
    my $jira = $jira{$uri};
    if ( not $jira ) {
        my ($jira_user, $jira_password) = $self->lookup_jira_user;
        $jira{$uri} = $jira
            = JIRA::Client->new( $uri, $jira_user, $jira_password );
        die "Unable to connect to JIRA SOAP API" unless $jira;
    }

    return $jira;
}



( run in 2.082 seconds using v1.01-cache-2.11-cpan-5735350b133 )