diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-12-18 00:34:53 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-12-18 00:40:55 +0100 |
commit | b238f10d9441afe1565cf698c54b69a58bbc4a45 (patch) | |
tree | cb7e63743100b398cd0ceeeb8ba87afc4c1e09b7 | |
parent | dfadb156aaf6759ab9d06de7dfa3261c82ea9910 (diff) | |
download | App-ArchLinux-PackagerTools-b238f10d9441afe1565cf698c54b69a58bbc4a45.tar.gz App-ArchLinux-PackagerTools-b238f10d9441afe1565cf698c54b69a58bbc4a45.tar.xz |
Fetch maintainers from archweb
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | cpanfile | 1 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools.pm | 17 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/Archweb.pm | 86 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/Config.pm | 4 |
5 files changed, 104 insertions, 12 deletions
@@ -41,17 +41,17 @@ updated. The returned packages contain the name of the distribution, the name of the pacman package, and the versions of each, the pacman package (which is older) and the CPAN distribution. -### get\_maintainer +### get\_maintainers - my $maintainer = $app->get_maintainer($pkgname); + my $maintainers = $app->get_maintainers($pkgname); -Accepts a package name and returns the maintainer of the package. +Accepts a package name and returns the maintainers of the package. ### add\_maintainers my $packages = $app->get_updateable_packages($distribution_names); my $packages_with_maintainer = $app->add_maintainers($packages); - print $packages_with_maintainer->[0]->{maintainer}; + print $packages_with_maintainer->[0]->{maintainers}->[0]->{name}; Accepts a list of packages (hashes with the pkgname key) and returns a list with the maintainer key added to each package. @@ -12,6 +12,7 @@ requires 'TOML'; requires 'autodie'; requires 'perl', 'v5.24.0'; requires 'strictures'; +requires 'WWW::JSON'; requires 'version'; on configure => sub { diff --git a/lib/App/ArchLinux/PackagerTools.pm b/lib/App/ArchLinux/PackagerTools.pm index 216c54c..720f056 100644 --- a/lib/App/ArchLinux/PackagerTools.pm +++ b/lib/App/ArchLinux/PackagerTools.pm @@ -11,6 +11,7 @@ use Log::Any qw($log); use App::ArchLinux::PackagerTools::Pacman; use App::ArchLinux::PackagerTools::CPAN; use App::ArchLinux::PackagerTools::Config; +use App::ArchLinux::PackagerTools::Archweb; =encoding utf-8 @@ -41,6 +42,7 @@ method new($class: $context = {}, $deps = {}) { $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context); $deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new($context); $deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new($context); + $deps->{archweb} //= App::ArchLinux::PackagerTools::Archweb->new($context); return $class->new_no_defaults($context, $deps); } @@ -107,24 +109,23 @@ method get_updateable_packages($distribution_names) { return \@packages; } -=head3 get_maintainer +=head3 get_maintainers - my $maintainer = $app->get_maintainer($pkgname); + my $maintainers = $app->get_maintainers($pkgname); -Accepts a package name and returns the maintainer of the package. +Accepts a package name and returns the maintainers of the package. =cut -method get_maintainer($pkgname) { - # TODO fetch maintainer from archweb + cache the value. use CHI - return "bluewind\@xinu.at"; +method get_maintainers($pkgname) { + return $self->{deps}->{archweb}->get_maintainers($pkgname); } =head3 add_maintainers my $packages = $app->get_updateable_packages($distribution_names); my $packages_with_maintainer = $app->add_maintainers($packages); - print $packages_with_maintainer->[0]->{maintainer}; + print $packages_with_maintainer->[0]->{maintainers}->[0]->{name}; Accepts a list of packages (hashes with the pkgname key) and returns a list with the maintainer key added to each package. @@ -137,7 +138,7 @@ method add_maintainers($packages) { for my $package ($packages->@*) { push @packages_with_maintainer, { $package->%*, - maintainer => $self->get_maintainer($package->{pkgname}), + maintainers => $self->get_maintainers($package->{pkgname}), }; } return \@packages_with_maintainer; diff --git a/lib/App/ArchLinux/PackagerTools/Archweb.pm b/lib/App/ArchLinux/PackagerTools/Archweb.pm new file mode 100644 index 0000000..5f3bcfa --- /dev/null +++ b/lib/App/ArchLinux/PackagerTools/Archweb.pm @@ -0,0 +1,86 @@ +package App::ArchLinux::PackagerTools::Archweb; +use strictures; + +use autodie; +use Function::Parameters; +use Log::Any qw($log); +use WWW::JSON; + +use App::ArchLinux::PackagerTools::Cache; +use App::ArchLinux::PackagerTools::Config; + +=head1 NAME + +App::ArchLinux::PackagerTools::Archweb - ShortDesc + +=head1 SYNOPSIS + +use App::ArchLinux::PackagerTools::Archweb; + +# synopsis... + +=head1 DESCRIPTION + +# longer description... + +=head1 METHODS + +=head2 new + + my $archweb = App::ArchLinux::PackagerTools::Archweb->new(); + +Returns a new instance. + +=cut + +method new($class: $context, $deps = {}) { + $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context); + $deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new($context); + + my $base_url = $deps->{config}->get_config()->{archweb}->{base_url}; + $deps->{wj} //= WWW::JSON->new(base_url => $base_url); + + return $class->new_no_defaults($context, $deps); +} + +method new_no_defaults($class: $context, $deps = {}) { + return $context->{$class} if defined $context->{$class}; + + my $self = {}; + bless $self, $class; + $self->{deps} = $deps; + $context->{$class} = $self; + return $self; +} + +=head2 Public Methods + +=cut + +=head3 get_maintainers + + my $maintainers = $archweb->get_maintainers($pkgname); + print $maintainers->[0]->{name}; + +Return a list with the names of the maintainers of a package. + +=cut + +method get_maintainers($pkgname) { + my $cache_timeout = $self->{deps}->{config}->{archweb}->{cache_timeout}; + my $json = $self->{deps}->{cache}->compute("archweb-package-json-$pkgname", $cache_timeout, sub { + $log->debugf("Gettings maintainers for pkgname: %s", $pkgname); + my $res = $self->{deps}->{wj}->get("/packages/search/json", {name => $pkgname}); + my $json = $res->res; + croak $log->errorf("API returned no result for search for package %s", $pkgname) if $json->{results}->@* == 0 or !$res->success; + $log->debugf("Result is %s", $json); + return $json; + }); + my $maintainers = $json->{results}->[0]->{maintainers}; + $log->debugf("Found maintainers: %s", $maintainers); + return [map {name => $_}, $maintainers->@*]; +} + +1; + +__END__ diff --git a/lib/App/ArchLinux/PackagerTools/Config.pm b/lib/App/ArchLinux/PackagerTools/Config.pm index 8fab001..417c925 100644 --- a/lib/App/ArchLinux/PackagerTools/Config.pm +++ b/lib/App/ArchLinux/PackagerTools/Config.pm @@ -103,6 +103,10 @@ method _get_default_config() { cache => { root_dir => path(($ENV{XDG_CACHE_HOME} // $ENV{HOME}."/.cache")."/perlpkg/v1/")->stringify(), }, + archweb => { + cache_timeout => '60m', + base_url => 'https://www.archlinux.org/', + }, cpan => { cache_timeout => '60m', mirror_url => 'https://cpan.metacpan.org/', |