Skip to content

Commit

Permalink
trying to fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Nov 28, 2024
1 parent 0e1740f commit 4f59d70
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
16 changes: 11 additions & 5 deletions lib/Sentra/Engine/DependabotMetrics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package Sentra::Engine::DependabotMetrics {
my $headers = {
'X-GitHub-Api-Version' => '2022-11-28',
'Accept' => 'application/vnd.github+json',
'User-Agent' => 'Sentra 0.0.2',
'User-Agent' => 'Sentra 0.0.3',
'Authorization' => "Bearer $token"
};

Expand All @@ -38,26 +38,32 @@ package Sentra::Engine::DependabotMetrics {
return "Error when trying to request information from GitHub, please review the parameters provided." unless @repos;

my $total_alerts = 0;
my %severity_count = (low => 0, medium => 0, high => 0, critical => 0);

my %severity_count = (
low => 0,
medium => 0,
high => 0,
critical => 0
);

for my $repo (@repos) {
my $alert_page = 1;

while (1) {
my $alert_url = "https://api.github.com/repos/$repo/dependabot/alerts?state=open&per_page=$per_page&page=$alert_page";
my $alert_tx = $userAgent->get($alert_url => $headers);
my $alert_tx = $userAgent -> get($alert_url => $headers);
my $res = $alert_tx->result or return "Error fetching alerts for $repo: " . $alert_tx->error->{message} . "\n";

$res->is_success or return "Error fetching alerts for $repo: " . $res->message . "\n";

my $alert_data = $res->json;
my $alert_data = $res -> json;

last unless @$alert_data;

$total_alerts += scalar @$alert_data;

for my $alert (@$alert_data) {
my $severity = $alert->{security_vulnerability}{severity} || 'unknown';
my $severity = $alert -> {security_vulnerability}{severity} || 'unknown';
$severity_count{$severity}++ if exists $severity_count{$severity};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sentra/Utils/Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package Sentra::Utils::Helper {

sub new {
return "
\rSentra v0.0.2
\rSentra v0.0.3
\rCore Commands
\r==============
\r\tCommand Description
Expand Down
46 changes: 25 additions & 21 deletions sentra.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,52 @@
use 5.030;
use strict;
use warnings;
use Getopt::Long;
use Getopt::Long qw(:config no_ignore_case);
use lib './lib/';
use Sentra::Engine::DependabotMetrics;
use Sentra::Engine::SearchFiles;
use Sentra::Engine::SlackWebhook;
use Sentra::Engine::Maintained;
use Sentra::Utils::Helper;

sub main {
my ($org, $token, $webhook, $message, $maintained, $dependency);

my ($org, $token, $webhook, $message, $help, %options);
my $per_page = 100;

Check failure on line 17 in sentra.pl

View workflow job for this annotation

GitHub Actions / critic

100 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead at line 17, column 20. Unnamed numeric literals make code less maintainable.

GetOptions(
'o|org=s' => \$org,
't|token=s' => \$token,
'w|webhook=s' => \$webhook,
'm|message=s' => \$message,
'mt|maintained' => \$maintained,
'd|dependency' => \$dependency,
'p|per_page=i' => \$per_page
'h|help' => \$help,
'mt|maintained' => \$options{'maintained'},
'd|dependency' => \$options{'dependency'},
'M|metrics' => \$options{'metrics'},
);

my %actions = (
'dependabot-metrics' => ($org && $token && !$maintained && !$dependency)
? sub { Sentra::Engine::DependabotMetrics -> new($org, $token, $per_page) }
: undef,
'repository-check' => ($org && $token && ($maintained || $dependency))
? sub { Sentra::Engine::SearchFiles -> new($org, $token, $maintained, $dependency, $per_page) }
: undef,
'send-webhook' => ($webhook)
? sub { Sentra::Engine::SlackWebhook -> new($message, $webhook) }
: undef,
my %dispatch_table = (
'metrics' => sub { Sentra::Engine::DependabotMetrics->new($org, $token, $per_page) },
'dependency' => sub { Sentra::Engine::SearchFiles->new($org, $token, $per_page) },
'maintained' => sub { Sentra::Engine::Maintained->new($org, $token, $per_page) },
);

for my $action (grep { defined } values %actions) {
print $action -> ();
for my $option (keys %options) {
if ($options{$option} && exists $dispatch_table{$option}) {
print $dispatch_table{$option}->();
}
}

if ($webhook && $message) {
Sentra::Engine::SlackWebhook->new($message, $webhook)->send();
}

if ($help) {
print Sentra::Utils::Helper -> new();

return 0;
}

print Sentra::Utils::Helper -> new();

return 1;
}

Expand Down

0 comments on commit 4f59d70

Please sign in to comment.