| 1 | package App::Changelord::Command::GitGather; | ||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||
| 3 | 2 | $App::Changelord::Command::GitGather::VERSION = '0.0.2'; | |||||||||||
| 4 | 2 | ▶ | use v5.36.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | use CLI::Osprey | ||||||||||||
| 8 | 2 | ▶ | desc => 'gather changes from git commit messages', | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | description_pod => <<'END_POD'; | |||||||||||
| 10 | Inspects the git log of the current branch for commit | ||||||||||||
| 11 | messages looking like change entries. If any are found, add them to the | ||||||||||||
| 12 | changelog. | ||||||||||||
| 13 | |||||||||||||
| 14 | =head2 Lower bound of the git log | ||||||||||||
| 15 | |||||||||||||
| 16 | C<git-gather> will inspect the git log from the most recent of those | ||||||||||||
| 17 | three points: | ||||||||||||
| 18 | |||||||||||||
| 19 | =over | ||||||||||||
| 20 | |||||||||||||
| 21 | =item The last change in the NEXT release having a C<commit> property. | ||||||||||||
| 22 | |||||||||||||
| 23 | =item The last tagged version. | ||||||||||||
| 24 | |||||||||||||
| 25 | =item The beginning of time. | ||||||||||||
| 26 | |||||||||||||
| 27 | =back | ||||||||||||
| 28 | |||||||||||||
| 29 | =head2 Change-like git message | ||||||||||||
| 30 | |||||||||||||
| 31 | Git messages are compared to the regular expression | ||||||||||||
| 32 | configured at `project.commit_regex`. If none is found, it | ||||||||||||
| 33 | defaults to | ||||||||||||
| 34 | |||||||||||||
| 35 | ^(?<type>[^: ]+):(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$ | ||||||||||||
| 36 | |||||||||||||
| 37 | The regular expression must capture a C<desc> field, and may | ||||||||||||
| 38 | capture a C<type> and C<ticket> as well. | ||||||||||||
| 39 | |||||||||||||
| 40 | END_POD | ||||||||||||
| 41 | |||||||||||||
| 42 | 2 | ▶ | use Path::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | |||||||||||||
| 44 | 2 | with 'App::Changelord::Role::Changelog'; | |||||||||||
| 45 | 2 | with 'App::Changelord::Role::Versions'; | |||||||||||
| 46 | 2 | with 'App::Changelord::Role::ChangeTypes'; | |||||||||||
| 47 | 2 | with 'App::Changelord::Role::GitRepo'; | |||||||||||
| 48 | |||||||||||||
| 49 | 2 | has commit_regex => ( | |||||||||||
| 50 | is => 'lazy' | ||||||||||||
| 51 | ); | ||||||||||||
| 52 | |||||||||||||
| 53 | 0 | ▶ | sub _build_commit_regex($self) { | ||||||||||
|
Subroutine
_build_commit_regex: not called CC=2 SCAR=17.9
| |||||||||||||
| 54 | 0 | my $regex = $self->changelog->{project}{commit_regex}; | |||||||||||
| 55 | 0 | my $default = '^(?<type>[^: ]+):(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$'; | |||||||||||
| 56 | 0 | ▶ | if(!$regex) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | warn "project.commit_regex not configured, using the default /$default/\n"; | |||||||||||
| 58 | 0 | $regex = $default; | |||||||||||
| 59 | } | ||||||||||||
| 60 | 0 | return $regex; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub lower_bound($self) { | ||||||||||
|
Subroutine
lower_bound: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 64 | # either the most recent commit in the current release | ||||||||||||
| 65 | 0 | my @sha1s = grep { $_ } map { $_->{commit} } grep { ref } $self->next_release->{changes}->@*; | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | return pop @sha1s if @sha1s; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | 0 | return $self->latest_version; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 0 | ▶ | sub get_commits($self,$since=undef) { | ||||||||||
|
Subroutine
get_commits: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 73 | 0 | ▶ | return reverse $self->repo->run( 'log', '--pretty=format:%H %s', $since ? "$since.." : () ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | sub munge_message($self,$message) { | ||||||||||
|
Subroutine
munge_message: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 77 | 0 | my $regex = $self->commit_regex; | |||||||||||
| 78 | |||||||||||||
| 79 | 0 | $message =~ s/(\S+) //; | |||||||||||
| 80 | 0 | my $commit = $1; | |||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | return () unless $message =~ qr/$regex/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | |||||||||||||
| 84 | 0 | return { %+, commit => $commit }; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | ▶ | sub save_changelog($self) { | ||||||||||
|
Subroutine
save_changelog: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 88 | 0 | my $src = $self->source; | |||||||||||
| 89 | |||||||||||||
| 90 | 0 | path($src)->spew( App::Changelord::Command::Init::serialize_changelog($self) ); | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | 0 | ▶ | sub run ($self) { | ||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 94 | |||||||||||||
| 95 | 0 | say "let's check those git logs..."; | |||||||||||
| 96 | |||||||||||||
| 97 | # figure out lower bound | ||||||||||||
| 98 | 0 | my $from = $self->lower_bound; | |||||||||||
| 99 | |||||||||||||
| 100 | 0 | ▶ | say "checking since ", ( $from || 'the dawn of time' ); | ||||||||||
|
Condition0%0/2
$from || 'the dawn of time'
MC/DC0%0/1
$from || 'the dawn of time'
$from
Truth table0%0/2
A
A= $from
| |||||||||||||
| 101 | |||||||||||||
| 102 | 0 | my @messages = map { $self->munge_message($_) } $self->get_commits($from); | |||||||||||
| 103 | |||||||||||||
| 104 | 0 | ▶ | unless(@messages) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 0 | say "\nno change detected"; | |||||||||||
| 106 | 0 | return; | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 0 | print "\n"; | |||||||||||
| 110 | 0 | say " * ", $_->{desc} for @messages; | |||||||||||
| 111 | 0 | print "\n"; | |||||||||||
| 112 | |||||||||||||
| 113 | 0 | push $self->next_release->{changes}->@*, @messages; | |||||||||||
| 114 | |||||||||||||
| 115 | 0 | $self->save_changelog; | |||||||||||
| 116 | |||||||||||||
| 117 | 0 | say $self->source, " updated"; | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | 2 | 1; | |||||||||||
| 121 | |||||||||||||
| 122 | __END__ | ||||||||||||