Skip to content

Commit

Permalink
Extract changes code to clarify
Browse files Browse the repository at this point in the history
  • Loading branch information
wasnotrice committed May 19, 2014
1 parent f7e30e4 commit 5e5db7d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tasks/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ def generate(categories = nil)
{ pattern: 'Changelog: bugfix', heading: 'Bug Fixes'}
]

last_sha = `git rev-list --tags --max-count=1`.chomp
last_release = `git describe #{last_sha}`.chomp
commit_range = "#{last_release}..master"
commit_range = commits_on_master_since_last_release
categorized_commits = []

changes = categories.inject([]) do |list, category|
commits = commits_matching(category[:pattern], commit_range)
categorized_commits.concat Array(commits)
categorized_commits.concat commits
list << changes_under_heading(category[:heading], commits)
end

# TODO: Add anything marked 'Changelog' without a parameter
all_change_commits = commits_matching('Changelog', commit_range)
misc_change_commits = all_change_commits.reject {|commit| categorized_commits.include? commit }
changes << changes_under_heading('Miscellaneous', misc_change_commits)

changes << misc_changes(commit_range, categorized_commits)

if changes.any?
changes << contributors(commit_range)
Expand All @@ -46,6 +40,11 @@ def commits_matching(pattern, commit_range)
end
end

def misc_changes(commit_range, categorized_commits)
misc_change_commits = commits_matching('Changelog', commit_range).reject {|commit| categorized_commits.include? commit }
changes_under_heading('Miscellaneous', misc_change_commits)
end

def changes_under_heading(title, commits)
if commits.any?
heading = heading(title, commits.length)
Expand All @@ -59,6 +58,12 @@ def contributors(commit_range)
names = contributors.map {|line| line.sub(/^.*\t/, '')}.join(", ")
heading << names
end

def commits_on_master_since_last_release
last_sha = `git rev-list --tags --max-count=1`.chomp
last_release = `git describe #{last_sha}`.chomp
commit_range = "#{last_release}..master"
end
end

desc "Generate changelog entries since last release"
Expand Down

0 comments on commit 5e5db7d

Please sign in to comment.