| 1 | 2 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Dist::Zilla::Plugin::SVK::Commit; | ||
| 6 | # ABSTRACT: commit dirty files | ||
| 7 | |||
| 8 | 2 | ▶ | use File::Temp qw{ tempfile }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 0 | ▶ | use SVK; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use SVK::XD; | ||
| 11 | use Moose; | ||
| 12 | use MooseX::Has::Sugar; | ||
| 13 | use MooseX::Types::Moose qw{ Str }; | ||
| 14 | |||
| 15 | use String::Formatter method_stringf => { | ||
| 16 | -as => '_format_string', | ||
| 17 | codes => { | ||
| 18 | c => sub { $_[0]->_get_changes }, | ||
| 19 | d => sub { require DateTime; | ||
| 20 | DateTime->now->format_cldr($_[1] || 'dd-MMM-yyyy') }, | ||
| 21 | n => sub { "\n" }, | ||
| 22 | N => sub { $_[0]->zilla->name }, | ||
| 23 | v => sub { $_[0]->zilla->version }, | ||
| 24 | }, | ||
| 25 | }; | ||
| 26 | |||
| 27 | with 'Dist::Zilla::Role::AfterRelease'; | ||
| 28 | with 'Dist::Zilla::Role::SVK::DirtyFiles'; | ||
| 29 | |||
| 30 | |||
| 31 | # -- attributes | ||
| 32 | |||
| 33 | has commit_msg => ( ro, isa=>Str, default => 'v%v%n%n%c' ); | ||
| 34 | |||
| 35 | |||
| 36 | # -- public methods | ||
| 37 | |||
| 38 | sub after_release { | ||
| 39 | my $self = shift; | ||
| 40 | |||
| 41 | # check if there are dirty files that need to be committed. | ||
| 42 | # at this time, we know that only those 2 files may remain modified, | ||
| 43 | # otherwise before_release would have failed, ending the release | ||
| 44 | # process. | ||
| 45 | my @output = sort { lc $a cmp lc $b } $self->list_dirty_files(1); | ||
| 46 | return unless @output; | ||
| 47 | |||
| 48 | # write commit message in a temp file | ||
| 49 | my ($fh, $filename) = tempfile( 'DZP-svk.XXXX', UNLINK => 1 ); | ||
| 50 | print $fh $self->get_commit_message; | ||
| 51 | close $fh; | ||
| 52 | |||
| 53 | # commit the files in svk | ||
| 54 | system( "svk add @output" ); | ||
| 55 | $self->log_debug($_) for qx "svk commit -F $filename"; | ||
| 56 | $self->log("Committed @output"); | ||
| 57 | unlink $filename; | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | sub get_commit_message { | ||
| 63 | my $self = shift; | ||
| 64 | |||
| 65 | return _format_string($self->commit_msg, $self); | ||
| 66 | } # end get_commit_message | ||
| 67 | |||
| 68 | # -- private methods | ||
| 69 | |||
| 70 | sub _get_changes { | ||
| 71 | my $self = shift; | ||
| 72 | |||
| 73 | # parse changelog to find commit message | ||
| 74 | my $changelog = Dist::Zilla::File::OnDisk->new( { name => $self->changelog } ); | ||
| 75 | my $newver = $self->zilla->version; | ||
| 76 | my @content = | ||
| 77 | grep { /^$newver(?:\s+|$)/ ... /^\S/ } # from newver to un-indented | ||
| 78 | split /\n/, $changelog->content; | ||
| 79 | shift @content; # drop the version line | ||
| 80 | # drop unindented last line and trailing blank lines | ||
| 81 | pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); | ||
| 82 | |||
| 83 | # return commit message | ||
| 84 | return join("\n", @content, ''); # add a final \n | ||
| 85 | } # end _get_changes | ||
| 86 | |||
| 87 | |||
| 88 | 1; | ||
| 89 | |||
| 90 | |||
| 91 | =pod | ||
| 92 | |||
| 93 | =head1 NAME | ||
| 94 | |||
| 95 | Dist::Zilla::Plugin::SVK::Commit - commit dirty files | ||
| 96 | |||
| 97 | =head1 VERSION | ||
| 98 | |||
| 99 | version 0.10 | ||
| 100 | |||
| 101 | =head1 SYNOPSIS | ||
| 102 | |||
| 103 | In your F<dist.ini>: | ||
| 104 | |||
| 105 | [SVK::Commit] | ||
| 106 | changelog = Changes ; this is the default | ||
| 107 | |||
| 108 | =head1 DESCRIPTION | ||
| 109 | |||
| 110 | Once the release is done, this plugin will record this fact in svk by | ||
| 111 | committing changelog and F<dist.ini>. The commit message will be taken | ||
| 112 | from the changelog for this release. It will include lines between | ||
| 113 | the current version and timestamp and the next non-indented line. | ||
| 114 | |||
| 115 | The plugin accepts the following options: | ||
| 116 | |||
| 117 | =over 4 | ||
| 118 | |||
| 119 | =item * changelog - the name of your changelog file. defaults to F<Changes>. | ||
| 120 | |||
| 121 | =item * allow_dirty - a file that will be checked in if it is locally | ||
| 122 | modified. This option may appear multiple times. The default | ||
| 123 | list is F<dist.ini> and the changelog file given by C<changelog>. | ||
| 124 | |||
| 125 | =item * commit_msg - the commit message to use. defaults to | ||
| 126 | C<v%v%n%n%c>, meaning the version number and the list of changes. | ||
| 127 | |||
| 128 | =back | ||
| 129 | |||
| 130 | You can use the following codes in commit_msg: | ||
| 131 | |||
| 132 | =over 4 | ||
| 133 | |||
| 134 | =item C<%c> | ||
| 135 | |||
| 136 | The list of changes in the just-released version (read from C<changelog>). | ||
| 137 | |||
| 138 | =item C<%{dd-MMM-yyyy}d> | ||
| 139 | |||
| 140 | The current date. You can use any CLDR format supported by | ||
| 141 | L<DateTime>. A bare C<%d> means C<%{dd-MMM-yyyy}d>. | ||
| 142 | |||
| 143 | =item C<%n> | ||
| 144 | |||
| 145 | a newline | ||
| 146 | |||
| 147 | =item C<%N> | ||
| 148 | |||
| 149 | the distribution name | ||
| 150 | |||
| 151 | =item C<%v> | ||
| 152 | |||
| 153 | the distribution version | ||
| 154 | |||
| 155 | =back | ||
| 156 | |||
| 157 | =head1 METHODS | ||
| 158 | |||
| 159 | =head2 get_commit_message | ||
| 160 | |||
| 161 | This method returns the commit message. The default implementation | ||
| 162 | reads the Changes file to get the list of changes in the just-released version. | ||
| 163 | |||
| 164 | =for Pod::Coverage after_release | ||
| 165 | |||
| 166 | =head1 AUTHOR | ||
| 167 | |||
| 168 | Dr Bean <drbean at (a) cpan dot (.) org> | ||
| 169 | |||
| 170 | =head1 COPYRIGHT AND LICENSE | ||
| 171 | |||
| 172 | This software is copyright (c) 2010 by Dr Bean. | ||
| 173 | |||
| 174 | This is free software; you can redistribute it and/or modify it under | ||
| 175 | the same terms as the Perl 5 programming language system itself. | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | |||
| 180 | __END__ | ||