Skip to content

Commit

Permalink
new modules to optmize
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Nov 29, 2024
1 parent 8e7de8a commit bbbe48b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
37 changes: 37 additions & 0 deletions lib/Sentra/Utils/Repositories_List.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Sentra::Utils::Repositories_List {
use strict;
use warnings;
use JSON;
use Sentra::Utils::UserAgent;

sub new {
my ($self, $org, $token) = @_;

my @repos;
my $page = 1;
my $userAgent = Sentra::Utils::UserAgent -> new($token);

while (1) {
my $url = "https://api.github.com/orgs/$org/repos?per_page=100&page=$page";
my $response = $userAgent -> get($url);

if ($response -> code() == 200) {
my $data = decode_json($response -> content());

if (scalar(@$data) == 0) {
last;
}

for my $repo (@$data) {
push @repos, "$org/$repo->{name}" unless $repo->{archived};
}

$page++;
}
}

return @repos;
}
}

1;
20 changes: 14 additions & 6 deletions lib/Sentra/Utils/UserAgent.pm
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package Sentra::Utils::UserAgent {
use strict;
use warnings;
use Mojo::UserAgent;
use LWP::UserAgent;

sub new {
my $userAgent = Mojo::UserAgent -> new();
my ($self, $token) = @_;

my $userAgent = LWP::UserAgent -> new(
timeout => 5,
ssl_opts => {
verify_hostname => 0,
SSL_verify_mode => 0
},
agent => "Sentra 0.0.3"
);

my $headers = {
$userAgent -> default_headers -> header (
'X-GitHub-Api-Version' => '2022-11-28',
'Accept' => 'application/vnd.github+json',
'User-Agent' => 'Sentra 0.0.3',
'Authorization' => "Bearer $token"
};
);

return "";
return $userAgent;
}
}

Expand Down

0 comments on commit bbbe48b

Please sign in to comment.