-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I like authoring strong commits. Sharing my commits via RSS as a changelog motivates me to keep up the good habits of writing strong commits. I like writing. I like process. I like writing about process. This silly idea will give me a feedback loop.
- Loading branch information
Showing
6 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class GitCommitChangelogTarget | ||
include Singleton | ||
|
||
TARGET_PATH = Build.target_dir + "/changelog.xml" | ||
AUTHOR = "Dan Ott".freeze | ||
TITLE = "Dan Ott's Website Changelog" | ||
URL = "https://danott.website" | ||
|
||
def to_target | ||
self | ||
end | ||
|
||
def hydrate | ||
self | ||
end | ||
|
||
def render | ||
RSS::Maker.make("2.0") do |maker| | ||
maker.channel.author = AUTHOR | ||
maker.channel.updated = commits.map(&:date).max.to_s | ||
maker.channel.about = URL | ||
maker.channel.title = TITLE | ||
maker.channel.link = URL | ||
maker.channel.description = TITLE | ||
|
||
commits.each do |commit| | ||
maker.items.new_item do |maker_item| | ||
maker_item.description = commit.description | ||
maker_item.link = commit.link | ||
maker_item.title = commit.title | ||
maker_item.updated = commit.updated | ||
end | ||
end | ||
end | ||
end | ||
|
||
def write | ||
File.write(TARGET_PATH, render) | ||
self | ||
end | ||
|
||
def commits | ||
GitCommitJson.generate.map do |commit| | ||
CommitRssItem.new( | ||
subject: commit.fetch("subject"), | ||
body: commit.fetch("body"), | ||
date: Time.parse(commit.fetch("date")), | ||
hash: commit.fetch("hash") | ||
) | ||
end | ||
end | ||
|
||
CommitRssItem = | ||
Struct.new(:subject, :body, :date, :hash, keyword_init: true) do | ||
def title | ||
subject | ||
end | ||
|
||
def description | ||
options = { | ||
auto_ids: false, | ||
hard_wrap: false, | ||
input: "GFM", | ||
syntax_highlighter: "rouge" | ||
} | ||
Kramdown::Document.new(body, options).to_html.strip | ||
end | ||
|
||
def link | ||
"https://github.com/danott/website/commit/" + hash | ||
end | ||
|
||
def updated | ||
date.to_s | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generate a minimal JSON structure from git commits. | ||
# | ||
# https://gist.github.com/varemenos/e95c2e098e657c7688fd#gistcomment-3542030 | ||
# This prior art was helpful. | ||
# | ||
# https://git-scm.com/docs/pretty-formats | ||
# The git pretty formats docs will be helpful if more details are ever desired. | ||
class GitCommitJson | ||
def self.generate(limit = 1000) | ||
desired_json_structure = { | ||
"body" => "%b", | ||
"date" => "%cI", | ||
"hash" => "%H", | ||
"subject" => "%s" | ||
}.freeze | ||
|
||
ordered_attribute_keys = desired_json_structure.keys | ||
ordered_attribute_value_placeholders = desired_json_structure.values | ||
|
||
attribute_separator = | ||
"🤞 I pledge to never type this in a git commit, lest I break my rudimentary parser" | ||
commit_separator = | ||
"...Same goes for this, because of the aforementioned parser breaking risks 🙃" | ||
|
||
git_format = | ||
ordered_attribute_value_placeholders.join(attribute_separator) + | ||
commit_separator | ||
log = `git log -n #{limit} --format="#{git_format}"` | ||
|
||
log | ||
.strip | ||
.chomp(commit_separator) | ||
.split(commit_separator) | ||
.map do |commit| | ||
ordered_attribute_values = commit.strip.split(attribute_separator) | ||
Hash[ordered_attribute_keys.zip(ordered_attribute_values)] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GitCommitChangelogTarget.instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
FeedTarget.new | ||
FeedTarget.instance |