Skip to content

Commit

Permalink
Development related cleanup (rouge-ruby#2018)
Browse files Browse the repository at this point in the history
* Removed unnecessary require of minitest/spec

* Move require git inside of Rogue::Tasks::Git#initialize to make it lazy

git gem has warnings, this quells them

* Strip trailing whitespace from changelog.rake

---------

Co-authored-by: Ryan Davis <ryand-ruby@zenspider.com>
  • Loading branch information
tancnle and zenspider authored Jan 7, 2024
1 parent fb9aae2 commit 7b8df6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'bundler'
Bundler.require
require 'rouge'
require 'minitest/spec'
require 'minitest/autorun'

Token = Rouge::Token
Expand Down
23 changes: 11 additions & 12 deletions tasks/update/changelog.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace :update do
desc "Insert lines in CHANGELOG.md for commits between SHAs (inclusive)"
desc "Insert lines in CHANGELOG.md for commits between SHAs (inclusive)"
task :changelog, [:beg_sha, :end_sha] do |t, args|
args.with_defaults(:end_sha => nil)

Expand All @@ -9,33 +9,32 @@ namespace :update do
working_dir = Rake.application.original_dir
repo = Rouge::Tasks::Git.new(working_dir, remote)
gitlog = repo.log(args.beg_sha, args.end_sha)

text = ''
not_inserted = true

File.readlines(changelog).each do |l|
if not_inserted && l.start_with?("##")
text += Rouge::Tasks.version_line(Rouge.version)
text += Rouge::Tasks.comparison_line(remote,
repo.prev_version,
text += Rouge::Tasks.comparison_line(remote,
repo.prev_version,
"v" + Rouge.version)
text += gitlog.converted.join("") + "\n"
not_inserted = false
end

text += l
end

File.write(changelog, text)
end
end

require 'git'

module Rouge
module Tasks
class Git
def initialize(dir, remote)
require 'git'
@repo = ::Git.open(dir)
@remote = remote
end
Expand All @@ -44,7 +43,7 @@ module Rouge
commits = @repo.log(100).between(beg_sha, end_sha)
Log.new(@remote, commits)
end

def prev_version
@prev_version ||= @repo
.tags
Expand All @@ -61,8 +60,8 @@ module Rouge
return a[1] <=> b[1] if a[0] == b[0]
return a[0] <=> b[0]
end
class Log

class Log
def initialize(remote, commits)
@remote = remote
@msgs = commits.map { |c| Message.new(c.message, c.author.name) }
Expand All @@ -85,7 +84,7 @@ module Rouge
end
end
end

def self.comparison_line(remote, previous, current)
"[Comparison with the previous version](https://#{remote}/compare/#{previous}...#{current})\n\n"
end
Expand All @@ -97,7 +96,7 @@ module Rouge
def self.message_line(message)
" - #{message}\n"
end

def self.version_line(version)
"## version #{version}: #{Time.now.strftime("%Y-%m-%d")}\n\n"
end
Expand Down

0 comments on commit 7b8df6c

Please sign in to comment.