Bug 39106: Use LWP::UserAgent and add error checking

This patch replaces the (newly introduced use of) REST::Client library
with (the already existing in the dependencies) LWP::UserAgent.

Bonus 1: validation on the response status is added to print a proper
error message and die if bugzilla is not available

Bonus 2: License added to the file

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomás Cohen Arazi 2025-02-14 14:47:40 -03:00 committed by Katrin Fischer
parent e562c96d2e
commit 57f271d6b2
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 28 additions and 10 deletions

View file

@ -166,7 +166,6 @@ recommends 'Net::SFTP::Foreign', '1.73';
recommends 'Net::Server', '0.97';
recommends 'Net::Z3950::SimpleServer', '1.15';
recommends 'PDF::FromHTML', '0.31';
recommends 'REST::Client', '281';
recommends 'SMS::Send', '0.05';
recommends 'Selenium::Remote::Driver', '1.27';
recommends 'Starman', '0.4014';

View file

@ -1,5 +1,22 @@
#!/usr/bin/env perl
# This file is part of Koha.
#
# Koha 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 3 of the License, or
# (at your option) any later version.
#
# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Term::ANSIColor qw(:constants);
use Git::Wrapper;
use File::Slurp qw( write_file );
@ -7,10 +24,10 @@ use File::Temp qw( tempfile );
use File::Basename qw(dirname);
use File::Path qw(make_path);
use List::Util qw( first );
use LWP::UserAgent ();
use Getopt::Long;
use Pod::Usage;
use Try::Tiny;
use REST::Client;
use JSON qw( decode_json );
$Term::ANSIColor::AUTOLOCAL = 1;
@ -85,17 +102,19 @@ switch_branch($tmp_src_branch);
if ($bug_number) {
say BLUE sprintf "Guessing a date to use from bugzilla's bug %s", $bug_number;
my $client = REST::Client->new(
{
host => 'https://bugs.koha-community.org/bugzilla3/rest',
}
);
my $client = LWP::UserAgent->new();
my $response = $client->get( 'https://bugs.koha-community.org/bugzilla3/rest'
. "/bug/$bug_number/attachment?include_fields=is_patch,is_obsolete,creation_time,summary" );
$client->GET("/bug/$bug_number/attachment?include_fields=is_patch,is_obsolete,creation_time,summary");
my $response = decode_json( $client->responseContent );
if ( !$response->is_success ) {
say RED sprintf "Request to Bugzilla returned an error: %s", $response->status_line;
exit 2;
}
my $bz_response = decode_json( $response->decoded_content );
my $time;
foreach my $attachment ( @{ $response->{bugs}->{$bug_number} } ) {
foreach my $attachment ( @{ $bz_response->{bugs}->{$bug_number} } ) {
next if ( $attachment->{is_obsolete} );
next if ( !$attachment->{is_patch} );