Skip to content

Commit

Permalink
Add configuration to pretty-print Changelog Entries and Config File (#58
Browse files Browse the repository at this point in the history
)

* Add option to pretty print changelog entries and config

* Add option to pretty print changelog entries and config

* Bump version

* [Format] Auto-formatting

---------

Co-authored-by: nnichols <[email protected]>
  • Loading branch information
nnichols and nnichols authored Mar 3, 2024
1 parent c2679bd commit a39aeb5
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .sealog/changes/1-0-0.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:minor 0
:patch 0}
:version-type :semver3
:changes {:added ["Idempotent changelog initialization via: `lein sealog init`"
"Rendering changelogs to markdown files via: `lein sealog render`"
"Changelog version management via: `lein sealog bump`"]}
:changes {:added ["Idempotent changelog initialization via: `lein sealog init`"
"Rendering changelogs to markdown files via: `lein sealog render`"
"Changelog version management via: `lein sealog bump`"]}
:timestamp "2022-10-23T16:09:09.167841Z"}
2 changes: 1 addition & 1 deletion .sealog/changes/1-0-1.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
:minor 0
:patch 1}
:version-type :semver3
:changes {:fixed ["Corrected SCM information in leiningen project file."]}
:changes {:fixed ["Corrected SCM information in leiningen project file."]}
:timestamp "2022-10-23T16:29:40.223306Z"}
6 changes: 3 additions & 3 deletions .sealog/changes/1-0-2.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:version {:major 1
:minor 0
:patch 2},
:version-type :semver3,
:changes {:fixed ["Updated footer link to point to the public repository"]},
:patch 2}
:version-type :semver3
:changes {:fixed ["Updated footer link to point to the public repository"]}
:timestamp "2022-12-11T15:51:59.959778100Z"}
4 changes: 2 additions & 2 deletions .sealog/changes/1-1-0.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
:minor 1
:patch 0}
:version-type :semver3
:changes {:added ["Created a configuration file for sealog consumers."]
:changed ["Sealog commands will now use the configuration file if it exists and no command line options are set."]}
:changes {:added ["Created a configuration file for sealog consumers."]
:changed ["Sealog commands will now use the configuration file if it exists and no command line options are set."]}
:timestamp "2024-02-19T22:08:42.332183900Z"}
6 changes: 6 additions & 0 deletions .sealog/changes/1-2-0.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:version {:major 1
:minor 2
:patch 0}
:version-type :semver3
:changes {:added ["Added `:pretty-print-edn?` to the configuration. EDN files for changelog entries and configuration may now be pretty printed."]}
:timestamp "2024-03-03T00:38:25.843229400Z"}
3 changes: 2 additions & 1 deletion .sealog/config.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{:changelog-filename "CHANGELOG.md"
:changelog-entry-directory ".sealog/changes/"
:version-scheme :semver3}
:version-scheme :semver3
:pretty-print-edn? true}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Table of Contents

