App-Git-IssueManager

 view release on metacpan or  search on metacpan

lib/App/Git/IssueManager/List.pm  view on Meta::CPAN

package App::Git::IssueManager::List;
#ABSTRACT: class implementing the add issue command of the GIT IssueManager
use strict;
use warnings;
use MooseX::App::Command;
extends qw(App::Git::IssueManager);
use Git::LowLevel;
use Git::IssueManager;
use Git::IssueManager::Issue;
use Text::ANSITable 0.602;
use Term::ANSIColor;
use Try::Tiny;
use Data::Dumper;

command_short_description 'list issues of a repository';
command_usage 'git issue list';

option 'show_status' => (
    is                => 'rw',
    isa               => 'ArrayRef[Str]',
    required          => 0,
    documentation     => q[select which issues with which stati should be displayd (open, assigned, inprogress, closed, all)],
    cmd_aliases       => [qw(s)],
    default           => sub {return ["open"];}
);

sub run
{
  my $self        = shift;
  my @stati=@{$self->show_status};

  #remove all numbers from array
  my @help;
  for my $s (@stati)
  {
    push(@help,$s) unless $s =~/^\d+$/;
  }
  @stati=@help;
  $self->show_status(\@help);

  my @all_stati=("open","closed","assigned","inprogress","all");

  # check if a wrong status is requested
  for my $s (@{$self->show_status})
  {
    if(!grep( /^$s$/, @all_stati ))
    {
      die("ERROR: unkown status  \"" . $s . "\"\n");
    }
  }

  # check if all issues are requested

  if (grep( /^all$/, @stati ) )
  {
    $self->show_status(['open','closed','inprogress','assigned']);
  }

  my $manager     = Git::IssueManager->new(repository=>Git::LowLevel->new(git_dir=> "."));
  if (!$manager->ready)
  {
    print("IssueManager not initialized yet. Please call \"init\" command to do so.");
    exit(-1);
  }
  binmode(STDOUT, ":utf8");
  my @issues=$manager->list();

  my $t = Text::ANSITable->new;
  $t->use_utf8(1);
  $t->use_color(1);
  $t->border_style('UTF8::SingleLine');
  $t->columns(["ID", "Subject", "Type", "Priority", "Severity", "Status", "Author", "Worker"]);



( run in 1.885 second using v1.01-cache-2.11-cpan-98e64b0badf )