Skip to content

Commit

Permalink
Shorten Changelog#generate a bit through extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed May 19, 2014
1 parent 5e5db7d commit f622722
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tasks/changelog.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
class Changelog
def generate(categories = nil)
categories ||= [
{ pattern: 'Changelog: feature', heading: 'New features'},
{ pattern: 'Changelog: improvement', heading: 'Improvements'},
{ pattern: 'Changelog: bugfix', heading: 'Bug Fixes'}
]
CATEGORY_MAPPING = [
{pattern: 'Changelog: feature', heading: 'New features'},
{pattern: 'Changelog: improvement', heading: 'Improvements'},
{pattern: 'Changelog: bugfix', heading: 'Bug Fixes'}
]

def generate(categories = CATEGORY_MAPPING)
commit_range = commits_on_master_since_last_release
changes = categorize_commits(categories, commit_range)
changes << contributors(commit_range) if changes.any?
changes.compact.join("\n\n")
end

private
def categorize_commits(categories, commit_range)
categorized_commits = []

changes = categories.inject([]) do |list, category|
Expand All @@ -16,12 +23,7 @@ def generate(categories = nil)
end

changes << misc_changes(commit_range, categorized_commits)

if changes.any?
changes << contributors(commit_range)
end

changes.compact.join("\n\n")
changes
end

def heading(title, count, underline_char = '-')
Expand Down

0 comments on commit f622722

Please sign in to comment.