From: Robert 'phaylon' Sedlacek Date: Tue, 18 Sep 2012 00:44:21 +0000 (+0000) Subject: report for git repository locations by host X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=60136b2b092ec198fd52102ddc1ad8fd73149cc3;p=scpubgit%2FSystem-Introspector-Report.git report for git repository locations by host --- diff --git a/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm b/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm new file mode 100644 index 0000000..feb14cf --- /dev/null +++ b/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm @@ -0,0 +1,73 @@ +package System::Introspector::Report::Builder::Repositories::Git::Locations; +use Moo; + +extends 'System::Introspector::Report::Builder'; + +has collect_matching => (is => 'ro', default => sub { [] }); +has _locations_by_origin => (is => 'lazy', default => sub { {} }); + +sub required_data { + return qw( + repositories/git + host + ); +} + +sub _match_origin { + my ($self, $origin) = @_; + my @match_rx = @{ $self->collect_matching }; + for my $rx (@match_rx) { + if ($origin =~ qr{^$rx$}i) { + return $1; + } + } + return undef; +} + +sub collect_from { + my ($self, $remote, $data) = @_; + my $git = $data->{'repositories/git'}{git} || {}; + for my $location (keys %$git) { + my $origin = $git->{$location}{config}{contents}{'remote.origin.url'} + or next; + my $matched = $self->_match_origin($origin) + or next; + push @{$self->_locations_by_origin->{$matched}}, { + remote => $remote, + hostname => $data->{host}{hostname}, + location => $location, + origin => $origin, + }; + } + return 1; +} + +sub render_reports { + my ($self) = @_; + my @columns = ( + { key => 'remote', label => 'Remote Host' }, + { key => 'hostname', label => 'Hostname' }, + { key => 'location', label => 'Location' }, + ); + my $collected = $self->_locations_by_origin; + return map { + my $identifier = $_; + my $rows = $collected->{$identifier}; + { + columns => [@columns], + title => "$identifier Checkouts", + id => ['repositories-git-locations', $identifier], + rowid => [qw( remote location )], + meta => { repository => $identifier }, + rows => [ + sort { + ($a->{remote} cmp $b->{remote}) + || + ($a->{location} cmp $b->{location}) + } @$rows, + ], + }; + } keys %$collected; +} + +1;