Skip to content

Commit

Permalink
better code composition
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Nov 28, 2024
1 parent ca1e3af commit 9c27e5e
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions lib/Sentra/Engine/Maintained.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down

0 comments on commit 9c27e5e

Please sign in to comment.