App-TimeTracker-Command-Gitlab

 view release on metacpan or  search on metacpan

lib/App/TimeTracker/Command/Gitlab.pm  view on Meta::CPAN

package App::TimeTracker::Command::Gitlab;
use strict;
use warnings;
use 5.010;

# ABSTRACT: App::TimeTracker Gitlab plugin
use App::TimeTracker::Utils qw(error_message warning_message);

our $VERSION = "1.004";

use Moose::Role;
use HTTP::Tiny;
use JSON::XS qw(encode_json decode_json);
use URI::Escape qw(uri_escape);

has 'issue' => (
    is            => 'rw',
    isa           => 'Str',
    documentation => 'gitlab issue',
    predicate     => 'has_issue'
);

has 'gitlab_client' => (
    is         => 'rw',
    isa        => 'Maybe[HTTP::Tiny]',
    lazy_build => 1,
    traits     => ['NoGetopt'],
);

sub _build_gitlab_client {
    my $self   = shift;
    my $config = $self->config->{gitlab};

    unless ( $config->{url} && $config->{token} ) {
        error_message(
            "Please configure Gitlab in your TimeTracker config (needs url & token)"
        );
        return;
    }

    return HTTP::Tiny->new(default_headers=>{
        'PRIVATE-TOKEN'=> $self->config->{gitlab}{token},
    });
}

has 'project_id' => (
    is=>'ro',
    isa=>'Str',
    documentation=>'The ID or namespace/name of this project',
    lazy_build=>1,
);

sub _build_project_id {
    my $self = shift;
    return $self->config->{gitlab}{project_id} if $self->config->{gitlab}{project_id};
    my $name = $self->config->{project};
    my $namespace = $self->config->{gitlab}{namespace} || '' ;
    if ($name && $namespace) {
        return join('%2F',$namespace, $name);
    }
    error_message("Please set either project_id, or project and namespace");
    return
}

before [ 'cmd_start', 'cmd_continue', 'cmd_append' ] => sub {
    my $self = shift;
    return unless $self->has_issue;

    my $issuename = 'issue#' . $self->issue;
    $self->insert_tag($issuename);

    my $issue =  $self->_call('GET','projects/'.$self->project_id.'/issues/'.$self->issue);



( run in 0.541 second using v1.01-cache-2.11-cpan-5735350b133 )