Class: CommitCommentTools::RepositoryStats
- Inherits:
-
Object
- Object
- CommitCommentTools::RepositoryStats
- Defined in:
- lib/commit-comment-tools/repository-stats.rb
Defined Under Namespace
Classes: CommitGroup
Instance Method Summary collapse
- #commit_groups_by_date ⇒ Object
- #commit_groups_by_month ⇒ Object
- #commit_groups_by_week ⇒ Object
- #create_commit_group(branch_name, key_format = "%Y-%m-%d") ⇒ Object
- #create_commit_groups(key_format = "%Y-%m-%d") ⇒ Object
-
#initialize(repository_path, branch_name, resolution = :day) ⇒ RepositoryStats
constructor
A new instance of RepositoryStats.
- #stats ⇒ Object
Constructor Details
#initialize(repository_path, branch_name, resolution = :day) ⇒ RepositoryStats
Returns a new instance of RepositoryStats.
54 55 56 57 58 59 60 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 54 def initialize(repository_path, branch_name, resolution=:day) @repository = Grit::Repo.new(repository_path) @target_branches = @repository.remotes.select do |branch| branch_name === branch.name end @resolution = resolution end |
Instance Method Details
#commit_groups_by_date ⇒ Object
85 86 87 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 85 def commit_groups_by_date create_commit_groups("%Y-%m-%d") end |
#commit_groups_by_month ⇒ Object
93 94 95 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 93 def commit_groups_by_month create_commit_groups("%Y-%m") end |
#commit_groups_by_week ⇒ Object
89 90 91 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 89 def commit_groups_by_week create_commit_groups("%Y-%Uw") end |
#create_commit_group(branch_name, key_format = "%Y-%m-%d") ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 103 def create_commit_group(branch_name, key_format="%Y-%m-%d") # TODO Use Grit::Commit.find_all groups = @repository.commits(branch_name, nil).group_by do |commit| commit.date.strftime(key_format) end groups.map do |key, commits| CommitGroup.new(branch_name, key, commits) end end |
#create_commit_groups(key_format = "%Y-%m-%d") ⇒ Object
97 98 99 100 101 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 97 def create_commit_groups(key_format="%Y-%m-%d") @target_branches.map do |branch| create_commit_group(branch.name, key_format) end.flatten end |
#stats ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/commit-comment-tools/repository-stats.rb', line 62 def stats # TODO format data case @resolution when :day commit_groups = commit_groups_by_date when :week commit_groups = commit_groups_by_week when :month commit_groups = commit_groups_by_month end # TODO make simple commit_groups.group_by do |commit_group| commit_group.branch_name end.each do |branch_name, commit_groups| puts branch_name commit_groups.sort_by do |group| group.key end.each do |group| puts "#{group.key},#{group.size},#{group.diff_lines_count},#{group.diff_bytesize}" end end end |