| 1 | package App::TimeTracker::Command::GitHub; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use 5.024; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: App::TimeTracker GitHub plugin | ||||||||||
| 7 | 1 | ▶ | use App::TimeTracker::Utils qw(error_message warning_message); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | our $VERSION = "1.002"; | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Pithub; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | has 'issue' => ( | |||||||||
| 15 | is => 'rw', | ||||||||||
| 16 | isa => 'Str', | ||||||||||
| 17 | documentation => 'github issue', | ||||||||||
| 18 | predicate => 'has_issue' | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 1 | has 'github_client' => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | isa => 'Maybe[Pithub]', | ||||||||||
| 24 | lazy_build => 1, | ||||||||||
| 25 | traits => ['NoGetopt'], | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub _build_github_client { | ||||||||
|
Subroutine
_build_github_client: not called CC=7 SCAR=40.3
| |||||||||||
| 29 | 0 | my $self = shift; | |||||||||
| 30 | 0 | my $config = $self->config->{github}; | |||||||||
| 31 | |||||||||||
| 32 | 0 | my %args; | |||||||||
| 33 | |||||||||||
| 34 | # required | ||||||||||
| 35 | 0 | for my $fld (qw(user repo token)) { | |||||||||
| 36 | error_message( "Please configure github." . $fld . ". in your TimeTracker config" ) | ||||||||||
| 37 | 0 | ▶ | unless $config->{$fld}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | $args{$fld} = $config->{$fld}; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # optional | ||||||||||
| 42 | 0 | ▶ | $args{api_uri} = $config->{api_uri} if $config->{api_uri}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | if ( $config->{upstream} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | for my $fld (qw(user repo)) { | |||||||||
| 46 | error_message( "You set upstream, but did not set '" . $fld . "'!" ) | ||||||||||
| 47 | 0 | ▶ | unless $config->{upstream}->{$fld}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $args{$fld} = $config->{upstream}->{$fld}; | |||||||||
| 49 | } | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | return Pithub->new(%args); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | before [ 'cmd_start', 'cmd_continue', 'cmd_append' ] => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||
| 56 | 0 | my $self = shift; | |||||||||
| 57 | 0 | ▶ | return unless $self->has_issue; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 0 | my $issuename = 'issue#' . $self->issue; | |||||||||
| 60 | 0 | $self->insert_tag($issuename); | |||||||||
| 61 | |||||||||||
| 62 | 0 | my $cfg = $self->config->{github}; | |||||||||
| 63 | my $response = | ||||||||||
| 64 | 0 | $self->github_client->issues->get( repo => $cfg->{repo}, issue_id => $self->issue ); | |||||||||
| 65 | 0 | ▶ | unless ( $response->success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | error_message( "Cannot find issue %s in %s/%s", $self->issue, $cfg->@{ 'user', 'repo' } ); | |||||||||
| 67 | 0 | return; | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | my $issue = $response->content; | |||||||||
| 70 | 0 | my $name = $issue->{title}; | |||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | if ( defined $self->description ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | $self->description( $self->description . ' ' . $name ); | |||||||||
| 74 | } | ||||||||||
| 75 | else { | ||||||||||
| 76 | 0 | $self->description($name); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | if ( $self->meta->does_role('App::TimeTracker::Command::Git') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | my $branch = $self->issue; | |||||||||
| 81 | 0 | ▶ | if ($name) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | $branch = $self->safe_branch_name( $self->issue . ' ' . $name ); | |||||||||
| 83 | } | ||||||||||
| 84 | 0 | $branch =~ s/_/-/g; | |||||||||
| 85 | 0 | ▶ | $self->branch( lc($branch) ) unless $self->branch; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | } | ||||||||||
| 87 | 1 | }; | |||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub App::TimeTracker::Data::Task::github_issue { | ||||||||
|
Subroutine
github_issue: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 90 | 0 | my $self = shift; | |||||||||
| 91 | 0 | foreach my $tag ( @{ $self->tags } ) { | |||||||||
| 92 | 0 | ▶ | next unless $tag =~ /^issue#(\d+)/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 0 | return $1; | |||||||||
| 94 | } | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 1 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 98 | |||||||||||
| 99 | 1 | q{ listening to: Train noises on my way from Wien to Graz } | |||||||||
| 100 | |||||||||||
| 101 | __END__ | ||||||||||