From 8315d677306b9ca2af0f5ca5cc255ecd3b8bcc66 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 14 Feb 2025 14:47:40 -0300 Subject: [PATCH] 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 --- cpanfile | 1 - misc/devel/auto_rebase.pl | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cpanfile b/cpanfile index 1614a392cd5..31f4d8bf1fd 100644 --- a/cpanfile +++ b/cpanfile @@ -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'; diff --git a/misc/devel/auto_rebase.pl b/misc/devel/auto_rebase.pl index 80c92f5c9ee..e9707361173 100755 --- a/misc/devel/auto_rebase.pl +++ b/misc/devel/auto_rebase.pl @@ -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 . + 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" ); + + if ( !$response->is_success ) { + say RED sprintf "Request to Bugzilla returned an error: %s", $response->status_line; + exit 2; + } - $client->GET("/bug/$bug_number/attachment?include_fields=is_patch,is_obsolete,creation_time,summary"); - my $response = decode_json( $client->responseContent ); + 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} ); -- 2.48.1