| 1 | package App::JC::Client::listIssues; | ||
| 2 | #ABSTRACT: class implementing the add issue command of the jira client | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use MooseX::App::Command; | ||
| 6 | extends qw(App::JC::Client); | ||
| 7 | |||
| 8 | use Term::ANSIColor; | ||
| 9 | use Try::Tiny; | ||
| 10 | use JIRA::Client::Automated; | ||
| 11 | |||
| 12 | # the version of the module | ||
| 13 | our $VERSION = '0.001'; | ||
| 14 | |||
| 15 | use String::Formatter named_stringf => { | ||
| 16 | codes => { | ||
| 17 | s => sub { $_ }, # string itself | ||
| 18 | }, | ||
| 19 | }; | ||
| 20 | |||
| 21 | command_short_description 'create an issue within a project'; | ||
| 22 | command_usage 'jc.pl add_issue <project> <type> <summary> <description>'; | ||
| 23 | |||
| 24 | |||
| 25 | option 'project' => ( | ||
| 26 | is => 'ro', | ||
| 27 | isa => 'Str', | ||
| 28 | required => 1, | ||
| 29 | documentation => q[The Project in which to create the issue], | ||
| 30 | cmd_aliases => [qw(p)], # Alternative option name | ||
| 31 | ); | ||
| 32 | |||
| 33 | option 'tasktype' => ( | ||
| 34 | is => 'ro', | ||
| 35 | isa => 'Str', | ||
| 36 | required => 0, | ||
| 37 | default => "all", | ||
| 38 | documentation => q[what kind of issue to add], | ||
| 39 | cmd_aliases => [qw(t)], # Alternative option name | ||
| 40 | ); | ||
| 41 | |||
| 42 | option 'start' => ( | ||
| 43 | is => 'ro', | ||
| 44 | isa => 'Int', | ||
| 45 | required => 0, | ||
| 46 | default => 1, | ||
| 47 | documentation => q[at which search result to start], | ||
| 48 | cmd_aliases => [qw(s)], # Alternative option name | ||
| 49 | ); | ||
| 50 | |||
| 51 | option 'max' => ( | ||
| 52 | is => 'ro', | ||
| 53 | isa => 'Int', | ||
| 54 | required => 0, | ||
| 55 | default => 100, | ||
| 56 | documentation => q[maximum number of results to show], | ||
| 57 | cmd_aliases => [qw(m)], # Alternative option name | ||
| 58 | ); | ||
| 59 | |||
| 60 | option 'format' => ( | ||
| 61 | is => 'ro', | ||
| 62 | isa => 'Str', | ||
| 63 | required => 0, | ||
| 64 | default => '%10{key}s %{summary}s', | ||
| 65 | documentation => q[in which format to show the output], | ||
| 66 | ); | ||
| 67 | |||
| 68 | |||
| 69 | sub run | ||
| 70 | { | ||
| 71 | my $self = shift; | ||
| 72 | |||
| 73 | my $jira = JIRA::Client::Automated->new($self->url, $self->user, $self->pass); | ||
| 74 | |||
| 75 | my $jql = "project = " . $self->project; | ||
| 76 | |||
| 77 | my $search_results = $jira->search_issues($jql, $self->start, $self->max); # query should be a single string of JQL | ||
| 78 | |||
| 79 | for my $issue (@{$search_results->{issues}}) | ||
| 80 | { | ||
| 81 | my $str=named_stringf($self->format(), { | ||
| 82 | key => $issue->{key}, | ||
| 83 | summary => $issue->{fields}->{summary}, | ||
| 84 | project_key => $issue->{fields}->{project}->{key}, | ||
| 85 | project_name => $issue->{fields}->{project}->{name}, | ||
| 86 | labels => $issue->{fields}->{labels}, | ||
| 87 | creator_user => $issue->{fields}->{creator}->{name}, | ||
| 88 | creator_key => $issue->{fields}->{creator}->{key}, | ||
| 89 | creator_name => $issue->{fields}->{creator}->{displayName}, | ||
| 90 | priority => $issue->{fields}->{priority}->{name}, | ||
| 91 | type => $issue->{fields}->{issuetype}->{name}, | ||
| 92 | description => $issue->{fields}->{description}, | ||
| 93 | |||
| 94 | }); | ||
| 95 | |||
| 96 | printf($str . "\n"); | ||
| 97 | } | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | __END__ |