Skip to content

Commit

Permalink
remove request to analsys endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Aug 23, 2024
1 parent c936433 commit 09f7323
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions lib/SecurityGate/Engine/Code.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package SecurityGate::Engine::Code {
use warnings;
use Mojo::UserAgent;
use Mojo::JSON;
use Data::Dumper;

sub new {
my ($class, $token, $repository, $severity_limits) = @_;

my $alerts_endpoint = "https://api.github.com/repos/$repository/code-scanning/alerts";
my $analyses_endpoint = "https://api.github.com/repos/$repository/code-scanning/analyses";

my $alerts_endpoint = "https://api.github.com/repos/$repository/code-scanning/alerts";
my $userAgent = Mojo::UserAgent -> new();
my $alerts_request = $userAgent -> get($alerts_endpoint, {Authorization => "Bearer $token"}) -> result();

Expand All @@ -19,6 +17,8 @@ package SecurityGate::Engine::Code {
my %severity_counts = map {$_ => 0} keys %$severity_limits;

foreach my $alert (@$alerts_data) {
print Dumper($alert);

if ($alert -> {state} eq "open") {
$open_alerts++;

Expand All @@ -37,7 +37,7 @@ package SecurityGate::Engine::Code {

foreach my $severity (keys %severity_counts) {
if ($severity_counts{$severity} > $severity_limits -> {$severity}) {
print "[+] More than $severity_limits -> {$severity} $severity code scanning alerts found.\n";
print "[+] More than $severity_limits->{$severity} $severity code scanning alerts found.\n";

$threshold_exceeded = 1;
}
Expand All @@ -53,21 +53,7 @@ package SecurityGate::Engine::Code {

return 1;
}

my $analyses_request = $userAgent -> get($analyses_endpoint, {Authorization => "Bearer $token"}) -> result();

if ($analyses_request -> code() == 200) {
my $analyses_data = $analyses_request -> json();

print "[!] Total of code scanning analyses found: " . scalar(@$analyses_data) . "\n";
}

else {
print "Error: Unable to fetch code scanning analyses. HTTP status code: " . $analyses_request -> code() . "\n";

return 1;
}


return 0;
}
}
Expand Down

0 comments on commit 09f7323

Please sign in to comment.