Initial commit
[kohakudos:koha-kudos.git] / kudos.pl
1 #!/usr/bin/perl
2
3 use Git::Wrapper;
4 use Modern::Perl;
5 use JSON;
6
7 my $git = Git::Wrapper->new('/home/chrisc/git/koha');
8 $git->fetch;
9 $git->checkout("origin/master");
10
11 my %authors;
12
13 my %orgs;
14 while ( my $line = <STDIN> ) {
15     chomp $line;
16     my @row = split( /,/, $line );
17     $orgs{ $row[0] } = $row[1];
18 }
19
20 my @log_objects = $git->log( { 'use-mailmap' => 1 }, "v3.18.00..HEAD" );
21 foreach my $log (@log_objects) {
22     if ( !$authors{ $log->author } ) {
23         my $authhash = { 'count' => 1, 'signoffs' => 0 };
24         $authors{ $log->author } = $authhash;
25     }
26     else {
27         $authors{ $log->author }->{'count'}++;
28     }
29     foreach ( $log->message =~ /Signed-off-by: (.*)/ ) {
30         if ( !$authors{$1} ) {
31             my $authhash = { 'count' => 0, 'signoffs' => 1 };
32             $authors{$1} = $authhash;
33         }
34         else {
35             $authors{$1}->{'signoffs'}++;
36         }
37
38     }
39 }
40
41 my %orgcounts;
42
43 foreach my $author ( keys %authors ) {
44     my $match = 0;
45
46     #    print "$author:\t" . $authors{$author}->{'count'} . "\n";
47     foreach my $org ( keys %orgs ) {
48         if ( $author =~ /$org/ ) {
49             if ( !$orgcounts{ $orgs{$org} } ) {
50                 my $orghash = {
51                     'count'    => $authors{$author}->{'count'},
52                     'signoffs' => $authors{$author}->{'signoffs'}
53                 };
54
55                 $orgcounts{ $orgs{$org} } = $orghash;
56             }
57             else {
58                 $orgcounts{ $orgs{$org} }->{'count'} +=
59                   $authors{$author}->{'count'};
60                 $orgcounts{ $orgs{$org} }->{'signoffs'} +=
61                   $authors{$author}->{'signoffs'};
62             }
63             $match = 1;
64             last;
65         }
66     }
67     unless ($match) {
68         warn "no match $author\n";
69         if ( !$orgcounts{$author} ) {
70             my $orghash = {
71                 'count'    => $authors{$author}->{'count'},
72                 'signoffs' => $authors{$author}->{'signoffs'}
73             };
74             $orgcounts{$author} = $orghash;
75         }
76         else {
77             $orgcounts{$author}->{'count'} +=
78               $authors{$author}->{'count'};
79             $orgcounts{$author}->{'signoffs'} +=
80               $authors{$author}->{'signoffs'};
81
82         }
83
84     }
85
86 }
87 my $json = JSON->new->allow_nonref;
88 $json = $json->canonical(1);
89         
90 my $json_text = $json->encode(\%orgcounts );
91 print $json_text;