From f7cb451feb7b2e54e251d2a5192d4b026535a649 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 13 Apr 2016 14:36:43 +0800 Subject: [PATCH] =?UTF-8?q?gitlab=E7=89=88=E6=9C=AC=E5=BA=93=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8F=90=E4=BA=A4=E4=BF=A1=E6=81=AF=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 21 ++++-- app/views/repositories/stats.html.erb | 70 +++++++++++++------ .../lib/gitlab/client/repositories.rb | 17 +++++ 3 files changed, 84 insertions(+), 24 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index dac4034d0..698fd1136 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -30,7 +30,7 @@ class RepositoriesController < ApplicationController menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers] default_search_scope :changesets - before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] + before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] @@ -562,10 +562,23 @@ update end def stats - @project_id = params[:id] + if @project.gpid.nil? + render 404 + return + end + project_id = @project.gpid @repository_id = @repository.identifier - # 提交次数统计 - @status_commit_count = Changeset.count(:conditions => ["#{Changeset.table_name}.repository_id = ?", @repository.id]) + creator = params[:creator] + rev = params[:rev] + g = Gitlab.client + begin + @static_total_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 1) + @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2) + @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3) + rescue + render_404 + return + end render :layout => 'base_projects' end diff --git a/app/views/repositories/stats.html.erb b/app/views/repositories/stats.html.erb index b4e4c92a3..5739eb35a 100644 --- a/app/views/repositories/stats.html.erb +++ b/app/views/repositories/stats.html.erb @@ -1,30 +1,60 @@ -
+

<%= l(:label_statistics) %>

<% if false %>
请在版本库中提交代码,统计信息将更准确
<% else %> -
修订 是版本库的提交次数, 显示为橘红色。

+
删除 是版本库的提交次数, 显示为橘红色。

变更 是对版本库中文件的修改次数, 显示为蓝色。
-

- <%= tag("embed", :width => 670, :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "commits_per_month")) %> -

-

- <%# 用户每月提交代码次数 %> - <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "commits_per_author")) %> -

-

- <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_commits_per_month")) %> -

-

- <%# 用户最近六个月的提交次数 %> - <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_commits_six_month")) %> -

-

- <%# 用户最近六个月的代码量 %> - <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_code_six_months")) %> -

+ + + + + + + + + + + + + + + + +
+

总情况

+ <% @static_total_per_user.each do |commit| %> +

总提交次数

+ <%= commit.uname %>:<%= commit.commits_num %> +

总提交代码量

+ <%= commit.uname %>:总提交次数<%= commit.commits_num %> + <%= commit.add %> + <%= commit.del %> + <% end %> +
+
+

月情况

+ <% @static_month__per_user.each do |commit| %> +

总提交次数

+ <%= commit.commits_num %> +

总提交代码量

+ <%= commit.add %> + <%= commit.del %> + <% end %> +
+
+

周情况

+ <% @static_week_per_user.each do |commit| %> +

总提交次数

+ <%= commit.commits_num %> +

总提交代码量

+ <%= commit.add %> + <%= commit.del %> + <% end %> +
+

<%= link_to l(:button_back), :action => 'show', :id => @project %>

<% html_title(l(:label_repository), l(:label_statistics)) -%> <% end %> \ No newline at end of file diff --git a/lib/gitlab-cli/lib/gitlab/client/repositories.rb b/lib/gitlab-cli/lib/gitlab/client/repositories.rb index 8824ca3e9..98a8ea150 100644 --- a/lib/gitlab-cli/lib/gitlab/client/repositories.rb +++ b/lib/gitlab-cli/lib/gitlab/client/repositories.rb @@ -89,6 +89,23 @@ class Gitlab::Client end alias_method :repo_commit, :commit + # Gets a statics of project repository. + # + # @example + # Gitlab.commits('viking') + # Gitlab.repo_commits('gitlab', :ref_name => 'api') + # + # @param [Integer] project The ID of a project. + # @param [Hash] options A customizable set of options. + # @option options [String] :ref_name The branch or tag name of a project repository. + # @option options [String] :creator The user name of a project repository. + # @option options [Integer] :period Statistics over time. 1:total 2:one month 3:one week + # @return [Array] + def rep_stats(project, options={}) + get("/projects/#{project}/repository/rep_stats", :query => options) + end + alias_method :repo_rep_stats, :rep_stats + # Get the diff of a commit in a project. # # @example