Skip to content

Commit

Permalink
Support custom date-time formats in Changes file
Browse files Browse the repository at this point in the history
New key release.changes_datetime_format is a strftime(3) format to
use when filling in the `{{$NEXT}}` marker.

Fixes tokuhirom#261.
  • Loading branch information
Chris White committed May 8, 2019
1 parent 81a80aa commit 8cd42b2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for Perl extension Minilla

{{$NEXT}}
- Support custom date-time formats in the Changes file (#261)

v3.1.4 2018-12-30T05:46:15Z
- Support travis-ci.com badge (#253)
Expand Down
8 changes: 7 additions & 1 deletion lib/Minilla/Release/RewriteChanges.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ sub run {
my ($self, $project, $opts) = @_;
return if $opts->{dry_run};

# NOTE: Duplicates Minilla::WorkDir::_rewrite_changes()
my $strftime_format =
($project->config->{release} &&
$project->config->{release}->{changes_datetime_format}) ||
'%Y-%m-%dT%H:%M:%SZ';

my $content = slurp_raw('Changes');
$content =~ s!\{\{\$NEXT\}\}!
"{{\$NEXT}}\n\n" . $project->version . " " . $project->work_dir->changes_time->strftime('%Y-%m-%dT%H:%M:%SZ')
"{{\$NEXT}}\n\n" . $project->version . " " . $project->work_dir->changes_time->strftime($strftime_format)
!e;
spew_raw('Changes' => $content);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Minilla/WorkDir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ sub build {
sub _rewrite_changes {
my $self = shift;

# NOTE: Duplicates Minilla::Release::RewriteChanges::run()
my $strftime_format =
($self->project->config->{release} &&
$self->project->config->{release}->{changes_datetime_format}) ||
'%Y-%m-%dT%H:%M:%SZ';

my $orig = slurp_raw('Changes');
$orig =~ s!\{\{\$NEXT\}\}!
$self->project->version . ' ' . $self->changes_time->strftime('%Y-%m-%dT%H:%M:%SZ')
$self->project->version . ' ' . $self->changes_time->strftime($strftime_format)
!e;
spew_raw('Changes', $orig);
}
Expand Down
43 changes: 43 additions & 0 deletions t/release_test/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,49 @@ MinimumVersion = false
};
};

subtest 'release.changes_datetime_format' => sub {

my $datetime_regex = qr/^(?:\S+\h+)?not a datetime/m;

subtest 'custom format' => sub {
my $guard = pushd(tempdir(CLEANUP => 1));

my $project = create_project();

spew('minil.toml', <<'...');
name = "Acme-Foo"
[release]
changes_datetime_format = "not a datetime"
...

my $workdir = $project->work_dir();
$workdir->build;

{
my $guard = pushd($workdir->dir);
ok -f 'Changes', 'Exists Changes';
like slurp('Changes'), $datetime_regex, 'Custom format is used';
}
};

subtest 'normal case' => sub {
my $guard = pushd(tempdir(CLEANUP => 1));

my $project = create_project();

write_minil_toml('Acme-Foo');

my $workdir = $project->work_dir();
$workdir->build;

{
my $guard = pushd($workdir->dir);
ok -f 'Changes', 'Exists Changes';
unlike slurp('Changes'), $datetime_regex, 'Custom format not used';
}
};
};

done_testing;

sub create_project {
Expand Down

0 comments on commit 8cd42b2

Please sign in to comment.