From: Robert 'phaylon' Sedlacek Date: Wed, 19 Sep 2012 12:05:11 +0000 (+0000) Subject: added new commit/branch/origin information to git repository reports X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=000ae97bc64f5f47ef4f9ae4ec84c546ea0701f4;p=scpubgit%2FSystem-Introspector-Report.git added new commit/branch/origin information to git repository reports --- diff --git a/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm b/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm index feb14cf..0692611 100644 --- a/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm +++ b/lib/System/Introspector/Report/Builder/Repositories/Git/Locations.pm @@ -24,6 +24,61 @@ sub _match_origin { return undef; } +my $_trim = sub { + my ($string) = @_; + $string =~ s{^\s*}{}g; + $string =~ s{\s*$}{}g; + return $string; +}; + +my $_format_commit = sub { + my ($current) = @_; + my @lines = @{ $current->{commit} || [] }; + return undef + unless @lines; + (my $commit = shift @lines) =~ s{^commit\s+}{}i; + my %header; + HEADER: while (my $line = shift @lines) { + if ($line =~ m{^([^:]+):\s*(.+)$}) { + $header{$1} = $2; + } + elsif ($line =~ m{^\s*$}) { + last HEADER; + } + else { + return 'Unable to parse message headers'; + } + } + my $title = ''; + while (my $line = shift @lines) { + if ($line =~ m{\S}) { + $title = $line; + } + } + return join("\n", + $commit->$_trim, + sprintf('by %s', $header{Author} || ''), + sprintf('at %s', $header{CommitDate} || ''), + $title->$_trim, + ); +}; + +my $_commit_count = sub { + my ($data) = @_; + my $branch = $data->{current}{branch}; + return undef + unless defined $branch; + if (my $cnt = $data->{tracked}{branches}{$branch}{local_commit_count}) { + return $cnt + if defined($cnt) and not(ref $cnt); + } + if (my $cnt = $data->{current}{origin}{local_commit_count}) { + return $cnt + if defined($cnt) and not(ref $cnt); + } + return undef; +}; + sub collect_from { my ($self, $remote, $data) = @_; my $git = $data->{'repositories/git'}{git} || {}; @@ -32,11 +87,15 @@ sub collect_from { or next; my $matched = $self->_match_origin($origin) or next; + my $current = $git->{$location}{current} || {}; push @{$self->_locations_by_origin->{$matched}}, { - remote => $remote, - hostname => $data->{host}{hostname}, - location => $location, - origin => $origin, + remote => $remote, + hostname => $data->{host}{hostname}, + location => $location, + origin => $origin, + local_count => $git->{$location}->$_commit_count, + branch => $current->{branch}, + last_commit => $current->$_format_commit, }; } return 1; @@ -45,9 +104,12 @@ sub collect_from { sub render_reports { my ($self) = @_; my @columns = ( - { key => 'remote', label => 'Remote Host' }, - { key => 'hostname', label => 'Hostname' }, - { key => 'location', label => 'Location' }, + { key => 'remote', label => 'Remote Host' }, + { key => 'hostname', label => 'Hostname' }, + { key => 'location', label => 'Location' }, + { key => 'branch', label => 'Branch' }, + { key => 'local_count', label => 'Changes' }, + { key => 'last_commit', label => 'Last Commit' }, ); my $collected = $self->_locations_by_origin; return map {