Merge commit 'refs/merge-requests/1' of gitorious.org:kohakudos/koha-kudos into integ...
[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     my $message = $log->message;
30     while ( $message =~ /Signed-off-by: (.*?)\n/g ) {
31         if ( !$authors{$1} ) {
32             my $authhash = { 'count' => 0, 'signoffs' => 1 };
33             $authors{$1} = $authhash;
34         }
35         else {
36             $authors{$1}->{'signoffs'}++;
37         }
38
39     }
40 }
41
42 my %orgcounts;
43
44 foreach my $author ( keys %authors ) {
45     my $match = 0;
46
47     #    print "$author:\t" . $authors{$author}->{'count'} . "\n";
48     foreach my $org ( keys %orgs ) {
49         if ( $author =~ /$org/ ) {
50             if ( !$orgcounts{ $orgs{$org} } ) {
51                 my $orghash = {
52                     'count'    => $authors{$author}->{'count'},
53                     'signoffs' => $authors{$author}->{'signoffs'}
54                 };
55
56                 $orgcounts{ $orgs{$org} } = $orghash;
57             }
58             else {
59                 $orgcounts{ $orgs{$org} }->{'count'} +=
60                   $authors{$author}->{'count'};
61                 $orgcounts{ $orgs{$org} }->{'signoffs'} +=
62                   $authors{$author}->{'signoffs'};
63             }
64             $match = 1;
65             last;
66         }
67     }
68     unless ($match) {
69         warn "no match $author\n";
70         if ( !$orgcounts{$author} ) {
71             my $orghash = {
72                 'count'    => $authors{$author}->{'count'},
73                 'signoffs' => $authors{$author}->{'signoffs'}
74             };
75             $orgcounts{$author} = $orghash;
76         }
77         else {
78             $orgcounts{$author}->{'count'} +=
79               $authors{$author}->{'count'};
80             $orgcounts{$author}->{'signoffs'} +=
81               $authors{$author}->{'signoffs'};
82
83         }
84
85     }
86
87 }
88 my $json = JSON->new->allow_nonref;
89 $json = $json->canonical(1);
90         
91 my $json_text = $json->encode(\%orgcounts );
92 print $json_text;