1 package System::Introspector::Report::Builder::Repositories::Git::Locations;
4 extends 'System::Introspector::Report::Builder';
6 has collect_matching => (is => 'ro', default => sub { [] });
7 has _locations_by_origin => (is => 'lazy', default => sub { {} });
17 my ($self, $origin) = @_;
18 my @match_rx = @{ $self->collect_matching };
19 for my $rx (@match_rx) {
20 if ($origin =~ qr{^$rx$}i) {
29 $string =~ s{^\s*}{}g;
30 $string =~ s{\s*$}{}g;
34 my $_format_commit = sub {
36 my @lines = @{ $current->{commit} || [] };
39 (my $commit = shift @lines) =~ s{^commit\s+}{}i;
41 HEADER: while (my $line = shift @lines) {
42 if ($line =~ m{^([^:]+):\s*(.+)$}) {
45 elsif ($line =~ m{^\s*$}) {
49 return 'Unable to parse message headers';
53 while (my $line = shift @lines) {
60 sprintf('by %s', $header{Author} || ''),
61 sprintf('at %s', $header{CommitDate} || ''),
66 my $_commit_count = sub {
68 my $branch = $data->{current}{branch};
70 unless defined $branch;
71 if (my $cnt = $data->{tracked}{branches}{$branch}{local_commit_count}) {
73 if defined($cnt) and not(ref $cnt);
75 if (my $cnt = $data->{current}{origin}{local_commit_count}) {
77 if defined($cnt) and not(ref $cnt);
83 my ($self, $remote, $data) = @_;
84 my $git = $data->{'repositories/git'}{git} || {};
85 for my $location (keys %$git) {
86 my $origin = $git->{$location}{config}{contents}{'remote.origin.url'}
88 my $matched = $self->_match_origin($origin)
90 my $current = $git->{$location}{current} || {};
91 push @{$self->_locations_by_origin->{$matched}}, {
93 hostname => $data->{host}{hostname},
94 location => $location,
96 local_count => $git->{$location}->$_commit_count,
97 branch => $current->{branch},
98 last_commit => $current->$_format_commit,
107 { key => 'remote', label => 'Remote Host' },
108 { key => 'hostname', label => 'Hostname' },
109 { key => 'location', label => 'Location' },
110 { key => 'branch', label => 'Branch' },
111 { key => 'local_count', label => 'Changes' },
112 { key => 'last_commit', label => 'Last Commit' },
114 my $collected = $self->_locations_by_origin;
117 my $rows = $collected->{$identifier};
119 columns => [@columns],
120 title => "$identifier Checkouts",
121 id => ['repositories-git-locations', $identifier],
122 rowid => [qw( remote location )],
123 meta => { repository => $identifier },
126 ($a->{remote} cmp $b->{remote})
128 ($a->{location} cmp $b->{location})