From 7579feaf4e2c8bc226608b782be8ec7c8dbf93ce Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 13 Jul 2022 14:26:08 -0400 Subject: [PATCH] add homepage url --- CHANGELOG.yml => CHANGELOG-sample.yml | 1 + lib/App/Changelord.pm | 37 +++++++++++++++++-- .../Changelord/Command/changelog-schema.yml | 6 +++ t/basic.t | 8 ++++ 4 files changed, 48 insertions(+), 4 deletions(-) rename CHANGELOG.yml => CHANGELOG-sample.yml (97%) diff --git a/CHANGELOG.yml b/CHANGELOG-sample.yml similarity index 97% rename from CHANGELOG.yml rename to CHANGELOG-sample.yml index 6a495c1..bfdb91d 100644 --- a/CHANGELOG.yml +++ b/CHANGELOG-sample.yml @@ -1,6 +1,7 @@ # yaml-language-server: $schema=./changelog-schema.yaml project: name: App::Changeman + homepage: https://git.babyl.ca/yanick/App-Changelord type: - feat: title: Features diff --git a/lib/App/Changelord.pm b/lib/App/Changelord.pm index bf0d8a7..0c99b04 100644 --- a/lib/App/Changelord.pm +++ b/lib/App/Changelord.pm @@ -20,16 +20,45 @@ has changelog => ( } ); -sub as_markdown($self) { - my $changelog = $self->changelog; +sub render_header($self) { my $output = "# Changelog"; - $output .= " for " . $changelog->{project}{name} - if $changelog->{project}{name}; + my $name = $self->changelog->{project}{name}; + + my %links = (); + + if( $self->changelog->{project}{homepage} ) { + $name = "[$name][homepage]"; + $links{homepage} = $self->changelog->{project}{homepage}; + } + + $output .= " for $name" if $name; + + if(%links) { + $output .= "\n\n"; + $output .= $self->render_refs(%links); + } $output .= "\n\n"; +} + +sub render_refs($self,%links) { + my $output = ''; + + for my $ref ( sort keys %links ) { + $output .= " [$ref]: $links{$ref}\n" + } + + return $output . "\n"; +} + +sub as_markdown($self) { + my $changelog = $self->changelog; + + my $output = $self->render_header; + my $n = 0; $output .= join "\n", map { $self->render_release($_, $n++) } $changelog->{releases}->@*; diff --git a/lib/App/Changelord/Command/changelog-schema.yml b/lib/App/Changelord/Command/changelog-schema.yml index 1596f66..676a2ab 100644 --- a/lib/App/Changelord/Command/changelog-schema.yml +++ b/lib/App/Changelord/Command/changelog-schema.yml @@ -3,7 +3,13 @@ additionalProperties: false properties: project: type: object + additionalProperties: false properties: + homepage: + type: string + description: url of the project's homepage + examples: + - https://github.com/yanick/app-changelord name: type: string description: name of the project diff --git a/t/basic.t b/t/basic.t index 8158f74..57321fe 100644 --- a/t/basic.t +++ b/t/basic.t @@ -12,4 +12,12 @@ my $change = App::Changelord->new( like $change->as_markdown, qr/# Changelog for Foo/; +subtest 'homepage' => sub { + $change->changelog->{project}{homepage} = 'the-url'; + + my $header = $change->render_header; + like $header, qr/\[Foo\]\[homepage\]/; + like $header, qr/\Q [homepage]: the-url/; +}; + done_testing();