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