JIRA-REST-0.024/0000775000423100042310000000000014553247333012766 5ustar gustavogustavoJIRA-REST-0.024/Makefile.PL0000644000423100042310000000320214553247333014733 0ustar gustavogustavo# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.029. use strict; use warnings; use 5.016; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Thin wrapper around Jira's REST API", "AUTHOR" => "Gustavo L. de M. Chaves ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "JIRA-REST", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.016", "NAME" => "JIRA::REST", "PREREQ_PM" => { "Carp" => 0, "Config::Identity" => "0.0019", "Encode" => 0, "HTML::TreeBuilder" => 0, "HTTP::CookieJar::LWP" => 0, "HTTP::Status" => 0, "JSON" => "2.23", "MIME::Base64" => 0, "Net::Netrc" => 0, "REST::Client" => 0, "URI" => 0, "URI::Escape" => 0, "utf8" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => 0, "lib" => 0 }, "VERSION" => "0.024", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Config::Identity" => "0.0019", "Encode" => 0, "HTML::TreeBuilder" => 0, "HTTP::CookieJar::LWP" => 0, "HTTP::Status" => 0, "JSON" => "2.23", "MIME::Base64" => 0, "Net::Netrc" => 0, "REST::Client" => 0, "Test::More" => 0, "URI" => 0, "URI::Escape" => 0, "lib" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); JIRA-REST-0.024/t/0000775000423100042310000000000014553247333013231 5ustar gustavogustavoJIRA-REST-0.024/t/release-kwalitee.t0000644000423100042310000000052714553247333016643 0ustar gustavogustavo BEGIN { unless ($ENV{RELEASE_TESTING}) { print qq{1..0 # SKIP these tests are for release candidate testing\n}; exit } } # this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.12 use strict; use warnings; use Test::More 0.88; use Test::Kwalitee 1.21 'kwalitee_ok'; kwalitee_ok( qw( -use_strict ) ); done_testing; JIRA-REST-0.024/t/01-atlassian.t0000755000423100042310000000345114553247333015617 0ustar gustavogustavo# -*- cperl -*- use 5.016; use warnings; use lib 't'; use Test::More; use JIRA::REST; if ($ENV{RELEASE_TESTING}) { plan tests => 7; } else { plan skip_all => 'these tests are for release testing'; } my $jira = new_ok('JIRA::REST', [{ url => 'https://jira.atlassian.com', anonymous => 1 }]); BAIL_OUT('Cannot proceed because I could not create a JIRA::REST object') unless $jira; if (my $project = eval {$jira->GET('/rest/api/latest/project/JRASERVER')}) { ok(defined $project && $project->{key} eq 'JRASERVER', 'GET /rest/api/latest/project/JRASERVER'); } else { fail('GET /rest/api/latest/project/JRASERVER'); } if (my $project = eval {$jira->GET('/project/JRASERVER')}) { ok(defined $project && $project->{key} eq 'JRASERVER', 'GET /project/JRASERVER'); } else { fail('GET /project/JRASERVER'); } if (my $info = eval {$jira->GET('/serverInfo')}) { ok(defined $info && $info->{serverTitle} =~ /Atlassian/, 'GET /serverInfo'); } else { fail('GET /serverInfo'); } $jira->set_search_iterator({ jql => 'project = JRASERVER AND resolution IS EMPTY AND issuetype = Bug ORDER BY key DESC', fields => [qw/description/], maxResults => 10, }); if (my $issue = eval {$jira->next_issue}) { ok(defined $issue && ref $issue && exists $issue->{fields}{description}, 'JQL search'); } else { fail('JQL search'); } $jira = new_ok('JIRA::REST', [{ url => 'https://jira.atlassian.com/rest/api/latest', anonymous => 1 }]); BAIL_OUT('Cannot proceed because I could not create a JIRA::REST object with a default API') unless $jira; if (my $project = eval {$jira->GET('/project/JRASERVER')}) { ok(defined $project && $project->{key} eq 'JRASERVER', 'GET /project/JRASERVER (with set default API)'); } else { fail('GET /project/JRASERVER (with set default API)'); } 1; JIRA-REST-0.024/t/author-pod-coverage.t0000644000423100042310000000056714553247333017277 0ustar gustavogustavo#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use strict; use warnings; use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); JIRA-REST-0.024/t/author-pod-syntax.t0000644000423100042310000000045414553247333017025 0ustar gustavogustavo#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); JIRA-REST-0.024/t/00-load.t0000755000423100042310000000016614553247333014556 0ustar gustavogustavo# -*- cperl -*- use 5.016; use warnings; use lib 't'; use Test::More tests => 1; BEGIN { use_ok 'JIRA::REST'; } 1; JIRA-REST-0.024/dist.ini0000644000423100042310000000144314553247333014432 0ustar gustavogustavo; See this to understand: http://dzil.org/tutorial/convert-dist.html name = JIRA-REST author = Gustavo L. de M. Chaves license = Perl_5 copyright_holder = CPQD [GatherDir] exclude_match = ~$ [@Filter] -bundle = @Basic -remove = GatherDir -remove = Readme [NextRelease] [@Git] [AutoPrereqs] [Prereqs / Recommends] HTTP::Status = 0 Net::Netrc = 0 [PodWeaver] [Git::NextVersion] [PkgVersion] [MetaJSON] [PodSyntaxTests] [PodCoverageTests] [Test::Kwalitee] skiptest = use_strict ; Don't test for strictness since we use 5.016 [GitHub::Update] [MetaResources] homepage = https://metacpan.org/module/JIRA::REST repository.web = https://github.com/gnustavo/jira-rest repository.url = https://github.com/gnustavo/JIRA-REST.git repository.type = git JIRA-REST-0.024/LICENSE0000644000423100042310000004370614553247333014003 0ustar gustavogustavoThis software is copyright (c) 2024 by CPQD . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2024 by CPQD . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2024 by CPQD . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End JIRA-REST-0.024/lib/0000775000423100042310000000000014553247333013534 5ustar gustavogustavoJIRA-REST-0.024/lib/JIRA/0000775000423100042310000000000014553247333014261 5ustar gustavogustavoJIRA-REST-0.024/lib/JIRA/REST.pm0000644000423100042310000006403414553247333015401 0ustar gustavogustavopackage JIRA::REST; # ABSTRACT: Thin wrapper around Jira's REST API $JIRA::REST::VERSION = '0.024'; use 5.016; use utf8; use warnings; use Carp; use URI; use Encode; use MIME::Base64; use URI::Escape; use JSON 2.23; use REST::Client; use HTTP::CookieJar::LWP; sub new { my ($class, %args) = &_grok_args; my ($path, $api) = ($args{url}->path, '/rest/api/latest'); # See if the user wants a default REST API: if ($path =~ s:(/rest/.*)$::) { $api = $1; $args{url}->path($path); } # Strip trailing slashes from $path. For some reason they cause 404 # errors down the road. if ($path =~ s:/+$::) { $args{url}->path($path); } unless ($args{anonymous} || $args{pat}) { # If username and password are not set we try to lookup the credentials if (! defined $args{username} || ! defined $args{password}) { ($args{username}, $args{password}) = _search_for_credentials($args{url}, $args{username}); } foreach (qw/username password/) { croak __PACKAGE__ . "::new: '$_' argument must be a non-empty string.\n" if ! defined $args{$_} || ref $args{$_} || length $args{$_} == 0; } } my $rest = REST::Client->new($args{rest_client_config}); # Set default base URL $rest->setHost($args{url}); # Follow redirects/authentication by default $rest->setFollow(1); unless ($args{anonymous} || $args{session}) { # Since Jira doesn't send an authentication challenge, we force the # sending of the authentication header. $rest->addHeader( Authorization => $args{pat} ? "Bearer $args{pat}" : 'Basic ' . encode_base64("$args{username}:$args{password}", '') ); } for my $ua ($rest->getUseragent) { # Configure UserAgent name $ua->agent(__PACKAGE__); # Set proxy to be used $ua->proxy(['http','https'] => $args{proxy}) if $args{proxy}; # Turn off SSL verification if requested $ua->ssl_opts(SSL_verify_mode => 0, verify_hostname => 0) if $args{ssl_verify_none}; # Configure a cookie_jar so that we can send Cookie headers $ua->cookie_jar(HTTP::CookieJar::LWP->new()); } my $jira = bless { rest => $rest, json => JSON->new->utf8->allow_nonref, api => $api, } => $class; $jira->{_session} = $jira->POST('/rest/auth/1/session', undef, { username => $args{username}, password => $args{password}, }) if $args{session}; return $jira; } sub _grok_args { my ($class, @args) = @_; # Valid option names in the order expected by the old-form constructor my @opts = qw/url username password rest_client_config proxy ssl_verify_none anonymous pat session/; my %args; if (@args == 1 && ref $args[0] && ref $args[0] eq 'HASH') { # The new-form constructor expects a single hash reference. @args{@opts} = delete @{$args[0]}{@opts}; croak __PACKAGE__ . "::new: unknown arguments: '", join("', '", sort keys %{$args[0]}), "'.\n" if keys %{$args[0]}; } else { # The old-form constructor expects a list of positional parameters. @args{@opts} = @args; } # Turn the url into a URI object if (! $args{url}) { croak __PACKAGE__ . "::new: 'url' argument must be defined.\n"; } elsif (! ref $args{url}) { $args{url} = URI->new($args{url}); } elsif (! $args{url}->isa('URI')) { croak __PACKAGE__ . "::new: 'url' argument must be a URI object.\n"; } if (!!$args{anonymous} + !!$args{pat} + !!$args{session} > 1) { croak __PACKAGE__ . "::new: 'anonymous', 'pat', and 'session' are mutually exclusive options.\n" } for ($args{rest_client_config}) { $_ //= {}; croak __PACKAGE__ . "::new: 'rest_client_config' argument must be a hash reference.\n" unless defined && ref && ref eq 'HASH'; } # remove the REST::Client faux config 'proxy' if set and use it later. # This is deprecated since v0.017 if (my $proxy = delete $args{rest_client_config}{proxy}) { carp __PACKAGE__ . "::new: passing 'proxy' in the 'rest_client_config' hash is deprecated. Please, use the corresponding argument instead.\n"; $args{proxy} //= $proxy; } return ($class, %args); } sub new_session { my ($class, @args) = @_; if (@args == 1 && ref $args[0] && ref $args[0] eq 'HASH') { $args[0]{session} = 1; } else { $args[8] = 1; } return $class->new(@args); } sub DESTROY { my $self = shift; $self->DELETE('/rest/auth/1/session') if exists $self->{_session}; return; } sub _search_for_credentials { my ($URL, $username) = @_; my (@errors, $password); # Try .netrc first ($username, $password) = eval { _user_pass_from_netrc($URL, $username) }; push @errors, "Net::Netrc: $@" if $@; return ($username, $password) if defined $username && defined $password; # Fallback to Config::Identity my $stub = $ENV{JIRA_REST_IDENTITY} || "jira"; ($username, $password) = eval { _user_pass_from_config_identity($stub) }; push @errors, "Config::Identity: $@" if $@; return ($username, $password) if defined $username && defined $password; # Still not defined, so we report errors for (@errors) { chomp; s/\n//g; s/ at \S+ line \d+.*//; } croak __PACKAGE__ . "::new: Could not locate credentials. Tried these modules:\n" . join("", map { "* $_\n" } @errors) . "Please specify the USERNAME and PASSWORD as arguments to new"; } sub _user_pass_from_config_identity { my ($stub) = @_; my ($username, $password); eval {require Config::Identity; Config::Identity->VERSION(0.0019) } or croak "Can't load Config::Identity 0.0019 or later.\n"; my %id = Config::Identity->load_check( $stub, [qw/username password/] ); return ($id{username}, $id{password}); } sub _user_pass_from_netrc { my ($URL, $username) = @_; my $password; eval {require Net::Netrc; 1} or croak "Can't require Net::Netrc module."; if (my $machine = Net::Netrc->lookup($URL->host, $username)) { # $username may be undef $username = $machine->login; $password = $machine->password; } else { croak "No credentials found in the .netrc file.\n"; } return ($username, $password); } sub _error { my ($self, $content, $type, $code) = @_; $type = 'text/plain' unless $type; $code = 500 unless $code; my $msg = __PACKAGE__ . " Error[$code"; if (eval {require HTTP::Status}) { if (my $status = HTTP::Status::status_message($code)) { $msg .= " - $status"; } } $msg .= "]:\n"; if ($type =~ m:text/plain:i) { $msg .= $content; } elsif ($type =~ m:application/json:) { # Jira errors may be laid out in all sorts of ways. You have to look # them up from the scant documentation at # https://docs.atlassian.com/jira/REST/latest/. Previously, I tried to # grok the actual message inside this JSON structure but I failed # miserably. So, I decided to give up and simply show the actual JSON # string as a message. It won't be as readable, but it will be complete # and correct! $msg .= $content; } elsif ($type =~ m:text/html:i && eval {require HTML::TreeBuilder}) { $msg .= HTML::TreeBuilder->new_from_content($content)->as_text; } elsif ($type =~ m:^(text/|application|xml):i) { $msg .= "$content"; } else { $msg .= "(binary content not shown)"; }; $msg =~ s/\n*$/\n/s; # end message with a single newline return $msg; } sub _content { my ($self) = @_; my $rest = $self->{rest}; my $code = $rest->responseCode(); my $type = $rest->responseHeader('Content-Type'); my $content = $rest->responseContent(); $code =~ /^2/ or croak $self->_error($content, $type, $code); return unless $content; if (! defined $type) { croak $self->_error("Cannot convert response content with no Content-Type specified."); } elsif ($type =~ m:^application/json:i) { return $self->{json}->decode($content); } elsif ($type =~ m:^text/plain:i) { return $content; } else { croak $self->_error("I don't understand content with Content-Type '$type'."); } } sub _build_path { my ($self, $path, $query) = @_; # Prefix $path with the default API prefix unless it already specifies # one or it's an absolute URL. $path = $self->{api} . $path unless $path =~ m@^(?:/rest/|(?i)https?:)@; if (defined $query) { croak $self->_error("The QUERY argument must be a hash reference.") unless ref $query && ref $query eq 'HASH'; return $path . '?'. join('&', map {$_ . '=' . uri_escape($query->{$_})} keys %$query); } else { return $path; } } sub GET { my ($self, $path, $query) = @_; $self->{rest}->GET($self->_build_path($path, $query)); return $self->_content(); } sub DELETE { my ($self, $path, $query) = @_; $self->{rest}->DELETE($self->_build_path($path, $query)); return $self->_content(); } sub PUT { my ($self, $path, $query, $value, $headers) = @_; $path = $self->_build_path($path, $query); $headers ||= {}; $headers->{'Content-Type'} //= 'application/json;charset=UTF-8'; $self->{rest}->PUT($path, $self->{json}->encode($value), $headers); return $self->_content(); } sub POST { my ($self, $path, $query, $value, $headers) = @_; $path = $self->_build_path($path, $query); $headers ||= {}; $headers->{'Content-Type'} //= 'application/json;charset=UTF-8'; $self->{rest}->POST($path, $self->{json}->encode($value), $headers); return $self->_content(); } sub rest_client { my ($self) = @_; return $self->{rest}; } sub set_search_iterator { my ($self, $params) = @_; my %params = ( %$params ); # rebuild the hash to own it $params{startAt} = 0; $self->{iter} = { params => \%params, # params hash to be used in the next call offset => 0, # offset of the next issue to be fetched results => { # results of the last call (this one is fake) startAt => 0, total => -1, issues => [], }, }; return; } sub next_issue { my ($self) = @_; my $iter = $self->{iter} or croak $self->_error("You must call set_search_iterator before calling next_issue"); if ($iter->{offset} == $iter->{results}{total}) { # This is the end of the search results $self->{iter} = undef; return; } elsif ($iter->{offset} == $iter->{results}{startAt} + @{$iter->{results}{issues}}) { # Time to get the next bunch of issues $iter->{params}{startAt} = $iter->{offset}; $iter->{results} = $self->POST('/search', undef, $iter->{params}); } return $iter->{results}{issues}[$iter->{offset}++ - $iter->{results}{startAt}]; } sub attach_files { my ($self, $issueIdOrKey, @files) = @_; # We need to violate the REST::Client class encapsulation to implement # the HTTP POST method necessary to invoke the /issue/key/attachments # REST endpoint because it has to use the form-data Content-Type. my $rest = $self->{rest}; # FIXME: How to attach all files at once? foreach my $file (@files) { my $response = $rest->getUseragent()->post( $rest->getHost . "/rest/api/latest/issue/$issueIdOrKey/attachments", %{$rest->{_headers}}, 'X-Atlassian-Token' => 'nocheck', 'Content-Type' => 'form-data', 'Content' => [ file => [$file, encode_utf8( $file )] ], ); $response->is_success or croak $self->_error("attach_files($file): " . $response->status_line); } return; } 1; __END__ =pod =encoding UTF-8 =head1 NAME JIRA::REST - Thin wrapper around Jira's REST API =head1 VERSION version 0.024 =head1 SYNOPSIS use JIRA::REST; my $jira = JIRA::REST->new({ url => 'https://jira.example.net', username => 'myuser', password => 'mypass', }); my $jira_with_session = JIRA::REST->new({ url => 'https://jira.example.net', username => 'myuser', password => 'mypass', session => 1, }); my $jira_with_pat = JIRA::REST->new({ url => 'https://jira.example.net', pat => 'NDc4NDkyNDg3ODE3OstHYSeYC1GnuqRacSqvUbookcZk', }); my $jira_anonymous = JIRA::REST->new({ url => 'https://jira.example.net', anonymous => 1, }); # File a bug my $issue = $jira->POST('/issue', undef, { fields => { project => { key => 'PRJ' }, issuetype => { name => 'Bug' }, summary => 'Cannot login', description => 'Bla bla bla', }, }); # Get issue $issue = $jira->GET("/issue/TST-101"); # Iterate on issues my $search = $jira->POST('/search', undef, { jql => 'project = "TST" and status = "open"', startAt => 0, maxResults => 16, fields => [ qw/summary status assignee/ ], }); foreach my $issue (@{$search->{issues}}) { print "Found issue $issue->{key}\n"; } # Iterate using utility methods $jira->set_search_iterator({ jql => 'project = "TST" and status = "open"', maxResults => 16, fields => [ qw/summary status assignee/ ], }); while (my $issue = $jira->next_issue) { print "Found issue $issue->{key}\n"; } # Attach files using an utility method $jira->attach_files('TST-123', '/path/to/doc.txt', 'image.png'); =head1 DESCRIPTION L is a proprietary bug tracking system from Atlassian. This module implements a very thin wrapper around Jira's REST APIs: =over =item * L This rich API superseded the old L which isn't supported anymore as of Jira version 7. The endpoints of this API have a path prefix of C. =item * L This API deals with the objects of the Jira Service Desk application. Its endpoints have a path prefix of C. =item * L This API deals with the objects of the Jira Software application. Its endpoints have a path prefix of C. =back =head1 CONSTRUCTORS =head2 new HASHREF =head2 new URL, USERNAME, PASSWORD, REST_CLIENT_CONFIG, PROXY, SSL_VERIFY_NONE, ANONYMOUS, PAT, SESSION The default constructor can take its arguments from a single hash reference or from a list of positional parameters. The first form is preferred because it lets you specify only the arguments you need. The second form forces you to pass undefined values if you need to pass a specific value to an argument further to the right. The arguments are described below with the names which must be used as the hash keys: =over 4 =item * B A string or a URI object denoting the base URL of the Jira server. This is a required argument. The REST methods described below all accept as a first argument the endpoint's path of the specific API method to call. In general you can pass the complete path, beginning with the prefix denoting the particular API to use (C, C, or C). However, you may specify a default API prefix by suffixing the URL with it. For example: my $jira = JIRA::REST->new({ url => 'https://jira.example.net/jira/rest/api/1', username => 'myuser', password => 'mypass' }); $jira->GET('/rest/api/1/issue/TST-1'); $jira->GET('/issue/TST-1'); With this constructor call both GET methods are the same, because the second one does not specify an API prefix. This is useful if you mainly want to use a particular API or if you want to specify a particular version of an API during construction. =item * B =item * B The username and password of a Jira user to use for authentication. If B is false and no B given, then, if either B or B isn't defined the module looks them up in either the C<.netrc> file or via L (which allows C encrypted credentials). L will look for F<~/.jira-identity> or F<~/.jira>. You can change the filename stub from C to a custom stub with the C environment variable. =item * B A JIRA::REST object uses a L object to make the REST invocations. This optional argument must be a hash reference that can be fed to the REST::Client constructor. Note that the C argument overwrites any value associated with the C key in this hash. As an extension, the hash reference also accepts one additional argument called B that is an extension to the REST::Client configuration and will be removed from the hash before passing it on to the REST::Client constructor. However, this argument is deprecated since v0.017 and you should avoid it. Use the following argument instead. =item * B To use a network proxy set this argument to the string or URI object describing the fully qualified URL (including port) to your network proxy. =item * B Sets the C and C options on the underlying L's user agent to 0, thus disabling them. This allows access to Jira servers that have self-signed certificates that don't pass L's verification methods. =item * B =item * B =item * B These three arguments are mutually exclusive, i.e., you can use at most one of them. By default, they are all undefined. The boolean B argument tells the module if you want to connect to the specified Jira with no authentication. This allows you to get some information from open or public Jira servers. If enabled, the B and B arguments are disregarded. The B argument maps to a string which should be a personal access token that can be used for authentication instead of a username and a password. This option is available since Jira version 8.14. Please refer to L for details. If enabled, the B and B arguments are disregarded. The booleal B argument tells the module if you want it to acquire a session cookie by making a C call to login to Jira. This is particularly useful when interacting with Jira Data Center, because it can use the session cookie to maintain affinity with one of the redundant servers. Upon destruction, the object makes a C call to logout from Jira. If enabled, the B and B arguments are required. =back =head2 new_session OPTIONS This alternative constructor simply invokes the default constructor with the same options, adding to them the B option. New code should use the default constructor with the B option because this constructor may be deprecated in the future. =head1 REST METHODS Jira's REST API documentation lists dozens of "resources" which can be operated via the standard HTTP requests: GET, DELETE, PUT, and POST. JIRA::REST objects implement four methods called GET, DELETE, PUT, and POST to make it easier to invoke and get results from Jira's REST endpoints. All four methods need two arguments: =over =item * RESOURCE This is the resource's 'path'. For example, in order to GET the list of all fields, you pass C, and in order to get SLA information about an issue you pass C. If you're using a method from Jira Core REST API you may omit the prefix C. For example, to GET the list of all fields you may pass just C. This argument is required. =item * QUERY Some resource methods require or admit parameters which are passed as a C appended to the resource's path. You may construct the query string and append it to the RESOURCE argument yourself, but it's easier and safer to pass the arguments in a hash. This way the query string is constructed for you and its values are properly L to avoid errors. This argument is optional for GET and DELETE. For PUT and POST it must be passed explicitly as C if not needed. =back The PUT and POST methods accept two more arguments: =over =item * VALUE This is the "entity" being PUT or POSTed. It can be any value, but usually is a hash reference. The value is encoded as a L string using the C method and sent with a Content-Type of C. It's usually easy to infer from the Jira REST API documentation which kind of value you should pass to each resource. This argument is required. =item * HEADERS This optional argument allows you to specify extra HTTP headers that should be sent with the request. Each header is specified as a key/value pair in a hash. =back All four methods return the value returned by the associated resource's method, as specified in the documentation, decoded according to its content type as follows: =over =item * application/json The majority of the API's resources return JSON values. Those are decoded using the C method of a C object. Most of the endpoints return hashes, which are returned as a Perl hash reference. =item * text/plain Those values are returned as simple strings. =back Some endpoints don't return anything. In those cases, the methods return C. The methods croak if they get any other type of values in return. In case of errors (i.e., if the underlying HTTP method return an error code different from 2xx) the methods croak with a multi-line string like this: ERROR: - So, in order to treat errors you must invoke the methods in an eval block or use any of the exception handling Perl modules, such as C and C. =head2 GET RESOURCE [, QUERY] Returns the RESOURCE as a Perl data structure. =head2 DELETE RESOURCE [, QUERY] Deletes the RESOURCE. =head2 PUT RESOURCE, QUERY, VALUE [, HEADERS] Creates RESOURCE based on VALUE. =head2 POST RESOURCE, QUERY, VALUE [, HEADERS] Updates RESOURCE based on VALUE. =head1 UTILITY METHODS This module provides a few utility methods. =head2 B Returns the L object used to interact with Jira. It may be useful when the Jira API isn't enough and you have to go deeper. =head2 B PARAMS Sets up an iterator for the search specified by the hash reference PARAMS. It must be called before calls to B. PARAMS must conform with the query parameters allowed for the C Jira REST endpoint. =head2 B This must be called after a call to B. Each call returns a reference to the next issue from the filter. When there are no more issues it returns undef. Using the set_search_iterator/next_issue utility methods you can iterate through large sets of issues without worrying about the startAt/total/offset attributes in the response from the /search REST endpoint. These methods implement the "paging" algorithm needed to work with those attributes. =head2 B ISSUE FILE... The C REST endpoint, used to attach files to issues, requires a specific content type encoding which is difficult to come up with just the C interface. This utility method offers an easier interface to attach files to issues. =head1 PERL AND JIRA COMPATIBILITY POLICY Currently L requires Perl 5.16 and is tested on Jira Data Center 8.13. We try to be compatible with the Perl native packages of the oldest L and L Linux distributions still getting maintainance updates. +-------------+-----------------------+------+ | End of Life | Distro | Perl | +-------------+-----------------------+------+ | 2023-04 | Ubuntu 18.04 (bionic) | 5.26 | | 2024-07 | CentOS 7 | 5.16 | | 2025-04 | Ubuntu 20.04 (focal) | 5.30 | | 2027-04 | Ubuntu 22.04 (jammy) | 5.34 | | 2029-05 | CentOS 8 | 5.26 | +-------------+-----------------------+------+ As you can see, we're kept behind mostly by the slow pace of CentOS (actually, RHEL) releases. As for Jira, the policy is very lax. I (the author) only test L on the Jira server installed in the company I work for, which is usually (but not always) at most one year older than the newest released version. I don't have yet an easy way to test it on different versions. =head1 SEE ALSO =over =item * C JIRA::REST uses a REST::Client object to perform the low-level interactions. =item * C This module Sub Classes JIRA::REST providing OAuth 1.0 support. =item * C This is another module implementing Jira's REST API using L. I got a message from the author saying that he doesn't intend to keep it going. =back =head1 REPOSITORY L =head1 AUTHOR Gustavo L. de M. Chaves =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2024 by CPQD . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut JIRA-REST-0.024/examples/0000775000423100042310000000000014553247333014604 5ustar gustavogustavoJIRA-REST-0.024/examples/edit_issue.pl0000755000423100042310000000557014553247333017306 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['issue|i=s', "Key of the issue to progress", {required => 1}], ['assign|a=s@', "Set of KEY[.ATTR]=VALUE assignments to perform", { required => 1 }], ['nonotify', "Supress email notification about the change."], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); my %assignments; foreach my $assign (@{$opt->assign}) { if (my ($key, $value) = ($assign =~ /(.+?)=(.+)/)) { if (my ($kkey, $attr) = ($key =~ /(.+?)\.(.+)/)) { if (!$assignments{$kkey}) { $assignments{$kkey} = {}; } $assignments{$kkey}{$attr} = $value; } else { $assignments{$key} = $value; } } else { die "Invalid assignment specification: $assign\n"; } } my $data = { fields => \%assignments }; $data->{notifyUsers} = 'false' if $opt->nonotify; $jira->PUT("/issue/@{[$opt->issue]}", undef, $data); __END__ =encoding utf8 =head1 NAME edit_issue.pl - Edit a JIRA issue =head1 SYNOPSIS edit.pl [-h] [long options...] --jiraurl STR JIRA server base URL --issue STR Key of the issue to progress --assign STR... Set of KEY[.ATTR]=VALUE assignments to perform --nonotify Supress email notification about the change. -h --help Print usage message and exit =head1 DESCRIPTION This script edits a JIRA issue, changing its fields. =head1 OPTIONS Common options are specified in the L documentation. Specific options are defined below: =over =item * B<--issue STR> Specifies the issue by its key (e.g. HD-1234). =item * B<--assign STR...> This multi-valued option specifies which fields are to be changed. Numeric, date, or string fields can be specified like this: --assign="summary=New summary" --assign="duedate=2017-01-01" Structured fields may need the name of an attribute to be assigned: --assign="assignee.name=gustavo" --assign="assignee.emailAddress=gustavo@cpqd.com.br" =item * B<--nonotify> By default JIRA sends email notifications to all parties involved in an issue when it's changed. This option supresses those notifications. However, admin or project admin permissions are required to disable the notification. =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2016-2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves Lisa Hare JIRA-REST-0.024/examples/lib/0000775000423100042310000000000014553247333015352 5ustar gustavogustavoJIRA-REST-0.024/examples/lib/JIRACLI.pm0000644000423100042310000000340114553247333016761 0ustar gustavogustavo#!/usr/bin/env perl package JIRACLI; use 5.016; use utf8; use warnings; use JIRA::REST; use IO::Interactive qw(is_interactive); use IO::Prompter; use Carp; use parent qw(Exporter); our @EXPORT_OK = qw(get_credentials); our $VERSION = '0.02'; sub get_credentials { my ($user, $pass) = @ENV{qw/jirauser jirapass/}; return ($user, $pass) if defined $user && defined $pass; unless (is_interactive()) { # We cannot prompt the user if we're not talking to a # terminal. croak "Cannot prompt user for credentials because STDIN isn't a terminal.\n"; } if (!defined $user) { $user = prompt( -prompt => "Username:", -in => \*STDIN, -out => \*STDERR, -verbatim, ); } if (! defined $pass) { $pass = prompt( -prompt => "Password:", -in => \*STDIN, -out => \*STDERR, -echo => '*', -verbatim, ); } return ($user, $pass); } 1; __END__ =encoding utf8 =head1 NAME JIRACLI - Common utilities for all JIRA CLI examples =head1 SYNOPSIS use lib $FindBin::Bin; use JIRACLI; =head1 DESCRIPTION This module contains a few functions used by most of the JIRA CLI examples =head1 FUNCTIONS =head2 get_credentials my ($user, $pass) = get_credentials(); This function will first check for user and password specified in the environment variables jirauser and jirpass. If no environment variables set will prompt interactively for entry of user and password =over =head1 COPYRIGHT Copyright 2016-2021 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves JIRA-REST-0.024/examples/transition.pl0000755000423100042310000000522014553247333017333 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use autodie; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['issue|i=s', "Key of the issue to progress", {required => 1}], ['transition-id|t=i', "ID of the transition to make", {required => 1}], ['resolution|r=s', "Resolution name to set"], ['comment|c=s', "Comment string to insert during transition"], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); my $data = { transition => { id => $opt->transition_id }, }; $data->{fields}{resolution} = { name => $opt->resolution } if $opt->resolution; $data->{update}{comment} = [{ add => { body => $opt->comment }}] if $opt->comment; $jira->POST("/issue/@{[$opt->issue]}/transitions", undef, $data); __END__ =encoding utf8 =head1 NAME transition.pl - Make a transition in a JIRA issue =head1 SYNOPSIS transition.pl [-hn] [long options...] --jiraurl STR JIRA server base URL --issue STR Key of the issue to progress --transition-id INT ID of the transition to make --resolution STR Resolution name to set --comment STR Comment string to insert during transition -n --dont Do not change anything -h --help Print usage message and exit =head1 DESCRIPTION This script makes a JIRA issue transition through its workflow. =head1 OPTIONS Common options are specified in the L documentation. Specific options are defined below: =over =item * B<--issue STR> Specifies the issue by its key (e.g. HD-1234). =item * B<--transition-id INT> Specifies the transition that should be performed by its numeric ID. You can grok it by hovering the mouse over the transition button and looking for the C part in its URL. =item * B<--resolution STR> If the transition leads to a terminal state you can specify a Resolution to be set. =item * B<--comment STR> Specifies a comment to be added to the issue during the transition. Note that the comment will not be added if the transition doesn't have a screen associated with it. =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2016-2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves Lisa Hare JIRA-REST-0.024/examples/comment_issue.pl0000755000423100042310000000441114553247333020014 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['issue|i=s', "Key of the issue to progress", {required => 1}], ['comment|c=s', "Comment body", {required => 1}], ['visibility' => 'hidden' => {'one_of' => [ ['group|g=s', "Group to restrict visibility to"], ['role|r=s', "Role to restrict visibility to"], ]}], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); my $comment = {body => $opt->comment}; if (my $type = $opt->visibility) { $comment->{visibility} = { type => $type, value => $opt->$type, } } $jira->POST("/issue/@{[$opt->issue]}/comment", undef, $comment); __END__ =encoding utf8 =head1 NAME comment_issue.pl - Comment a JIRA issue =head1 SYNOPSIS comment_issue.pl [-ghir] [long options...] --jiraurl STR JIRA server base URL -i STR --issue STR Key of the issue to progress -c STR --comment STR Comment body -g STR --group STR Group to restrict visibility to -r STR --role STR Role to restrict visibility to -h --help Print usage message and exit =head1 DESCRIPTION This script adds a comment to a JIRA issue. =head1 OPTIONS Common options are specified in the L documentation. Specific options are defined below: =over =item * B<--issue STR> Specifies the issue by its key (e.g. HD-1234). =item * B<--comment STR> The comment body. =item * B<--group STR> Use this option to restrict the comment visibility to the specified group. =item * B<--role STR> Use this option to restrict the comment visibility to the specified role. Note that the B<--group> and B<--role> options are mutually exclusive. =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2019-2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves JIRA-REST-0.024/examples/create_issue.pl0000755000423100042310000000316414553247333017621 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['project|p=s', "Project to create issue under", {required => 1}], ['summary|s=s', "Issue summary", {required => 1}], ['description|d=s', "Issue description", {required => 1}], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); my $data = { fields => { project => { key => $opt->project }, summary => $opt->summary, description => $opt->description, issuetype => { name => 'Bug' } } }; my $res = $jira->POST('/issue', undef, $data); print "Issue created ID: $res->{id}\n"; __END__ =encoding utf8 =head1 NAME create_issue.pl - Creates an issue =head1 SYNOPSIS create_issue.pl [-hn] [long options...] --jiraurl STR JIRA server base URL --project STR The project key --summary STR Issue Summary --description Issue Description -h --help Print usage message and exit =head1 DESCRIPTION This script creates an issue =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2016-2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Lisa Hare JIRA-REST-0.024/examples/download_attachment.pl0000755000423100042310000000603214553247333021162 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; # We need at least REST::Client version 280 to be able to download absolute URLs. See # https://github.com/milescrawford/cpan-rest-client/commit/3cb20d8f8c42c3433a269abbaf437ad101a97563. use REST::Client 280; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o [FILE]', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['issue=s', "Key of the issue from which to download attachments", {required => 1}], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); my $issue = $jira->GET('/issue/' . $opt->issue); # Get a reference to the attachment hashes my $attachments = $issue->{fields}{attachment}; if (my $file = shift) { if (my ($attachment) = grep {$_->{filename} eq $file} @$attachments) { # The 'content' key of the attachment hash contains the complete URL to # the attachment. But we can't use the JIRA::REST::GET method to get it # because it expects a JSON response and not an octet-stream with the # attachment contents. So, we grok the underlying REST::Client from the # JIRA::REST object and use its methods to download the attachment, # which takes advantage of the already set up authentication mechanism. my $rest_client = $jira->rest_client; $rest_client->setContentFile($file); $rest_client->request(GET => $attachment->{content}); $rest_client->setContentFile(undef); } else { die "No such attachment: $file\n"; } } else { if (my @attachments = map {$_->{filename}} @$attachments) { warn join("\n ", 'Which attachment do you want to download?', sort @attachments), "\n"; } else { warn "$opt->{issue} has no attachments\n"; } } __END__ =encoding utf8 =head1 NAME download_attachment.pl - Download an attachment from an issue =head1 SYNOPSIS download_attachment.pl [-h] [long options...] [FILE] --jiraurl STR JIRA server base URL --issue STR Key of the issue from which to download attachments -h --help Print usage message and exit =head1 DESCRIPTION This script downloads an attachment from a JIRA issue. If there is no FILE argument the script lists the names of all the issue attachments. To download a specific attachment, pass its name as the FILE argument. It is downloaded in the current directory with the same name. =head1 OPTIONS Common options are specified in the L documentation. Specific options are defined below: =over =item * B<--issue STR> Specifies the issue by its key (e.g. HD-1234). =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves JIRA-REST-0.024/examples/search.pl0000755000423100042310000000426014553247333016411 0ustar gustavogustavo#!/usr/bin/env perl # perl -Ilib examples/search.pl --jiraurl https://lharey.atlassian.net --jql "assignee = 'Lisa Hare'" use 5.016; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['jql=s', "JQL query expression", {required => 1}], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); if ($opt->help) { print $usage->text; exit 0; } my ($username, $password) = get_credentials(); # Scripts which make lots of calls to Jira should set up a session to be gentle. my $jira = JIRA::REST->new({ url => $opt->jiraurl, username => $username, password => $password, session => 1, }); $jira->set_search_iterator({ jql => $opt->jql, fields => [qw/summary issuetype status priority assignee reporter/], }); while (my $issue = $jira->next_issue) { my $fields = $issue->{fields}; print <<"EOS"; ID: $issue->{id} Summary: $fields->{summary} Type: $fields->{issuetype}{name} Status: $fields->{status}{name} Priority: $fields->{priority}{name} Reporter: $fields->{reporter}{name} EOS } __END__ =head1 NAME search.pl - Search JIRA issues by a JQL filter =head1 SYNOPSIS search.pl [-hn] [long options...] --jiraurl STR JIRA server base URL --jql STR JQL query expression -h --help Print usage message and exit =head1 DESCRIPTION This script searches JIRA issues by a JQL filter, printing their keys on STDOUT, one per line, or more information about them, depending on the options given. =head1 OPTIONS =over =item * B<--jql STR> Specifies the L used to search for issues. =item * B<--jiraurl STR> The JIRA server base url =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2016-2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves Lisa Hare JIRA-REST-0.024/examples/attach.pl0000755000423100042310000000300114553247333016400 0ustar gustavogustavo#!/usr/bin/env perl use 5.016; use utf8; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Getopt::Long::Descriptive; use JIRACLI qw/get_credentials/; my ($opt, $usage) = describe_options( '%c %o FILE ...', ['jiraurl=s', "JIRA server base URL", {required => 1}], ['issue=s', "Key of the issue to attach to", {required => 1}], ['help|h', "Print usage message and exit"], {show_defaults => 1}, ); unless (@ARGV) { $usage->die({pre_text => "Missing FILE arguments.\n\n"}); } if ($opt->help) { print $usage->text; exit 0; } my $jira = JIRA::REST->new( $opt->jiraurl, get_credentials(), ); $jira->attach_files($opt->issue, @ARGV); __END__ =encoding utf8 =head1 NAME attachment.pl - Attach files to an issue =head1 SYNOPSIS attach.pl [-ghir] [long options...] FILE ... --jiraurl STR JIRA server base URL --issue STR Key of the issue to progress -h --help Print usage message and exit =head1 DESCRIPTION This script attaches one of more files to a JIRA issue. The files are passed as arguments. =head1 OPTIONS Common options are specified in the L documentation. Specific options are defined below: =over =item * B<--issue STR> Specifies the issue by its key (e.g. HD-1234). =back =head1 ENVIRONMENT See the L documentation. =head1 COPYRIGHT Copyright 2022 CPQD. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Gustavo Chaves JIRA-REST-0.024/Changes0000644000423100042310000001630414553247333014263 0ustar gustavogustavoRevision history for perl module JIRA-REST. -*- text -*- 0.024 2024-01-21 14:05:30-03:00 America/Sao_Paulo [Enhancement] - JIRA::REST gives up on trying to decode the error messages returned by Jira. They are inconsistent and undocumented, as far as I know. From now on, we simply show the JSON object containing the error message. - Don't croak anymore on the PUT and POST methods when the third argument (value) is undefined. There are API endpoints for which this makes sense. 0.023 2022-04-10 20:54:14-03:00 America/Sao_Paulo [New features] - Implement the new JIRA::REST::rest_client auxiliary method to make it OK to get to the underlying REST::Client object. [Documentation] - Implement two new example scripts showing how to deal with attachments. The download_attachment.pl script uses the new J::R::rest_client method. - Update the Perl and Jira Compatibility Policy section. 0.022 2021-12-19 16:22:52-03:00 America/Sao_Paulo [Deprecation] - The new_session constructor is deprecated. New code should use the 'session' argument to the default constructor. [New features] - Martin Sluka kindly added support for Personal Access Tokens so that it's now possible to authenticate without usernames and passwords. This requires at least Jira 8.14. - Add the 'session' argument to the constructor. [Enhancement] - Martin Sluka also kindly contributed code to make JIRA::REST do not send Authorization HTTP headers if we've set up a session. This lessens the burden to Jira, which may be significant for scripts making lots of calls. - The example scripts were refactored to be modernized. 0.021 2021-02-05 22:14:44-03:00 America/Sao_Paulo [Deprecation] - Since CentOS 6 reached EOL on December/2020, following our policy we're dropping support for it and, consequently, for Perl 5.10. Now Jira::REST requires Perl 5.16, which ships with CentOS 7, which will reach EOL on July, 2024. [Enhancement] - Now the constructor sets up a cookie jar on the LWP::UserAgent object inside, so that it can keep and use the session cookies it gets from the server, making it possible to establish and keep user sessions. This is particularly useful when interacting with Jira Data Center instances. [New feature] - A new constructor called 'new_session' is implemented. It accepts the same options as the default constructor 'new', invokes it and then creates a user session, which is destroyed during destruction of the JIRA::REST object. 0.020 2019-11-02 23:13:42-03:00 America/Sao_Paulo [Documentation] - Some fixes, a new reference to JIRA::REST::OAuth, a new example script showing how to add a comment. 0.019 2018-07-28 18:00:17-03:00 America/Sao_Paulo [Changes] - JIRA::REST now requires at least Perl 5.10. Previously it required Perl 5.8. A new section in the documentation explains our Perl and Jira compatibility Policy. [Fixes] - William Carr fixed the sub_error routine teaching it yet another way Jira can pass error messages back. [Documentation] - Lisa Hare graciously contributed some example scripts which can be found on the 'examples' directory. - All mentions of 'JIRA' were changed to 'Jira', following the change Atlassian made in all of its site and documentation. 0.018 2017-05-30 09:38:37-03:00 America/Sao_Paulo [Fixes] - Strip trailing slashes from JIRA's URL to avoid 404 errors. - Make sure UTF-8-encoded filenames are preserved when attached to JIRA. - Correct the github-repository-uri in the metadata. 0.017 2017-01-06 15:47:28-02:00 America/Sao_Paulo [Fixes] - Fix attach_file() method which was broken on v0.016. 0.016 2016-12-26 22:48:03-02:00 America/Sao_Paulo (TRIAL RELEASE) [New features] - Add support for all JIRA REST API's: JIRA Core, JIRA ServiceDesk, and JIRA Software. - Add a new-style of parameter passing for the constructor, via a hash reference. - Add support for anonymous REST interaction with JIRA. - Add support for a new REST::Client configration extension to turn off SSL verification. [Fix] - Add missing META.json file to the distribution. [Enhancement] - Add a few tests against jira.atlassian.com that can be performed anonymously during release. [Deprecation] - The 'proxy' key to the REST::Client hash is deprecated in favor of the new homonymous constructor parameter. 0.015 2016-12-02 14:08:34-02:00 America/Sao_Paulo [Fix] - [RT#119092] v0.014 introduced an error making the constructor reject URLs ending in slash. 0.014 2016-11-23 07:27:52-02:00 America/Sao_Paulo [New feature] - JIRA::REST now supports the JIRA Software REST API and the JIRA Service Desk REST API in addition to the JIRA Core REST API with a minimal change. How cool is that!? Many thanks Evan Brown for such a nice idea. [Changes] - Downgrade Perl version requirement from 5.10 to 5.8.8 to enable use on older Perls. 0.013 2016-11-22 16:01:45-02:00 America/Sao_Paulo [New feature] - Add support for getting username and password from Config::Identity, which supports gpg encrypted credentials. 0.012 2016-01-15 22:16:02-02:00 America/Sao_Paulo [Fix] - Remove dependency on Data::Util. 0.011 2015-05-21 19:10:57-03:00 America/Sao_Paulo [New feature] - Add support for connecting to JIRA via a HTTP proxy. [Fix] - Recognize and output JIRA errors produced in XML format. 0.010 2014-11-08 12:54:50 America/Sao_Paulo [New features] - Add utility method 'attach_files'. [Changes] - Prints any textual error message, not just of types text/plain and text/html. 0.009 2014-09-09 20:32:15 America/Sao_Paulo [Fixes] - Fix the set_search_iterator/next_issue pair of methods. [Changes] - The iterators now use JIRA's own default (which is 50) when the 'maxResults' argument isn't set. Previously our default was set to 256. 0.008 2014-09-06 19:14:06 America/Sao_Paulo [Changes] - Show every detail in JIRA error messages. Some of which weren't being shown before. (Thanks to Michael Kröll for the tip.) 0.006 2014-08-16 20:50:07 America/Sao_Paulo [Changes] - Suppress script line numbers from error messages. - Released on #cpanday. 0.005 2014-08-07 20:25:14 America/Sao_Paulo [Changes] - New utility methods 'set_search_iterator' and 'next_issue' make it easier to iterate through large sets of issues without having to deal with "pagination". - Error messages are not presented in a consistent format. JIRA errors are parsed and presented in a legible way. 0.004 2013-12-14 14:54:06 America/Sao_Paulo [Fixes] - [RT-91368] Some resource responses contain no content but specify a Content-Type. Those were being considered errors. Now they simply return undef. - When a resource response contains a content but doesn't specify a Content-Type it's an error. Previously it was returning undef. 0.003 2013-09-03 17:32:02 America/Sao_Paulo [Fixes] - Fix code in documentation. 0.002 2013-05-31 14:50:44 America/Sao_Paulo [Fixes] - Fix URL mangling in new. 0.001 2013-05-31 08:52:14 America/Sao_Paulo JIRA-REST-0.024/MANIFEST0000644000423100042310000000073014553247333014115 0ustar gustavogustavo# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.029. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README.md dist.ini examples/attach.pl examples/comment_issue.pl examples/create_issue.pl examples/download_attachment.pl examples/edit_issue.pl examples/lib/JIRACLI.pm examples/search.pl examples/transition.pl lib/JIRA/REST.pm t/00-load.t t/01-atlassian.t t/author-pod-coverage.t t/author-pod-syntax.t t/release-kwalitee.t tidyall.ini JIRA-REST-0.024/META.yml0000644000423100042310000000201014553247333014226 0ustar gustavogustavo--- abstract: "Thin wrapper around Jira's REST API" author: - 'Gustavo L. de M. Chaves ' build_requires: Test::More: '0' lib: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.029, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: JIRA-REST recommends: HTTP::Status: '0' Net::Netrc: '0' requires: Carp: '0' Config::Identity: '0.0019' Encode: '0' HTML::TreeBuilder: '0' HTTP::CookieJar::LWP: '0' HTTP::Status: '0' JSON: '2.23' MIME::Base64: '0' Net::Netrc: '0' REST::Client: '0' URI: '0' URI::Escape: '0' perl: '5.016' utf8: '0' warnings: '0' resources: homepage: https://metacpan.org/module/JIRA::REST repository: https://github.com/gnustavo/JIRA-REST.git version: '0.024' x_generated_by_perl: v5.34.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' JIRA-REST-0.024/README.md0000644000423100042310000000257114553247333014250 0ustar gustavogustavo# JIRA::REST A thin wrapper around Jira's REST APIs ## What's this about? [Jira](http://www.atlassian.com/software/jira) is a proprietary bug tracking system from [Atlassian](http://www.atlassian.com/software/jira/). This module implements a thin wrapper around Jira's REST APIs: - [Jira Core REST API](https://docs.atlassian.com/jira/REST/server/) This rich API superseded the old [Jira SOAP API](http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html) which isn't supported anymore as of Jira version 7. - [Jira Service Desk REST API](https://docs.atlassian.com/jira-servicedesk/REST/server/) This API deals with the objects of the Jira Service Desk application. - [Jira Software REST API](https://docs.atlassian.com/jira-software/REST/server/) This API deals with the objects of the Jira Software application. ## Getting Help In order to ask questions or to report problems, please, [file an issue at GitHub](https://github.com/gnustavo/JIRA-REST/issues). ## Copyright & License JIRA::REST is copyright (c) 2013-2021 of [CPQD](http://www.cpqd.com.br/). This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. About the only thing you can't do is pretend that you wrote code that you didn't. ## Enjoy! Gustavo Chaves JIRA-REST-0.024/tidyall.ini0000644000423100042310000000031014553247333015121 0ustar gustavogustavo[PerlCritic] select = lib/**/*.pm argv = --verbose 10 [PodChecker] select = lib/**/*.pm, TODO.pod [PodSpell] select = lib/**/*.pm, TODO.pod ispell_argv = -p .ispell_english -d american suggest = 1 JIRA-REST-0.024/META.json0000644000423100042310000000375214553247333014414 0ustar gustavogustavo{ "abstract" : "Thin wrapper around Jira's REST API", "author" : [ "Gustavo L. de M. Chaves " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.029, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "JIRA-REST", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Kwalitee" : "1.21", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "recommends" : { "HTTP::Status" : "0", "Net::Netrc" : "0" }, "requires" : { "Carp" : "0", "Config::Identity" : "0.0019", "Encode" : "0", "HTML::TreeBuilder" : "0", "HTTP::CookieJar::LWP" : "0", "HTTP::Status" : "0", "JSON" : "2.23", "MIME::Base64" : "0", "Net::Netrc" : "0", "REST::Client" : "0", "URI" : "0", "URI::Escape" : "0", "perl" : "5.016", "utf8" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0", "lib" : "0" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://metacpan.org/module/JIRA::REST", "repository" : { "type" : "git", "url" : "https://github.com/gnustavo/JIRA-REST.git", "web" : "https://github.com/gnustavo/jira-rest" } }, "version" : "0.024", "x_generated_by_perl" : "v5.34.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.32", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" }