From 9c27e5eba7b2aed0d357f0e5629a67e032c98ab0 Mon Sep 17 00:00:00 2001 From: htrgouvea Date: Thu, 28 Nov 2024 21:37:09 +0000 Subject: [PATCH] better code composition --- lib/Sentra/Engine/Maintained.pm | 54 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/Sentra/Engine/Maintained.pm b/lib/Sentra/Engine/Maintained.pm index d1ddffc..2e83a52 100644 --- a/lib/Sentra/Engine/Maintained.pm +++ b/lib/Sentra/Engine/Maintained.pm @@ -17,37 +17,35 @@ package Sentra::Engine::Maintained { 'X-GitHub-Api-Version' => '2022-11-28' }; - my $output = ''; - + my $output = ''; my $repo_url = "https://api.github.com/orgs/$org/repos?per_page=$per_page"; - my $repo_tx = $userAgent -> get($repo_url => $headers); - - my $res = $repo_tx -> result or return "Error fetching repositories: " . $repo_tx->error->{message} . "\n"; - $res -> is_success or return "Error fetching repositories: " . $res->message . "\n"; - - my $repos = $res->json; + my $repo_tx = $userAgent -> get($repo_url => $headers); + my $res = $repo_tx -> result(); - for my $repo (@$repos) { - next if $repo -> {archived}; - - my $full_name = "$org/$repo->{name}"; - - - my $commits_url = "https://api.github.com/repos/$full_name/commits"; - my $commits_tx = $userAgent->get($commits_url => $headers); - my $commits_res = $commits_tx->result; - - if ($commits_res && $commits_res->is_success) { - my $commits = $commits_res->json; - - if (@$commits) { - my $last_commit_date_str = $commits->[0]{commit}{committer}{date}; - my $last_commit_date = DateTime::Format::ISO8601->parse_datetime($last_commit_date_str); + if ($res -> is_success) { + my $repos = $res->json; + + for my $repo (@$repos) { + next if $repo -> {archived}; + + my $full_name = "$org/$repo->{name}"; + my $commits_url = "https://api.github.com/repos/$full_name/commits"; + my $commits_tx = $userAgent -> get($commits_url => $headers); + my $commits_res = $commits_tx -> result; + + if ($commits_res && $commits_res->is_success) { + my $commits = $commits_res->json; - $output .= "The repository https://github.com/$full_name has not been updated for more than 90 days.\n" - if DateTime -> now -> subtract(days => 90) > $last_commit_date; - } - } + if (@$commits) { + my $last_commit_date_str = $commits->[0]{commit}{committer}{date}; + my $last_commit_date = DateTime::Format::ISO8601 -> parse_datetime($last_commit_date_str); + + if (DateTime -> now -> subtract(days => 90) > $last_commit_date) { + $output .= "The repository https://github.com/$full_name has not been updated for more than 90 days.\n"; + } + } + } + } } return $output || "No issues found.";