File Coverage

blib/lib/Dist/Zilla/Plugin/Authors.pm
Criterion Covered Total %
statement 18 37 48.6
branch n/a
condition n/a
subroutine 6 9 66.6
pod 0 2 0.0
total 24 48 50.0


line stmt bran cond sub pod time code
1             use strict;
2 1     1   88617 use warnings;
  1         3  
  1         27  
3 1     1   5 use utf8;
  1         2  
  1         26  
4 1     1   502 use Git::Wrapper;
  1         14  
  1         4  
5 1     1   436 use List::MoreUtils qw(uniq);
  1         31839  
  1         36  
6 1     1   516 use Moose;
  1         11120  
  1         7  
7 1     1   2080 with qw/Dist::Zilla::Role::FileGatherer/;
  1         451994  
  1         8  
8              
9             my $string = shift;
10             my $git = shift;
11 0     0 0   return map { s/^\s*$string\s*//; $_ }
12 0           grep { /$string/ }
13 0           $git->RUN('log', {grep => $string});
  0            
14 0           }
  0            
15              
16             my ($self, $arg) = @_;
17             my $file = Dist::Zilla::File::FromCode->new({
18             name => 'AUTHORS',
19 0     0 0   code_return_type => 'bytes',
20             code => sub {
21             my $git = Git::Wrapper->new('./');
22             my @authors = $git->RUN('log', {pretty => "format:%aN <%aE>"});
23             my @signed_authors = git_log_grep('Signed-off-by:', $git);
24 0     0     my @co_authors = git_log_grep('Co-authored-by:', $git);
25 0           foreach (@signed_authors, @co_authors) {
26 0           eval {
27 0           my @_co_authors = $git->RUN('check-mailmap', $_);
28 0           push @authors, @_co_authors;
29 0           };
30 0           }
31 0           return join("\n", uniq sort @authors);
32             },
33             });
34 0           $self->add_file($file);
35             return;
36 0           }
37 0            
38 0           1;
39              
40              
41             =pod
42            
43             =encoding UTF-8
44            
45             =head1 NAME
46            
47             Dist::Zilla::Plugin::Authors - Build AUTHORS file from Git history
48            
49             =head1 VERSION
50            
51             version 0.1.0
52              
53             =head1 SYNOPSIS
54            
55             If you want to auto-generate an AUTHORS file listing all commiters from Git
56             history you can use this Plugin like the example below.
57            
58             name = Foo-Bar
59             [@Basic]
60             [Authors]
61              
62             =head1 DESCRIPTION
63            
64             Auto generate AUTHORS file including every commiters in the format:
65              
66             Author Name <author email>
67              
68             It collects also every author name on Git commit messages containing the
69             strings below:
70              
71             Signed-off-by: Author Name <author email>
72             Co-authored-by: Author Name <author email>
73              
74             The Dist::Zilla::Plugin::Authors respects the `.mailmap` to reduce duplication
75             of authors on the generated AUTHORS file.
76              
77             =head1 AUTHOR
78            
79             Joenio Marques da Costa <joenio@joenio.me>
80            
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2022 by Joenio Marques da Costa.
84              
85             This is free software; you can redistribute it and/or modify it under the same
86             terms as the Perl 5 programming language system itself.
87            
88             =cut