Skip to content

Commit

Permalink
Omit Git SHA from MemoryChangesets
Browse files Browse the repository at this point in the history
When a MemoryChangeset is created, it's usually for some change mono
itself made, like updating dependency versions or releasing the final
version of a package (when it's a prerelease).

When it creates changelog entries for these changes, the Git SHA points
to the last commit, any commit, which is inaccurate.

The commit in which this change is actually stored is not made yet, so
omit it from the changelog. This creates less noise in the changelog.
  • Loading branch information
tombruijn committed Jun 1, 2021
1 parent 6b17581 commit dd2a62f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changesets/changelog-entries-without-commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bump: "patch"
---

Remove commit info from some changeset entries made by mono. Changeset entries made by mono for dependency bumps do not have a commit, as they are part of the "publish" commit, which doesn't exist at time of changelog generation, so omit the information to reduce noise.
12 changes: 12 additions & 0 deletions lib/mono/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def bump
@metadata["bump"]
end

def date
commit[:date]
end

def commit
@commit ||=
begin
Expand All @@ -81,6 +85,14 @@ def initialize(metadata, message)
super(nil, metadata, message)
end

def date
@date ||= Time.now
end

def commit
# noop
end

def remove
# noop
end
Expand Down
21 changes: 16 additions & 5 deletions lib/mono/changeset_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ def changesets

def write_changesets_to_changelog
new_messages = []
sets = changesets.sort_by { |set| [set.bump, set.commit[:date]] }
sets = changesets.sort_by { |set| [set.bump, set.date] }
sets.each do |changeset|
commit = changeset.commit
url = "#{config.repo}/commit/#{commit[:long]}"
new_messages << "- [#{commit[:short]}](#{url}) #{changeset.bump} - " \
"#{changeset.message.lines.join(" ")}\n"
new_messages << build_changelog_entry(changeset)
end
changelog_path = File.join(package.path, "CHANGELOG.md")
FileUtils.touch(changelog_path)
Expand Down Expand Up @@ -59,5 +56,19 @@ def next_bump
"patch"
end
end

private

def build_changelog_entry(changeset)
message = ["- "]
commit = changeset.commit
if commit
url = "#{config.repo}/commit/#{commit[:long]}"
message << "[#{commit[:short]}](#{url}) "
end
message << changeset.bump
message << " - #{changeset.message.lines.join(" ")}\n"
message.join
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/mono/cli/publish/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@

changelog = File.read("CHANGELOG.md")
expect_changelog_to_include_version_header(changelog, next_version)
expect_changelog_to_include_release_notes(changelog, :patch, "Package release.")
expect_changelog_to_include_message(changelog, :patch, "Package release.")

expect(local_changes?).to be_falsy, local_changes.inspect
expect(commited_files).to eql([
Expand Down
8 changes: 5 additions & 3 deletions spec/support/helpers/publish_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ def expect_changelog_to_include_release_notes(changelog, bump, message = nil)
.to match(%r{- \[[a-z0-9]{7}\]\(#{url}/commit/[a-z0-9]{40}\) #{bump} - #{message}})
end

def expect_changelog_to_include_message(changelog, bump, message)
expect(changelog).to match(/- #{bump} - #{message}/)
end

def expect_changelog_to_include_package_bump(changelog, package, version)
url = "https://github.com/appsignal/#{current_project}"
message = "Update #{package} dependency to #{version}"
expect(changelog)
.to match(%r{- \[[a-z0-9]{7}\]\(#{url}/commit/[a-z0-9]{40}\) patch - #{message}})
expect_changelog_to_include_message(changelog, "patch", message)
end

def do_not_publish_package
Expand Down

0 comments on commit dd2a62f

Please sign in to comment.