* [1.2.0 - 2024-03-03](#120---2024-03-03)
* [1.1.0 - 2024-02-19](#110---2024-02-19)
* [1.0.2 - 2022-12-11](#102---2022-12-11)
* [1.0.1 - 2022-10-23](#101---2022-10-23)
* [1.0.0 - 2022-10-23](#100---2022-10-23)

## 1.2.0 - 2024-03-03

* Added
* Added `:pretty-print-edn?` to the configuration. EDN files for changelog entries and configuration may now be pretty printed.

## 1.1.0 - 2024-02-19

* Added
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ The following keys and values are supported:
* `:changelog-entry-directory`
* A string representing a filepath relative to the project root where the `.edn` change files will be stored.
* `:version-scheme`
* The versioning scheme to be assumed by Sealog.
* The versioning scheme to be assumed by Sealog. Currently supported options are:
* `:semver3` - [3 Position Semantic Versioning 2.0](https://semver.org/)
* `:pretty-print-edn?`
* A boolean to determine if the .edn config and changelog entry files should be pretty printed. Defaults to false

## License

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.wallbrew</groupId>
<artifactId>lein-sealog</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.2.0</version>
<name>lein-sealog</name>
<description>A Leiningen plugin for managing your changelog.</description>
<url>https://github.com/Wall-Brew-Co/common-beer-format</url>
Expand All @@ -20,7 +20,7 @@
<url>https://github.com/Wall-Brew-Co/lein-sealog</url>
<connection>scm:git:git://github.com/Wall-Brew-Co/lein-sealog.git</connection>
<developerConnection>scm:git:ssh://[email protected]/Wall-Brew-Co/lein-sealog.git</developerConnection>
<tag>db37860c4764348af4bbdd537b538b2d0ee18955</tag>
<tag>fbbb9f5108342b76fd7ca8329e72b7294c20ede4</tag>
</scm>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.wallbrew/lein-sealog "1.1.0"
(defproject com.wallbrew/lein-sealog "1.2.0"
:description "A Leiningen plugin for managing your changelog."
:url "https://github.com/Wall-Brew-Co/common-beer-format"
:license {:name "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/leiningen/sealog/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
changelog (impl/load-changelog-entry-directory! configuration)
sorted-changelog (changelog/sort-changelog-descending changelog)
changes (impl/render-changelog sorted-changelog)]
(spit filepath changes)
(impl/write-file! filepath changes)
(main/info (format "Wrote changelog to: %s" filepath))))


Expand All @@ -49,5 +49,5 @@
changelog (impl/load-changelog-entry-directory! configuration)
new-entry (update (changelog/bump changelog bump-type) :timestamp str)
new-file (str changelog-directory (changelog/render-filename new-entry))]
(spit new-file new-entry)
(impl/write-edn-file! new-file new-entry configuration)
(println (format "Created new changelog entry: %s" new-file))))
13 changes: 11 additions & 2 deletions src/leiningen/sealog/impl.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns leiningen.sealog.impl
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pp]
[clojure.spec.alpha :as spec]
[clojure.string :as str]
[leiningen.core.main :as main]
Expand Down Expand Up @@ -41,6 +42,14 @@
(spit filename content))


(defn write-edn-file!
"Write the contents to a file as EDN."
[filename content {:keys [pretty-print-edn?]}]
(if pretty-print-edn?
(write-file! filename (with-out-str (pp/pprint content)))
(write-file! filename content)))


(defn read-file!
"This is a wrapper around `slurp` that logs the filename to the console."
[filename]
Expand Down Expand Up @@ -175,12 +184,12 @@

(defn init!
"Create a new changelog directory."
[{:keys [changelog-entry-directory version-scheme] :as _config}]
[{:keys [changelog-entry-directory version-scheme] :as config}]
(let [initial-entry (changelog/initialize version-scheme)
initial-entry-filename (str changelog-entry-directory (changelog/render-filename initial-entry))
entry (update initial-entry :timestamp str)]
(io/make-parents (io/file initial-entry-filename))
(write-file! initial-entry-filename entry)))
(write-edn-file! initial-entry-filename entry config)))


(defn sealog-configured?
Expand Down
12 changes: 10 additions & 2 deletions src/leiningen/sealog/types/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@
:description "The versioning scheme to use."}))


(spec/def ::pretty-print-edn?
(st/spec
{:type :boolean
:description "Whether or not to pretty print the EDN files."}))


(spec/def ::config
(st/spec
{:type :map
:spec (spec/keys :opt-un [::changelog-filename
::changelog-entry-directory
::version-scheme])
::version-scheme
::pretty-print-edn?])
:description "The configuration for Sealog."}))


(def default-config
"The default configuration for Sealog."
{:changelog-filename "CHANGELOG.md"
:changelog-entry-directory ".sealog/changes/"
:version-scheme :semver3})
:version-scheme :semver3
:pretty-print-edn? false})
1 change: 1 addition & 0 deletions test/leiningen/sealog/types/config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(is (test-util/generatable? ::sut/changelog-filename))
(is (test-util/generatable? ::sut/changelog-entry-directory))
(is (test-util/generatable? ::sut/version-scheme))
(is (test-util/generatable? ::sut/pretty-print-edn?))
(is (test-util/generatable? ::sut/config))))


Expand Down

0 comments on commit a39aeb5

Please sign in to comment.