Permalink
Browse files

draft of CheckChangesHasContent

  • Loading branch information...
1 parent 28c2069 commit fccc9b3cb063bb3318af2fb8875ecbbcb23316c8 @xdg xdg committed May 12, 2010
Showing with 51 additions and 16 deletions.
  1. +51 −3 lib/Dist/Zilla/Plugin/CheckChangesHasContent.pm
  2. +0 −13 t/dist-zilla-plugin-checkchangeshascontent.t
View
54 lib/Dist/Zilla/Plugin/CheckChangesHasContent.pm
@@ -1,25 +1,73 @@
use strict;
use warnings;
package Dist::Zilla::Plugin::CheckChangesHasContent;
-# ABSTRACT: a module for CPAN
+# ABSTRACT: Ensure Changes has content before releasing
# Dependencies
+use Dist::Zilla 2.100950 (); # XXX really the next release after this date
use autodie 2.00;
+use File::pushd 0 ();
use Moose 0.99;
use namespace::autoclean 0.09;
# extends, roles, attributes, etc.
+with 'Dist::Zilla::Role::BeforeRelease';
+
+has changelog => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'Changes'
+);
+
# methods
+sub before_release {
+ my $self = shift;
+ my $changes_file = $self->changelog;
+ my $newver = $self->zilla->version;
+
+ $self->zilla->ensure_built_in;
+
+ # chdir in
+ my $wd = File::pushd::pushd($self->zilla->built_in);
+
+ # Must have Changes file
+ -e $changes_file or $self->log_fatal("No $changes_file found");
+
+ # Changes must have content
+ $self->_get_changes
+ or $self->log_fatal("$changes_file has no content for $newver");
+
+ return;
+}
+
+# _get_changes copied and adapted from Dist::Zilla::Plugin::Git::Commit
+# by Jerome Quelin
+sub _get_changes {
+ my $self = shift;
+
+ # parse changelog to find commit message
+ my $changelog = Dist::Zilla::File::OnDisk->new( { name => $self->changelog } );
+ my $newver = $self->zilla->version;
+ my @content =
+ grep { /^$newver\s+/ ... /^\S/ } # from newver to un-indented
+ split /\n/, $changelog->content;
+ shift @content; # drop the version line
+ # drop unindented last line and trailing blank lines
+ pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ );
+
+ # return number of non-blank lines
+ return scalar @content;
+} # end _get_changes
+
__PACKAGE__->meta->make_immutable;
1;
__END__
-=for Pod::Coverage::TrustPod
- method_name_here
+=for Pod::Coverage before_release
=begin wikidoc
View
13 t/dist-zilla-plugin-checkchangeshascontent.t
@@ -1,13 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More 0.88; END { done_testing }
-use Test::Exception 0.29;
-
-# Work around buffering that can show diags out of order
-Test::More->builder->failure_output(*STDOUT) if $ENV{HARNESS_VERBOSE};
-
-my ($obj);
-require_ok( 'Dist::Zilla::Plugin::CheckChangesHasContent' );
-$obj = new_ok( 'Dist::Zilla::Plugin::CheckChangesHasContent' ); # add \@args, if needed
-

0 comments on commit fccc9b3

Please sign in to comment.