@ -249,6 +249,14 @@ update
return - 1
end
end
if params [ :to ] == 'gitlab'
g = Gitlab . client
g . post ( '/session' , body : { email : User . current . mail , password : User . current . hashed_password } )
redirect_to " http://192.168.41.130:3000/gitlab-org/gitlab-shell/tree/master "
return
end
#if( !User.current.member_of?(@project) || @project.hidden_repo)
@repository . fetch_changesets if Setting . autofetch_changesets? && @path . empty?
@ -441,6 +449,8 @@ update
def stats
@project_id = params [ :id ]
@repository_id = @repository . identifier
# 提交次数统计
@status_commit_count = Changeset . count ( :conditions = > [ " #{ Changeset . table_name } .repository_id = ? " , @repository . id ] )
render :layout = > 'base_projects'
end
@ -451,6 +461,12 @@ update
data = graph_commits_per_month ( @repository )
when " commits_per_author "
data = graph_commits_per_author ( @repository )
when " author_commits_per_month "
data = graph_author_commits_per_month ( @repository )
when " author_commits_six_month "
data = author_commits_six_month ( @repository )
when " author_code_six_months "
data = author_code_six_month ( @repository )
end
if data
headers [ " Content-Type " ] = " image/svg+xml "
@ -476,7 +492,18 @@ update
if params [ :repository_id ] . present?
@repository = @project . repositories . find_by_identifier_param ( params [ :repository_id ] )
else
@repository = @project . repository
# 多版本库,如果一个版本库为空则去下一个
rep_count = @project . repositories . count
if @project . repository . nil?
for i in 0 .. rep_count
unless @project . repositories [ i ] . nil?
@repository = @project . repositories [ i ]
break
end
end
else
@repository = @project . repository
end
end
( render_404 ; return false ) unless @repository
@path = params [ :path ] . is_a? ( Array ) ? params [ :path ] . join ( '/' ) : params [ :path ] . to_s
@ -540,11 +567,12 @@ update
:stack = > :side ,
:scale_integers = > true ,
:step_x_labels = > 2 ,
:show_data_values = > fals e,
:show_data_values = > tru e,
:graph_title = > l ( :label_commits_per_month ) ,
:show_graph_title = > true
)
# 具状图
graph . add_data (
:data = > commits_by_month [ 0 .. 11 ] . reverse ,
:title = > l ( :label_revision_plural )
@ -560,7 +588,7 @@ update
def graph_commits_per_author ( repository )
commits_by_author = Changeset . count ( :all , :group = > :committer , :conditions = > [ " repository_id = ? " , repository . id ] )
commits_by_author . to_a . sort! { | x , y | x . last < = > y . last }
commits_by_author = commits_by_author . to_a . sort! { | x , y | x . last < = > y . last } . last ( 25 )
changes_by_author = Change . count ( :all , :group = > :committer , :include = > :changeset , :conditions = > [ " #{ Changeset . table_name } .repository_id = ? " , repository . id ] )
h = changes_by_author . inject ( { } ) { | o , i | o [ i . first ] = i . last ; o }
@ -582,7 +610,7 @@ update
:fields = > fields ,
:stack = > :side ,
:scale_integers = > true ,
:show_data_values = > fals e,
:show_data_values = > tru e,
:rotate_y_labels = > false ,
:graph_title = > l ( :label_commits_per_author ) ,
:show_graph_title = > true
@ -597,6 +625,123 @@ update
)
graph . burn
end
# 用户最近一年的提交次数
def graph_author_commits_per_month ( repository )
@date_to = Date . today
@date_from = @date_to << 12
@date_from = Date . civil ( @date_from . year , @date_from . month , @date_from . day )
commits_by_author = Changeset . count ( :all , :group = > :committer ,
:conditions = > [ " #{ Changeset . table_name } .repository_id = ? AND #{ Changeset . table_name } .commit_date BETWEEN ? AND ? " , repository . id , @date_from , @date_to ] )
commits_by_author = commits_by_author . to_a . sort! { | x , y | x . last < = > y . last } . last ( 25 )
fields = commits_by_author . collect { | r | r . first }
commits_data = commits_by_author . collect { | r | r . last }
fields = fields + [ " " ] * ( 10 - fields . length ) if fields . length < 10
commits_data = commits_data + [ 0 ] * ( 10 - commits_data . length ) if commits_data . length < 10
# Remove email adress in usernames
fields = fields . collect { | c | c . gsub ( %r{ <.+@.+> } , '' ) }
graph = SVG :: Graph :: BarHorizontal . new (
:height = > 400 ,
:width = > 600 ,
:fields = > fields ,
:stack = > :side ,
:scale_integers = > true ,
:show_data_values = > true ,
:rotate_y_labels = > false ,
:graph_title = > l ( :label_author_commits_year ) ,
:show_graph_title = > true ,
:no_css = > true
)
graph . add_data (
:data = > commits_data ,
:title = > l ( :label_revision_commit_count )
)
graph . burn
end
# 用户最近六个月的提交次数
def author_commits_six_month ( repository )
@date_to = Date . today
@date_from = @date_to << 6
@date_from = Date . civil ( @date_from . year , @date_from . month , @date_from . day )
commits_by_author = Changeset . count ( :all , :group = > :committer ,
:conditions = > [ " #{ Changeset . table_name } .repository_id = ? AND #{ Changeset . table_name } .commit_date BETWEEN ? AND ? " , repository . id , @date_from , @date_to ] )
commits_by_author = commits_by_author . to_a . sort! { | x , y | x . last < = > y . last } . last ( 25 )
fields = commits_by_author . collect { | r | r . first }
commits_data = commits_by_author . collect { | r | r . last }
fields = fields + [ " " ] * ( 10 - fields . length ) if fields . length < 10
commits_data = commits_data + [ 0 ] * ( 10 - commits_data . length ) if commits_data . length < 10
# Remove email adress in usernames
fields = fields . collect { | c | c . gsub ( %r{ <.+@.+> } , '' ) }
graph = SVG :: Graph :: BarHorizontal . new (
:height = > 400 ,
:width = > 600 ,
:fields = > fields ,
:stack = > :side ,
:scale_integers = > true ,
:show_data_values = > true ,
:rotate_y_labels = > false ,
:graph_title = > l ( :label_author_commits_six_month ) ,
:show_graph_title = > true
)
graph . add_data (
:data = > commits_data ,
:title = > l ( :label_revision_commit_count )
)
graph . burn
end
# 最近六个月代码量统计
def author_code_six_month ( repository )
@date_to = Date . today
@date_from = @date_to << 6
@date_from = Date . civil ( @date_from . year , @date_from . month , @date_from . day )
commits_by_author = Changeset . count ( :group = > :committer , :conditions = > [ " #{ Changeset . table_name } .repository_id = ? AND #{ Changeset . table_name } .commit_date BETWEEN ? AND ? " , repository . id , @date_from , @date_to ] )
commits_by_author = commits_by_author . to_a . sort! { | x , y | x . last < = > y . last } . last ( 40 )
all_author = [ ]
commits_by_author . each do | cba |
all_author << cba . first
end
# all_author = all_author.collect {|c| c.gsub(%r{/ /<.+@.+>}, '') }
all_author = all_author . collect { | c | c . split . first }
commits_by_author = repository . commits ( all_author , " #{ @date_from } " , " #{ @date_to } " , repository . id == 150 ? " szzh " : 'master' )
fields = commits_by_author . collect { | r | r . first }
commits_data = commits_by_author . collect { | r | r . last }
fields = fields + [ " " ] * ( 10 - fields . length ) if fields . length < 10
commits_data = commits_data + [ 0 ] * ( 10 - commits_data . length ) if commits_data . length < 10
# Remove email adress in usernames
fields = fields . collect { | c | c . gsub ( %r{ <.+@.+> } , '' ) }
graph = SVG :: Graph :: BarHorizontal . new (
:height = > 400 ,
:width = > 600 ,
:fields = > fields ,
:stack = > :side ,
:scale_integers = > true ,
:show_data_values = > true ,
:rotate_y_labels = > false ,
:graph_title = > l ( :label_author_code_six_month ) ,
:show_graph_title = > true
)
graph . add_data (
:data = > commits_data ,
:title = > l ( :lable_revision_code_count )
)
graph . burn
end
def check_hidden_repo
project = Project . find ( params [ :id ] )
if ! User . current . member_of? ( project )