| 1 | package JIRA::REST; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Thin wrapper around Jira's REST API | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $JIRA::REST::VERSION = '0.025'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.034; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use JSON 2.23; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use REST::Client; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use HTTP::CookieJar::LWP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my ($class, %args) = &_grok_args; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($path, $api) = ($args{url}->path, '/rest/api/latest'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | # See if the user wants a default REST API: | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($path =~ s:(/rest/.*)$::) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | $api = $1; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $args{url}->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # Strip trailing slashes from $path. For some reason they cause 404 | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # errors down the road. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($path =~ s:/+$::) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $args{url}->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $rest = REST::Client->new($args{rest_client_config}); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Set default base URL | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $rest->setHost($args{url}); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Follow redirects/authentication by default | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $rest->setFollow(1); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | for my $ua ($rest->getUseragent) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | # Configure UserAgent name | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $ua->agent(__PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Set proxy to be used | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $ua->proxy(['http','https'] => $args{proxy}) if $args{proxy}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # Turn off SSL verification if requested | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $ua->ssl_opts(SSL_verify_mode => 0, verify_hostname => 0) if $args{ssl_verify_none}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Configure a cookie_jar so that we can send Cookie headers | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $ua->cookie_jar(HTTP::CookieJar::LWP->new()); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 55 | rest => $rest, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | json => JSON->new->utf8->allow_nonref, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | api => $api, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($args{anonymous}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->{authentication} = 'anonymous'; | |||||||||||||||||||||||||||||||||||||||||
| 62 | # Do not authenticate | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } elsif ($args{pat}) { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->{authentication} = 'personal access token'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $rest->addHeader(Authorization => "Bearer $args{pat}"); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ($args{client_id}) { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->{authentication} = 'access token'; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | foreach (qw/client_secret scope/) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | croak __PACKAGE__ . "::new: '$_' argument must be defined when 'client_id' is defined.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | unless defined $args{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $access_token = _access_token($self, $args{client_id}, $args{client_secret}, $args{scope}); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $rest->addHeader(Authorization => "Bearer $access_token"); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->{authentication} = 'basic'; | |||||||||||||||||||||||||||||||||||||||||
| 78 | # If username and password are not both set we try to lookup the credentials | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (! defined $args{username} || ! defined $args{password}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args{"username"} and defined $args{"password"}
MC/DC0%0/2
defined $args{"username"} and defined $args{"password"}
defined $args{"username"}
defined $args{"password"}
Truth table0%0/3
A and B
A= defined $args{"username"}B= defined $args{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | ($args{username}, $args{password}) = | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | _search_for_credentials($args{url}, $args{username}); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | foreach (qw/username password/) { | |||||||||||||||||||||||||||||||||||||||||
| 85 | croak __PACKAGE__ . "::new: '$_' argument must be a non-empty string.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ! defined $args{$_} || ref $args{$_} || length $args{$_} == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $args{$_} or ref $args{$_} or length $args{$_} == 0
not defined $args{$_} or ref $args{$_}
MC/DC0%0/3
not defined $args{$_} or ref $args{$_} or length $args{$_} == 0
not defined $args{$_}
ref $args{$_}
length $args{$_} == 0
Truth table0%0/4
not(A) or B or C
A= not defined $args{$_}B= ref $args{$_}C= length $args{$_} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | $rest->addHeader( | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | Authorization => | |||||||||||||||||||||||||||||||||||||||||
| 91 | 'Basic ' . encode_base64("$args{username}:$args{password}", '') | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($args{session} && $self->{authentication} eq 'basic') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"session"} and $self->{"authentication"} eq "basic"
MC/DC0%0/2
$args{"session"} and $self->{"authentication"} eq "basic"
$args{"session"}
$self->{"authentication"} eq "basic"
Truth table0%0/3
A and B
A= $args{"session"}B= $self->{"authentication"} eq "basic"
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | $self->{session} = $self->POST( | ||||||||||||||||||||||||||||||||||||||||||
| 98 | '/rest/auth/1/session', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | username => $args{username}, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | password => $args{password}, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub _grok_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_grok_args: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # Valid option names in the order expected by the old-form constructor | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @opts = qw/url username password rest_client_config proxy ssl_verify_none anonymous pat session client_id client_secret scope/; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my %args; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (@args == 1 && ref $args[0] && ref $args[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@args == 1 and ref $args[0] and ref $args[0] eq "HASH"
@args == 1 and ref $args[0]
MC/DC0%0/3
@args == 1 and ref $args[0] and ref $args[0] eq "HASH"
@args == 1
ref $args[0]
ref $args[0] eq "HASH"
Truth table0%0/4
A and B and C
A= @args == 1B= ref $args[0]C= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | # The new-form constructor expects a single hash reference. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | @args{@opts} = delete $args[0]->@{@opts}; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | croak __PACKAGE__ . "::new: unknown arguments: '", join("', '", sort keys $args[0]->%*), "'.\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | if keys $args[0]->%*; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # The old-form constructor expects a list of positional parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | @args{@opts} = @args; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # Turn the url into a URI object | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if (! $args{url}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | croak __PACKAGE__ . "::new: 'url' argument must be defined.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif (! ref $args{url}) { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $args{url} = URI->new($args{url}); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } elsif (! $args{url}->isa('URI')) { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | croak __PACKAGE__ . "::new: 'url' argument must be a URI object.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | for ($args{rest_client_config}) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $_ //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_ //= {}
MC/DC0%0/1
$_ //= {}
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | croak __PACKAGE__ . "::new: 'rest_client_config' argument must be a hash reference.\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $_ and ref $_ and ref $_ eq "HASH"
defined $_ and ref $_
MC/DC0%0/3
defined $_ and ref $_ and ref $_ eq "HASH"
defined $_
ref $_
ref $_ eq "HASH"
Truth table0%0/4
A and B and C
A= defined $_B= ref $_C= ref $_ eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | unless defined && ref && ref eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return ($class, %args); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub _access_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_access_token: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ($self, $client_id, $client_secret, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $path = | |||||||||||||||||||||||||||||||||||||||||
| 150 | '/rest/oauth2/latest/token?' . | ||||||||||||||||||||||||||||||||||||||||||
| 151 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 152 | '&', | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 'grant_type=client_credentials', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 'client_id=' . uri_escape($client_id), | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 'client_secret=' . uri_escape($client_secret), | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 'scope=' . uri_escape($scope), | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | $self->{rest}->POST( | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $path, | |||||||||||||||||||||||||||||||||||||||||
| 161 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | {'Content-Type' => 'application/x-www-form-urlencoded'}, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return $self->_content()->{access_token}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $self->DELETE('/rest/auth/1/session') if exists $self->{session}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub _search_for_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_search_for_credentials: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my ($URL, $username) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my (@errors, $password); | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Try .netrc first | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ($username, $password) = eval { _user_pass_from_netrc($URL, $username) }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | push @errors, "Net::Netrc: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return ($username, $password) if defined $username && defined $password; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $username and defined $password
MC/DC0%0/2
defined $username and defined $password
defined $username
defined $password
Truth table0%0/3
A and B
A= defined $usernameB= defined $password
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | # Fallback to Config::Identity | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $stub = $ENV{JIRA_REST_IDENTITY} || "jira"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'JIRA_REST_IDENTITY'} || 'jira'
MC/DC0%0/1
$ENV{'JIRA_REST_IDENTITY'} || 'jira'
$ENV{'JIRA_REST_IDENTITY'}
Truth table0%0/2
A
A= $ENV{'JIRA_REST_IDENTITY'}
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ($username, $password) = eval { _user_pass_from_config_identity($stub) }; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | push @errors, "Config::Identity: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | return ($username, $password) if defined $username && defined $password; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $username and defined $password
MC/DC0%0/2
defined $username and defined $password
defined $username
defined $password
Truth table0%0/3
A and B
A= defined $usernameB= defined $password
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # Still not defined, so we report errors | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | for (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | s/\n//g; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | s/ at \S+ line \d+.*//; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | croak __PACKAGE__ . "::new: Could not locate credentials. Tried these modules:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | . join("", map { "* $_\n" } @errors) | |||||||||||||||||||||||||||||||||||||||||
| 197 | . "Please specify the USERNAME and PASSWORD as arguments to new"; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub _user_pass_from_config_identity { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_user_pass_from_config_identity: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ($stub) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my ($username, $password); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | eval {require Config::Identity; Config::Identity->VERSION(0.0019) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | or croak "Can't load Config::Identity 0.0019 or later.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my %id = Config::Identity->load_check( $stub, [qw/username password/] ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return ($id{username}, $id{password}); | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub _user_pass_from_netrc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_user_pass_from_netrc: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my ($URL, $username) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $password; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | eval {require Net::Netrc; 1} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | or croak "Can't require Net::Netrc module."; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if (my $machine = Net::Netrc->lookup($URL->host, $username)) { # $username may be undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $username = $machine->login; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $password = $machine->password; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | croak "No credentials found in the .netrc file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return ($username, $password); | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my ($self, $content, $type, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $type = 'text/plain' unless $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $code = 500 unless $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $msg = __PACKAGE__ . " Error[$code"; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (eval {require HTTP::Status}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (my $status = HTTP::Status::status_message($code)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $msg .= " - $status"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $msg .= "]:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ($type =~ m:text/plain:i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $msg .= $content; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } elsif ($type =~ m:application/json:) { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # Jira errors may be laid out in all sorts of ways. You have to look | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # them up from the scant documentation at | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # https://docs.atlassian.com/jira/REST/latest/. Previously, I tried to | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # grok the actual message inside this JSON structure but I failed | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # miserably. So, I decided to give up and simply show the actual JSON | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # string as a message. It won't be as readable, but it will be complete | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # and correct! | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $msg .= $content; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | } elsif ($type =~ m:text/html:i && eval {require HTML::TreeBuilder}) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type =~ m[text/html]iu and eval {
do {
require HTML::TreeBuilder
}
}
MC/DC0%0/2
$type =~ m[text/html]iu and eval {
do {
require HTML::TreeBuilder
}
}
$type =~ m[text/html]iu
eval {
do {
require HTML::TreeBuilder
}
}
Truth table0%0/3
A and B
A= $type =~ m[text/html]iuB= eval {
do {
require HTML::TreeBuilder
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $msg .= HTML::TreeBuilder->new_from_content($content)->as_text; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } elsif ($type =~ m:^(text/|application|xml):i) { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $msg .= "<Content-Type: $type>$content</Content-Type>"; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $msg .= "<Content-Type: $type>(binary content not shown)</Content-Type>"; | |||||||||||||||||||||||||||||||||||||||||
| 256 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $msg =~ s/\n*$/\n/s; # end message with a single newline | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub _content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $rest = $self->{rest}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $code = $rest->responseCode(); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $type = $rest->responseHeader('Content-Type'); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $content = $rest->responseContent(); | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $code =~ /^2/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | or croak $self->_error($content, $type, $code); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | return unless $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if (! defined $type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | croak $self->_error("Cannot convert response content with no Content-Type specified."); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } elsif ($type =~ m:^application/json:i) { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return $self->{json}->decode($content); | |||||||||||||||||||||||||||||||||||||||||
| 278 | } elsif ($type =~ m:^text/plain:i) { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | croak $self->_error("I don't understand content with Content-Type '$type'."); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub _build_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_path: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my ($self, $path, $query) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # Prefix $path with the default API prefix unless it already specifies | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # one or it's an absolute URL. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $path = $self->{api} . $path unless $path =~ m@^(?:/rest/|(?i)https?:)@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if (defined $query) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | croak $self->_error("The QUERY argument must be a hash reference.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $query and ref $query eq "HASH"
MC/DC0%0/2
ref $query and ref $query eq "HASH"
ref $query
ref $query eq "HASH"
Truth table0%0/3
A and B
A= ref $queryB= ref $query eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | unless ref $query && ref $query eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return $path . '?'. join('&', map {$_ . '=' . uri_escape($query->{$_})} keys %$query); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub GET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GET: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my ($self, $path, $query) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->{rest}->GET($self->_build_path($path, $query)); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return $self->_content(); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub DELETE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my ($self, $path, $query) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->{rest}->DELETE($self->_build_path($path, $query)); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return $self->_content(); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub PUT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my ($self, $path, $query, $value, $headers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $path = $self->_build_path($path, $query); | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $headers ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table0%0/2
A
A= $headers
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $headers->{'Content-Type'} //= 'application/json;charset=UTF-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers->{"Content-Type"} //= "application/json;charset=UTF-8"
MC/DC0%0/1
$headers->{"Content-Type"} //= "application/json;charset=UTF-8"
$headers->{"Content-Type"}
Truth table0%0/2
A
A= $headers->{"Content-Type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $self->{rest}->PUT($path, $self->{json}->encode($value), $headers); | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return $self->_content(); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub POST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
POST: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my ($self, $path, $query, $value, $headers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $path = $self->_build_path($path, $query); | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $headers ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table0%0/2
A
A= $headers
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $headers->{'Content-Type'} //= 'application/json;charset=UTF-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers->{"Content-Type"} //= "application/json;charset=UTF-8"
MC/DC0%0/1
$headers->{"Content-Type"} //= "application/json;charset=UTF-8"
$headers->{"Content-Type"}
Truth table0%0/2
A
A= $headers->{"Content-Type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $self->{rest}->POST($path, $self->{json}->encode($value), $headers); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $self->_content(); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | sub rest_client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_client: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | return $self->{rest}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub set_search_iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_search_iterator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my %params = ( %$params ); # rebuild the hash to own it | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $params{startAt} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | $self->{iter} = { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | params => \%params, # params hash to be used in the next call | |||||||||||||||||||||||||||||||||||||||||
| 357 | offset => 0, # offset of the next issue to be fetched | ||||||||||||||||||||||||||||||||||||||||||
| 358 | results => { # results of the last call (this one is fake) | ||||||||||||||||||||||||||||||||||||||||||
| 359 | startAt => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 360 | total => -1, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | issues => [], | ||||||||||||||||||||||||||||||||||||||||||
| 362 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 363 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub next_issue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_issue: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | my $iter = $self->{iter} | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | or croak $self->_error("You must call set_search_iterator before calling next_issue"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | if ($iter->{offset} == $iter->{results}{total}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | # This is the end of the search results | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self->{iter} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 378 | } elsif ($iter->{offset} == $iter->{results}{startAt} + $iter->{results}{issues}->@*) { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | # Time to get the next bunch of issues | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $iter->{params}{startAt} = $iter->{offset}; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $iter->{results} = $self->POST('/search', undef, $iter->{params}); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $iter->{results}{issues}[$iter->{offset}++ - $iter->{results}{startAt}]; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub attach_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach_files: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ($self, $issueIdOrKey, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | # We need to violate the REST::Client class encapsulation to implement | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # the HTTP POST method necessary to invoke the /issue/key/attachments | ||||||||||||||||||||||||||||||||||||||||||
| 392 | # REST endpoint because it has to use the form-data Content-Type. | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $rest = $self->{rest}; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | # FIXME: How to attach all files at once? | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||
| 398 | my $response = $rest->getUseragent()->post( | ||||||||||||||||||||||||||||||||||||||||||
| 399 | $rest->getHost . "/rest/api/latest/issue/$issueIdOrKey/attachments", | ||||||||||||||||||||||||||||||||||||||||||
| 400 | $rest->{_headers}->%*, | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | 'X-Atlassian-Token' => 'nocheck', | |||||||||||||||||||||||||||||||||||||||||
| 402 | 'Content-Type' => 'form-data', | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 'Content' => [ file => [$file, encode_utf8( $file )] ], | ||||||||||||||||||||||||||||||||||||||||||
| 404 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $response->is_success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | or croak $self->_error("attach_files($file): " . $response->status_line); | ||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | __END__ | ||||||||||||||||||||||||||||||||||||||||||