Merge pull request #651 from opf/feature/contribution_rake_task

[FEATURE] Group authors by contribution period
pull/630/head
sschu 11 years ago
commit 7dc315beba
  1. 24
      lib/tasks/copyright_authors.rake

@ -29,11 +29,12 @@
namespace :copyright do
namespace :authors do
desc "Shows contributors to a project"
desc "Shows contributors of a repository"
task :show, :arg1 do |task, args|
contribution_periods = contribution_periods_of_project(args[:arg1])
contribution_periods = contribution_periods_of_repository(args[:arg1])
formatted_periods = format_contribution_periods(contribution_periods)
show_contribution_periods(contribution_periods)
show_contribution_periods(formatted_periods)
end
private
@ -43,7 +44,7 @@ namespace :copyright do
CONTRIBUTION_REGEX = /^(?<date>\d\d\d\d-\d\d-\d\d) (?<author>.*)$/
def contribution_periods_of_project(path)
def contribution_periods_of_repository(path)
contributions = []
contribution_periods = []
path = '.' if path.nil?
@ -64,10 +65,17 @@ namespace :copyright do
contribution_periods.sort_by{ |c| [c.end, c.begin] }.reverse
end
def show_contribution_periods(contribution_periods)
contribution_periods.each do |c|
period = (c.begin == c.end) ? c.begin.to_s : "#{c.begin} - #{c.end}"
puts "#{period} #{c.author}"
def format_contribution_periods(contribution_periods)
contribution_periods.each_with_object({}) do |c, h|
date = (c.begin == c.end) ? c.begin.to_s : "#{c.begin} - #{c.end}"
h[date] = [] unless h.has_key? date
h[date] << c.author
end
end
def show_contribution_periods(formatted_periods)
formatted_periods.each_pair do |date, authors|
puts "#{date} #{authors.join(", ")}"
end
end
end

Loading…
Cancel
Save