@@ -5,121 +5,84 @@ class RepositoriesController < ApplicationController
5
5
# GET /repositories
6
6
# GET /repositories.json
7
7
def index
8
- @username = current_user . username
8
+ @username = current_user . username
9
9
set_initial_variables
10
10
end
11
11
12
12
# GET /repositories/1
13
13
# GET /repositories/1.json
14
14
def show
15
- github = Octokit ::Client . new access_token : current_user . oauth_token
16
- @id = @repository . id
17
- repop = github . repo @repository . full_name
18
- total = 0
19
- if repop
20
- @name_repo = repop . full_name
21
- commits = github . commits @name_repo
22
- @data = Hash . new
23
-
24
- commits . each do |c |
25
- cTemp = github . commit @name_repo , c . sha
26
- if @data . has_key? cTemp . commit . author . email
27
- @data [ cTemp . commit . author . email ] [ "name" ] = cTemp . commit . author . name . to_s
28
- @data [ cTemp . commit . author . email ] [ "additions" ] = @data [ cTemp . commit . author . email ] [ "additions" ] . to_i + cTemp . stats . additions . to_i
29
- @data [ cTemp . commit . author . email ] [ "deletions" ] = @data [ cTemp . commit . author . email ] [ "deletions" ] . to_i + cTemp . stats . deletions . to_i
30
- @data [ cTemp . commit . author . email ] [ "modified" ] = @data [ cTemp . commit . author . email ] [ "modified" ] . to_i + cTemp . stats . modifiedw . to_i
31
- else
32
- @data [ cTemp . commit . author . email ] = {
33
- name : cTemp . commit . author . name . to_s ,
34
- additions : cTemp . stats . additions . to_i ,
35
- deletions : cTemp . stats . deletions . to_i ,
36
- modified : cTemp . stats . modified . to_i
37
- }
38
- end
39
-
40
- end
41
- # @name_repo = repop.full_name
42
- else
43
- @name_repo = "nil"
44
- end
45
- @username = current_user . username
46
-
47
-
48
- @chart = LazyHighCharts ::HighChart . new ( 'pie' ) do |f |
49
- f . chart ( { :defaultSeriesType => "pie" ,
15
+ @authors = @repository . authors
16
+ @username = current_user . username
17
+ @chart = LazyHighCharts ::HighChart . new ( 'pie' ) do |f |
18
+ f . chart ( { :defaultSeriesType => "pie" ,
50
19
:margin => [ 50 , 200 , 60 , 170 ] } ,
51
20
52
- )
53
-
54
- f . series (
55
- :type => 'pie' ,
56
- :name => 'percentage contribution' ,
57
- :data => [
58
- [ 'Sam' , 45.0 ] ,
59
- [ 'Pedro' , 15.0 ] ,
60
- [ 'Juan' , 30.0 ] ,
61
- [ 'Thomas' , 5.0 ] ,
62
- [ 'Jeff' , 5.0 ]
63
- ] )
64
- f . legend ( :layout => 'vertical' , :style => { :left => 'auto' , :bottom => 'auto' , :right => '50px' , :top => '100px' } )
65
- f . plot_options ( :pie => {
66
- :allowPointSelect => true ,
67
- :cursor => "pointer" ,
68
- :dataLabels => {
21
+ )
22
+
23
+ f . series (
24
+ :type => 'pie' ,
25
+ :name => 'percentage contribution' ,
26
+ :data => [
27
+ [ 'Sam' , 45.0 ] ,
28
+ [ 'Pedro' , 15.0 ] ,
29
+ [ 'Juan' , 30.0 ] ,
30
+ [ 'Thomas' , 5.0 ] ,
31
+ [ 'Jeff' , 5.0 ]
32
+ ] )
33
+ f . legend ( :layout => 'vertical' , :style => { :left => 'auto' , :bottom => 'auto' , :right => '50px' , :top => '100px' } )
34
+ f . plot_options ( :pie => {
35
+ :allowPointSelect => true ,
36
+ :cursor => "pointer" ,
37
+ :dataLabels => {
69
38
:enabled => true ,
70
39
:color => "black" ,
71
40
:style => {
72
- :font => "13px Trebuchet MS, Verdana, sans-serif"
41
+ :font => "13px Trebuchet MS, Verdana, sans-serif"
73
42
}
74
- }
75
- } )
76
- end
77
- @data_in_series = [ ]
78
- @data . each do |key , value |
79
- @data_in_series . push ( [ value [ "name" ] , value [ "additions" ] + value [ "modified" ] ] )
80
-
81
- end
82
-
83
-
84
- @chart2 = LazyHighCharts ::HighChart . new ( 'pie' ) do |c |
85
- c . chart (
86
- plotBackgroundColor : nil ,
87
- plotBorderWidth : nil ,
88
- plotShadow : false ,
89
- type : 'pie'
90
- )
91
- c . title (
92
- text : 'Contributions to repo'
93
- )
94
- c . tooltip (
95
- pointFormat : '{series.name}: <b>{point.percentage:.1f}%</b>'
96
- )
97
- #c.options[:chart][:height] = 800
98
- #c.options[:chart][:width] = 800
99
- c . plotOptions (
100
- pie : {
101
- allowPointSelect : true ,
102
- cursor : 'pointer' ,
103
- dataLabels : {
104
- enabled : true ,
105
- format : '<b>{point.name}</b>: {point.percentage:.1f} %' ,
106
- style : {
107
- color : 'black'
108
- }
109
- }
110
- }
111
- )
112
- c . series (
113
- :type => 'pie' ,
114
- :name => 'percentage contribution' ,
115
- :data => @data_in_series
116
- )
43
+ }
44
+ } )
45
+ end
46
+ @data_in_series = [ ]
47
+ @authors . each do |author |
48
+ @data_in_series . push ( [ author . name , @repository . commits . where ( author_username : author . username ) . sum ( &:additions ) + @repository . commits . where ( author_username : author . username ) . sum ( &:files_changed ) ] )
117
49
end
118
- end
119
-
120
-
121
-
122
50
51
+ @chart2 = LazyHighCharts ::HighChart . new ( 'pie' ) do |c |
52
+ c . chart (
53
+ plotBackgroundColor : nil ,
54
+ plotBorderWidth : nil ,
55
+ plotShadow : false ,
56
+ type : 'pie'
57
+ )
58
+ c . title (
59
+ text : 'Contributions to repo'
60
+ )
61
+ c . tooltip (
62
+ pointFormat : '{series.name}: <b>{point.percentage:.1f}%</b>'
63
+ )
64
+ #c.options[:chart][:height] = 800
65
+ #c.options[:chart][:width] = 800
66
+ c . plotOptions (
67
+ pie : {
68
+ allowPointSelect : true ,
69
+ cursor : 'pointer' ,
70
+ dataLabels : {
71
+ enabled : true ,
72
+ format : '<b>{point.name}</b>: {point.percentage:.1f} %' ,
73
+ style : {
74
+ color : 'black'
75
+ }
76
+ }
77
+ }
78
+ )
79
+ c . series (
80
+ :type => 'pie' ,
81
+ :name => 'percentage contribution' ,
82
+ :data => @data_in_series
83
+ )
84
+ end
85
+ end
123
86
124
87
# GET /repositories/1/edit
125
88
def edit
@@ -128,7 +91,40 @@ def edit
128
91
# POST /repositories
129
92
# POST /repositories.json
130
93
def create
94
+ github = Octokit ::Client . new access_token : current_user . oauth_token
131
95
@repository = Repository . new ( repository_params )
96
+ repop = github . repo @repository . full_name
97
+ if repop
98
+ @name_repo = repop . full_name
99
+ commits = github . commits @name_repo
100
+ commits . each do |c |
101
+ cTemp = github . commit @name_repo , c . sha
102
+ commit = Commit . new
103
+ #if Author not exists in that repository
104
+ if !Author . where ( username : cTemp . commit . author . email . to_s ) . any?
105
+ author = Author . new
106
+ author . username = cTemp . commit . author . email . to_s
107
+ author . name = cTemp . commit . author . name . to_s
108
+ author . repositories << @repository
109
+ author . save
110
+ else
111
+ author = Author . where ( username : cTemp . commit . author . email . to_s ) . first
112
+ if !author . repositories . where ( id : @repository . id ) . any?
113
+ author . repositories << @repository
114
+ end
115
+ author . save
116
+ end
117
+ commit . message = cTemp . commit . message . to_s
118
+ commit . additions = cTemp . stats . additions . to_i
119
+ commit . deletions = cTemp . stats . deletions . to_i
120
+ commit . files_changed = cTemp . files . count . to_i
121
+ commit . author_username = Author . where ( username : cTemp . commit . author . email . to_s ) . first . username
122
+ commit . repository = @repository
123
+ commit . save
124
+ end
125
+ else
126
+ @name_repo = "nil"
127
+ end
132
128
133
129
respond_to do |format |
134
130
if @repository . save
@@ -160,41 +156,41 @@ def update
160
156
def destroy
161
157
@repository . destroy
162
158
respond_to do |format |
163
- format . html { redirect_to repositories_url , notice : 'Repository was successfully destroyed.' }
159
+ format . html { redirect_to repositories_path , notice : 'Repository was successfully destroyed.' }
164
160
format . json { head :no_content }
165
161
end
166
162
end
167
163
168
164
private
169
- # Use callbacks to share common setup or constraints between actions.
170
- def set_repository
171
- @repository = Repository . find ( params [ :id ] )
172
- end
165
+ # Use callbacks to share common setup or constraints between actions.
166
+ def set_repository
167
+ @repository = Repository . find ( params [ :id ] )
168
+ end
173
169
174
- # Never trust parameters from the scary internet, only allow the white list through.
175
- def repository_params
176
- params . require ( :repository ) . permit ( :github_id , :url , :name , :full_name , :description , :size , :collaborator )
177
- end
170
+ # Never trust parameters from the scary internet, only allow the white list through.
171
+ def repository_params
172
+ params . require ( :repository ) . permit ( :github_id , :url , :name , :full_name , :description , :size , :collaborator )
173
+ end
178
174
179
- def set_initial_variables
180
- github = Octokit ::Client . new access_token : current_user . oauth_token
181
- repos = Repository . all . to_a
182
- github . repos . each do |item |
183
- if !Repository . where ( github_id : item . id ) . any?
184
- repo = Repository . new
185
- repo . github_id = item . id
186
- repo . url = item . html_url
187
- repo . name = item . name
188
- repo . full_name = item . full_name
189
- repo . description = item . description
190
- repo . size = item . size
191
- repo . collaborator = item . collaborator
192
- repos . push ( repo )
193
- end
175
+ def set_initial_variables
176
+ github = Octokit ::Client . new access_token : current_user . oauth_token
177
+ repos = Repository . all . to_a
178
+ github . repos . each do |item |
179
+ if !Repository . where ( github_id : item . id ) . any?
180
+ repo = Repository . new
181
+ repo . github_id = item . id
182
+ repo . url = item . html_url
183
+ repo . name = item . name
184
+ repo . full_name = item . full_name
185
+ repo . description = item . description
186
+ repo . size = item . size
187
+ repo . collaborator = item . collaborator
188
+ repos . push ( repo )
194
189
end
195
-
196
- @repositories = repos
197
- @repo = Repository . new
198
- # @site = github.oauth.login
199
190
end
191
+
192
+ @repositories = repos
193
+ @repo = Repository . new
194
+ # @site = github.oauth.login
195
+ end
200
196
end
0 commit comments