From a17c334470136d8d48b60af36a3df283c27c92e7 Mon Sep 17 00:00:00 2001 From: Sebastian Davids Date: Sun, 21 Apr 2024 12:41:28 +0200 Subject: [PATCH 1/2] Mention authorEmail on config man page Signed-off-by: Sebastian Davids --- doc/man/config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/man/config.md b/doc/man/config.md index 7232a4b..7625caf 100644 --- a/doc/man/config.md +++ b/doc/man/config.md @@ -9,6 +9,8 @@ List of the currently set properties. `author` Change the default name of the ADR author. +`authorEmail` Change the default email of the ADR author. + `dateFormat` Change how the dates in the ADRs are represented. `docPath` Change the location where future ADRs are stored. From 0a59e0a9849c9b91076bb92d00767a2b801b66e1 Mon Sep 17 00:00:00 2001 From: Sebastian Davids Date: Sun, 21 Apr 2024 13:31:23 +0200 Subject: [PATCH 2/2] Added year field Signed-off-by: Sebastian Davids --- CHANGELOG.md | 6 ++++ doc/usage/Writing_Templates.md | 6 ++++ src/main/java/org/doble/adr/model/Record.java | 3 ++ src/test/java/org/doble/adr/RecordTest.java | 36 +++++++++++++++++++ .../template_with_REUSE_file_header.md | 5 +++ 5 files changed, 56 insertions(+) create mode 100644 src/test/resources/template_with_REUSE_file_header.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3cb40..987af1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and from version 4.0.0 this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +* Added year as template attribute (see [issue 49])(https://github.com/adoble/adr-j/issues/49). Many thanks to [Sebastian Davis](https://github.com/sdavids) for the PR. + ## [3.3.0] ### Added diff --git a/doc/usage/Writing_Templates.md b/doc/usage/Writing_Templates.md index c76b640..e825665 100644 --- a/doc/usage/Writing_Templates.md +++ b/doc/usage/Writing_Templates.md @@ -64,6 +64,12 @@ Type: field Description: The date the ADR was created +### `year` + +Type: field + +Description: The year the ADR was created + ### `author` Type: field diff --git a/src/main/java/org/doble/adr/model/Record.java b/src/main/java/org/doble/adr/model/Record.java index f08b5c5..46efd00 100644 --- a/src/main/java/org/doble/adr/model/Record.java +++ b/src/main/java/org/doble/adr/model/Record.java @@ -16,6 +16,8 @@ import org.doble.adr.TemplateProvider; public class Record { + private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy"); + private final Path docsPath; // Where the adr files are stored private final Optional template; // Using String type instead of Path as the default template is a resource. // Resources are not correctly supported by Path. @@ -135,6 +137,7 @@ public Path createPeristentRepresentation() throws ADRException { .map(line -> line.replaceAll("\\{\\{author\\}\\}", author)) .map(line -> line.replaceAll("\\{\\{author.email\\}\\}", authorEmail)) .map(line -> line.replaceAll("\\{\\{date\\}\\}", dateFormatter.format(date))) + .map(line -> line.replaceAll("\\{\\{year\\}\\}", YEAR_FORMATTER.format(date))) .filter(line -> !(line.contains("{{{link.id}}}") && linkFragments.size() == 0)) // Remove lines // which will be // blank diff --git a/src/test/java/org/doble/adr/RecordTest.java b/src/test/java/org/doble/adr/RecordTest.java index 0beadf7..af4ccf1 100644 --- a/src/test/java/org/doble/adr/RecordTest.java +++ b/src/test/java/org/doble/adr/RecordTest.java @@ -385,4 +385,40 @@ public void testRecordConstructionWithGivenAuthorAndAuthorEmail() throws Excepti assertEquals(expectedContents, actualContents); } + + @Test + @Order(12) + public void testRecordConstructionWithGivenAuthorAndAuthorEmailAndYear() throws Exception { + String expectedContents = """ + + # 69. ADR templates should support REUSE file header"""; + + // Build the record + Record record = new Record.Builder(docPath, dateFormatter) + .id(69) + .name("ADR templates should support REUSE file header") + .date(LocalDate.of(2024, 4, 12)) + .author("Andrew Doble") + .authorEmail("andrew.l.doble@gmail.com") + .template("rsrc:template_with_REUSE_file_header.md") + .build(); + + record.createPeristentRepresentation(); + + // Check if the ADR file has been created + assertTrue(Files.exists(fileSystem.getPath("/test/0069-adr-templates-should-support-reuse-file-header.md"))); + + // Read in the file + Path adrFile = fileSystem.getPath("/test/0069-adr-templates-should-support-reuse-file-header.md"); + + String actualContents; + try (Stream lines = Files.lines(adrFile)) { + actualContents = lines.collect(Collectors.joining("\n")); + } + + assertEquals(expectedContents, actualContents); + } } diff --git a/src/test/resources/template_with_REUSE_file_header.md b/src/test/resources/template_with_REUSE_file_header.md new file mode 100644 index 0000000..f0b1dc6 --- /dev/null +++ b/src/test/resources/template_with_REUSE_file_header.md @@ -0,0 +1,5 @@ + +# {{id}}. {{name}}