diggit 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fbc5e12f3c7806df481b5627dc5f904f89428c5
4
- data.tar.gz: 6600fc64a91b44b386795d16a792caa11f12d932
3
+ metadata.gz: ea02ededd6c7a3836496975d8d994a75e131c4dc
4
+ data.tar.gz: efb7cd6e4cabca46c43449a71de61ed52b9233e9
5
5
  SHA512:
6
- metadata.gz: 5defc137d1d9cd066c730c4c2d01b2da01bd7f848866cd01888caf6b97fea24377e293ddfc66ade5f03f9b6742ca3bc177b611762a30deb697b9fe6ff894f326
7
- data.tar.gz: 535718d8f71f8f088f08c08bab2edb33e8e270db0e928a208d26c273c4a71b445863060ec2157175adb33fc33292e8120ba4d0df94931f96a1589db783a800ed
6
+ metadata.gz: a4eddd07d9a7102df17b2b8841d3f3c10ef11c1c60cb3d035cf43c3af5bcdc91c4adb5caa4ed814ab8d74dc97c8f6ff41ed0c98d43af3f9e76395163cb85d861
7
+ data.tar.gz: 59a4947128381985ad25d2b27aaa52b12ec48362c4cda8c0b885919fdab9504d54579dc15f29e5f841682e20c536e9e622c36df86fd82980d64a36dfa7e4bd13
@@ -1,5 +1,13 @@
1
1
  # Changelog of Diggit
2
2
 
3
+ ### Version 2.0.2
4
+ * Fixed analysis cleaning
5
+ * Fixed error in gemspec
6
+ * Now rspec is launched after rubocop.
7
+ * Dgit binary now takes a `-f` flag to indicates folder
8
+ * It is now possible to deletes joins and analyses from a dgit folder
9
+ * The `clone` commands has been renamed `clones` for consistency sake
10
+
3
11
  ### Version 2.0.1
4
12
  * Removed `errors`command, merged with subcommands of `sources`
5
13
  * Added a lot of documentation
data/bin/dgit CHANGED
@@ -17,202 +17,211 @@
17
17
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
20
- #
21
20
 
22
21
  require 'gli'
23
22
  require_relative '../lib/dgit'
24
23
 
25
- include GLI::App
24
+ module Diggit
25
+ include GLI::App
26
26
 
27
- program_desc 'A git repository analysis tool.'
27
+ extend self
28
+ program_desc 'A git repository analysis tool.'
28
29
 
29
- switch [:v, :verbose], default_value: false, negatable: false, desc: "Indicates if the debug information are visible."
30
+ switch [:v, :verbose], default_value: false, negatable: false, desc: "Indicates if the debug information are visible."
31
+ flag [:f, :folder], default_value: ".", desc: "Path to the diggit folder. Default: current folder."
30
32
 
31
- version Diggit::VERSION
33
+ version Diggit::VERSION
32
34
 
33
- subcommand_option_handling :normal
34
- arguments :strict
35
+ subcommand_option_handling :normal
36
+ arguments :strict
35
37
 
36
- desc 'Init a diggit folder.'
37
- skips_pre
38
- command :init do |c|
39
- c.action do |_global_options, _options, _args|
40
- Diggit::Dig.init_dir
41
- Log.ok "Diggit folder initialized."
38
+ desc 'Init a diggit folder.'
39
+ skips_pre
40
+ command :init do |c|
41
+ c.action do |globals, _options, _args|
42
+ Diggit::Dig.init_dir globals[:f]
43
+ Log.ok "Diggit folder initialized."
44
+ end
42
45
  end
43
- end
44
46
 
45
- desc 'Display the status of the diggit folder.'
46
- command :status do |c|
47
- c.action do |_global_options, _options, _args|
48
- Log.info "Config"
49
- Log.info "======"
50
- Log.info "- Analyses: #{Diggit::Dig.it.config.get_analyses.join(', ')}"
51
- Log.info "- Joins: #{Diggit::Dig.it.config.get_joins.join(', ')}"
52
- Log.info ""
53
- Log.info "Journal"
54
- Log.info "======="
55
- Log.info "- New sources:"
56
- Log.indent do
57
- Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:new).size}"
58
- Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:new, true).size}"
59
- end
60
- Log.info "- Cloned sources:"
61
- Log.indent do
62
- Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:cloned).size}"
63
- Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:cloned, true).size}"
47
+ desc 'Display the status of the diggit folder.'
48
+ command :status do |c|
49
+ c.action do |_global_options, _options, _args|
50
+ Log.info "Config"
51
+ Log.info "======"
52
+ Log.info "- Analyses: #{Diggit::Dig.it.config.get_analyses.join(', ')}"
53
+ Log.info "- Joins: #{Diggit::Dig.it.config.get_joins.join(', ')}"
54
+ Log.info ""
55
+ Log.info "Journal"
56
+ Log.info "======="
57
+ Log.info "- New sources:"
58
+ Log.indent do
59
+ Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:new).size}"
60
+ Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:new, true).size}"
61
+ end
62
+ Log.info "- Cloned sources:"
63
+ Log.indent do
64
+ Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:cloned).size}"
65
+ Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:cloned, true).size}"
66
+ end
64
67
  end
65
68
  end
66
- end
67
69
 
68
- desc 'Manage the sources of the diggit folder.'
69
- command :sources do |c|
70
- c.desc 'List the sources.'
71
- c.command :list do |list|
72
- list.action do |_global_options, _options, _args|
73
- sources = Diggit::Dig.it.journal.sources
74
- sources.each_index do |idx|
75
- msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})"
76
- sources[idx].error? ? Log.error(msg) : Log.ok(msg)
70
+ desc 'Manage the sources of the diggit folder.'
71
+ command :sources do |c|
72
+ c.desc 'List the sources.'
73
+ c.command :list do |list|
74
+ list.action do |_global_options, _options, _args|
75
+ sources = Diggit::Dig.it.journal.sources
76
+ sources.each_index do |idx|
77
+ msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})"
78
+ sources[idx].error? ? Log.error(msg) : Log.ok(msg)
79
+ end
77
80
  end
78
81
  end
79
- end
80
- c.desc 'Add a source.'
81
- c.arg_name 'url'
82
- c.command :add do |add|
83
- add.action do |_global_options, _options, args|
84
- Diggit::Dig.it.journal.add_source args[0]
82
+ c.desc 'Add a source.'
83
+ c.arg_name 'url'
84
+ c.command :add do |add|
85
+ add.action do |_global_options, _options, args|
86
+ Diggit::Dig.it.journal.add_source args[0]
87
+ end
85
88
  end
86
- end
87
- c.desc 'Import sources from a file.'
88
- c.arg_name 'file'
89
- c.command :import do |import|
90
- import.action do |_global_options, _options, args|
91
- File.open(args[0]).each { |line| Diggit::Dig.it.journal.add_source(line) }
89
+ c.desc 'Import sources from a file.'
90
+ c.arg_name 'file'
91
+ c.command :import do |import|
92
+ import.action do |_global_options, _options, args|
93
+ File.open(args[0]).each { |line| Diggit::Dig.it.journal.add_source(line) }
94
+ end
92
95
  end
93
- end
94
- c.desc 'Display all sources in error.'
95
- c.command :errors do |errors|
96
- errors.action do |_global_options, _options, _args|
97
- sources = Diggit::Dig.it.journal.sources
98
- sources.each_index do |idx|
99
- msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})"
100
- Log.error msg if sources[idx].error?
96
+ c.desc 'Display all sources in error.'
97
+ c.command :errors do |errors|
98
+ errors.action do |_global_options, _options, _args|
99
+ sources = Diggit::Dig.it.journal.sources
100
+ sources.each_index do |idx|
101
+ msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})"
102
+ Log.error msg if sources[idx].error?
103
+ end
101
104
  end
102
105
  end
103
- end
104
- c.desc 'Display information on a source'
105
- c.arg_name 'id'
106
- c.command :info do |info|
107
- info.action do |_global_options, _options, args|
108
- src = Diggit::Dig.it.journal.sources_by_ids(args.to_i)
109
- url = "URL: #{src.url}"
110
- src.error? ? Log.error(url) : Log.info(url)
111
- Log.info "State: #{src.state}"
112
- Log.info "Performed analyses: #{src.performed_analyses.join(', ')}" unless src.performed_analyses.empty?
113
- Log.error "Ongoing analyses: #{src.ongoing_analyses.join(', ')}" unless src.ongoing_analyses.emtpy?
114
- if src.error?
115
- error = src.error
116
- Log.indent do
117
- Log.error error[:message]
118
- Log.info error[:backtrace].join("\n")
106
+ c.desc 'Display information on a source'
107
+ c.arg_name 'id'
108
+ c.command :info do |info|
109
+ info.action do |_global_options, _options, args|
110
+ src = Diggit::Dig.it.journal.sources_by_ids(args[0].to_i)[0]
111
+ url = "URL: #{src.url}"
112
+ src.error? ? Log.error(url) : Log.info(url)
113
+ Log.info "State: #{src.state}"
114
+ Log.info "Performed analyses: #{src.performed_analyses.join(', ')}" unless src.performed_analyses.empty?
115
+ Log.error "Ongoing analyses: #{src.ongoing_analyses.join(', ')}" unless src.ongoing_analyses.empty?
116
+ if src.error?
117
+ error = src.error
118
+ Log.indent do
119
+ Log.error error[:message]
120
+ Log.info error[:backtrace].join("\n")
121
+ end
119
122
  end
120
123
  end
121
124
  end
125
+ c.default_command :list
122
126
  end
123
- c.default_command :list
124
- end
125
127
 
126
- desc 'Manage the joins of the diggit folder.'
127
- command :joins do |c|
128
- c.desc 'List the joins'
129
- c.command :list do |list|
130
- list.action do |_global_options, _options, _args|
131
- Diggit::Dig.it.config.get_joins.each { |a| Log.info a.name }
128
+ desc 'Manage the joins of the diggit folder.'
129
+ command :joins do |c|
130
+ c.desc 'List the joins'
131
+ c.command :list do |list|
132
+ list.action do |_global_options, _options, _args|
133
+ Diggit::Dig.it.config.get_joins.each { |a| Log.info a.name }
134
+ end
132
135
  end
133
- end
134
- c.desc 'Add add join.'
135
- c.arg_name 'name'
136
- c.command :add do |add|
137
- add.action do |_global_options, _options, args|
138
- Diggit::Dig.it.config.add_join args[0]
136
+ c.desc 'Add a join.'
137
+ c.arg_name 'name'
138
+ c.command :add do |add|
139
+ add.action do |_global_options, _options, args|
140
+ Diggit::Dig.it.config.add_join args[0]
141
+ end
139
142
  end
140
- end
141
- c.desc 'Perform joins.'
142
- c.command :perform do |perform|
143
- perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
144
- perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: []
145
- perform.flag [:m, :mode], desc: "running mode",
146
- must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run
147
- perform.action do |_global_options, options, _args|
148
- Diggit::Dig.it.join(options[:s], options[:a], options[:m])
143
+ c.desc 'Delete a join.'
144
+ c.arg_name 'name'
145
+ c.command :del do |del|
146
+ del.action do |_global_options, _options, args|
147
+ Diggit::Dig.it.config.del_join args[0]
148
+ end
149
149
  end
150
+ c.desc 'Perform joins.'
151
+ c.command :perform do |perform|
152
+ perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
153
+ perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: []
154
+ perform.flag [:m, :mode], desc: "running mode",
155
+ must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run
156
+ perform.action do |_global_options, options, _args|
157
+ Diggit::Dig.it.join(options[:s], options[:a], options[:m])
158
+ end
159
+ end
160
+ c.default_command :list
150
161
  end
151
- c.default_command :list
152
- end
153
162
 
154
- desc 'Manage the analyses of the diggit folder.'
155
- command :analyses do |c|
156
- c.desc 'List the analyses'
157
- c.command :list do |list|
158
- list.action do |_global_options, _options, _args|
159
- Diggit::Dig.it.config.get_analyses.each { |a| Log.info a.name }
163
+ desc 'Manage the analyses of the diggit folder.'
164
+ command :analyses do |c|
165
+ c.desc 'List the analyses'
166
+ c.command :list do |list|
167
+ list.action do |_global_options, _options, _args|
168
+ Diggit::Dig.it.config.get_analyses.each { |a| Log.info a.name }
169
+ end
160
170
  end
161
- end
162
- c.desc 'Add an analysis.'
163
- c.arg_name 'name'
164
- c.command :add do |add|
165
- add.action do |_global_options, _options, args|
166
- Diggit::Dig.it.config.add_analysis args[0]
171
+ c.desc 'Add an analysis.'
172
+ c.arg_name 'name'
173
+ c.command :add do |add|
174
+ add.action do |_global_options, _options, args|
175
+ Diggit::Dig.it.config.add_analysis args[0]
176
+ end
167
177
  end
168
- end
169
- c.desc 'Delete an analysis.'
170
- c.arg_name 'name'
171
- c.command :del do |add|
172
- add.action do |_global_options, _options, args|
173
- Diggit::Dig.it.config.del_analysis args[0]
178
+ c.desc 'Delete an analysis.'
179
+ c.arg_name 'name'
180
+ c.command :del do |del|
181
+ del.action do |_global_options, _options, args|
182
+ Diggit::Dig.it.config.del_analysis args[0]
183
+ end
174
184
  end
175
- end
176
- c.desc 'Perform analyses.'
177
- c.command :perform do |perform|
178
- perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
179
- perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: []
180
- perform.flag [:m, :mode], desc: "running mode",
181
- must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run
182
- perform.action do |_global_options, options, _args|
183
- Diggit::Dig.it.analyze(options[:s], options[:a], options[:m])
185
+ c.desc 'Perform analyses.'
186
+ c.command :perform do |perform|
187
+ perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
188
+ perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: []
189
+ perform.flag [:m, :mode], desc: "running mode",
190
+ must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run
191
+ perform.action do |_global_options, options, _args|
192
+ Diggit::Dig.it.analyze(options[:s], options[:a], options[:m])
193
+ end
184
194
  end
195
+ c.default_command :list
185
196
  end
186
- c.default_command :list
187
- end
188
197
 
189
- desc 'Manage clone actions.'
190
- command :clone do |c|
191
- c.desc 'Perform the clones.'
192
- c.command :perform do |perform|
193
- perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
194
- perform.action do |_global_options, options, _args|
195
- Diggit::Dig.it.clone(*options[:s])
198
+ desc 'Manage clone actions.'
199
+ command :clones do |c|
200
+ c.desc 'Perform the clones.'
201
+ c.command :perform do |perform|
202
+ perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: []
203
+ perform.action do |_global_options, options, _args|
204
+ Diggit::Dig.it.clone(*options[:s])
205
+ end
196
206
  end
207
+ c.default_command :perform
208
+ end
209
+ pre do |globals, _command, _options, _args|
210
+ Diggit::Dig.init globals[:f]
211
+ Log.level = :fine if globals[:v]
212
+ true
197
213
  end
198
- c.default_command :perform
199
- end
200
214
 
201
- pre do |global, _command, _options, _args|
202
- Diggit::Dig.init
203
- Log.level = :fine if global[:v]
204
- true
205
- end
215
+ post do |_global, _command, _options, _args|
216
+ # Post logic here, skips_post to skip commands
217
+ end
206
218
 
207
- post do |_global, _command, _options, _args|
208
- # Post logic here, skips_post to skip commands
209
- end
219
+ on_error do |exception|
220
+ Log.error "Error running diggit."
221
+ Log.error exception.message
222
+ Log.info exception.backtrace.join("\n")
223
+ false
224
+ end
210
225
 
211
- on_error do |exception|
212
- Log.error "Error running diggit."
213
- Log.error exception.message
214
- Log.info exception.backtrace.join("\n")
215
- false
226
+ exit run(ARGV)
216
227
  end
217
-
218
- exit run(ARGV)
@@ -16,9 +16,8 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
- require_relative "dgit/core"
22
- require_relative "dgit/plugins"
23
- require_relative "dgit/version"
24
- require_relative "dgit/log"
20
+ require_relative 'dgit/core'
21
+ require_relative 'dgit/plugins'
22
+ require_relative 'dgit/version'
23
+ require_relative 'dgit/log'
@@ -16,7 +16,7 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
19
+ # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
20
 
21
21
  require 'oj'
22
22
  require 'rugged'
@@ -113,6 +113,11 @@ module Diggit
113
113
  @entry[:ongoing_analyses]
114
114
  end
115
115
 
116
+ def clean_analysis(analysis)
117
+ performed_analyses.delete_if { |e| e == analysis.name }
118
+ ongoing_analyses.delete_if { |e| e == analysis.name }
119
+ end
120
+
116
121
  def clone
117
122
  if File.exist?(folder)
118
123
  Rugged::Repository.new(folder)
@@ -120,6 +125,7 @@ module Diggit
120
125
  Rugged::Repository.clone_at(url, folder)
121
126
  end
122
127
  self.state = :cloned
128
+ self.error = nil
123
129
  rescue => e
124
130
  Log.error "Error cloning #{url}."
125
131
  self.error = Journal.dump_error(e)
@@ -226,11 +232,11 @@ module Diggit
226
232
  end
227
233
 
228
234
  def to_hash
229
- { analyses: @analyses.map(&:name), joins: @joins.map(&:name) }
235
+ { analyses: @analyses.map(&:simple_name), joins: @joins.map(&:simple_name) }
230
236
  end
231
237
 
232
238
  def add_analysis(name)
233
- load_analysis(name) unless @analyses.map(&:name).include?(name)
239
+ load_analysis(name) unless @analyses.map(&:simple_name).include?(name)
234
240
  Dig.it.save_config
235
241
  end
236
242
 
@@ -239,17 +245,17 @@ module Diggit
239
245
  end
240
246
 
241
247
  def del_analysis(name)
242
- @analyses.delete_if { |a| a.name == name }
248
+ @analyses.delete_if { |a| a.simple_name == name }
243
249
  Dig.it.save_config
244
250
  end
245
251
 
246
252
  def get_analyses(*names)
247
253
  return analyses if names.empty?
248
- analyses.select { |a| names.include?(a.name) }
254
+ analyses.select { |a| names.include?(a.simple_name) }
249
255
  end
250
256
 
251
257
  def add_join(name)
252
- load_join(name) unless @joins.map(&:name).include?(name)
258
+ load_join(name) unless @joins.map(&:simple_name).include?(name)
253
259
  Dig.it.save_config
254
260
  end
255
261
 
@@ -258,13 +264,13 @@ module Diggit
258
264
  end
259
265
 
260
266
  def del_join(name)
261
- @joins.delete_if { |j| j.name == name }
267
+ @joins.delete_if { |j| j.simple_name == name }
262
268
  Dig.it.save_config
263
269
  end
264
270
 
265
271
  def get_joins(*names)
266
272
  return joins if names.empty?
267
- joins.select { |j| joins.include?(j.name) }
273
+ joins.select { |j| joins.include?(j.simple_name) }
268
274
  end
269
275
 
270
276
  def self.empty_config
@@ -303,7 +309,7 @@ module Diggit
303
309
  end
304
310
 
305
311
  def self.plugin_paths(name, type, root)
306
- Dir.glob(File.join(root, 'plugins', type.to_s, '**', "#{name}.rb"))
312
+ Dir.glob(File.join(root, 'plugins', type.to_s, '**{,/*/**}', "#{name}.rb"))
307
313
  end
308
314
 
309
315
  # Constructor. Should not be called directly. Use {.instance} instead.
@@ -386,7 +392,7 @@ module Diggit
386
392
  end
387
393
 
388
394
  # Initialize and return the diggit instance into the given folder.
389
- # @param folder the path to the folder.
395
+ # @param folder [String] the path to the folder.
390
396
  # @return [Dig] the instance.
391
397
  def self.init(folder = '.')
392
398
  @diggit = Dig.new(folder)
@@ -401,7 +407,7 @@ module Diggit
401
407
  # It creates a +sources+ folder.
402
408
  # It creates a +plugins+ folder.
403
409
  # Directory creation is skipped if folder already exist.
404
- # @param folder the path to the folder.
410
+ # @param folder [String] the path to the folder.
405
411
  # @return [void]
406
412
  def self.init_dir(folder = '.')
407
413
  dgit_folder = File.expand_path(DGIT_FOLDER, folder)
@@ -541,7 +547,7 @@ module Diggit
541
547
 
542
548
  def clean_analysis(s, a)
543
549
  a.clean
544
- s.del_analysis(a.name)
550
+ s.clean_analysis(a)
545
551
  ensure
546
552
  save_journal
547
553
  end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  require 'formatador'
22
21
 
@@ -48,7 +47,7 @@ class Formatador
48
47
  end
49
48
 
50
49
  def self.visible(method)
51
- target = method.to_sym
50
+ target = method.to_sym
52
51
  if target == :ok || target == :error || target == :info
53
52
  true
54
53
  elsif (target == :warn || target == :debug) && level == :fine
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  require_relative 'core'
22
21
 
@@ -33,13 +32,27 @@ module Diggit
33
32
  @options = options
34
33
  end
35
34
 
35
+ # Returns the name of the plugin class
36
+ # @return [String]
36
37
  def name
37
38
  self.class.name
38
39
  end
39
40
 
41
+ # Returns the name of the plugin class
42
+ # @return [String]
40
43
  def self.name
41
44
  to_s.underscore
42
45
  end
46
+
47
+ # Returns the value of a plugin option
48
+ # @param ns [Symbol] the name of the option's namespace
49
+ # @param opt [Symbol] the name of the option
50
+ # @param default [Object] the default value
51
+ # @return [Object]
52
+ def read_option(ns, opt, default)
53
+ return @options[ns][opt] if @options.key?(ns) && @options[ns].key?(opt)
54
+ default
55
+ end
43
56
  end
44
57
 
45
58
  class Addon < Plugin
@@ -48,7 +61,9 @@ module Diggit
48
61
  end
49
62
  end
50
63
 
51
- # Base class for analyses and joins. Runnables can be runned or cleaned.
64
+ # Base class for analyses and joins.
65
+ # Runnables can be runned or cleaned.
66
+ # A clean of a runnable should always work, even if it has never been run.
52
67
  # These methods have to be implemented in the subclasses.
53
68
  # Addons can be made available to a runnable through a call to {.require\_addons}.
54
69
  # Addons can be accessed through the addons attribute, and they contain
@@ -81,7 +96,7 @@ module Diggit
81
96
 
82
97
  # Add an addon as a required addon.
83
98
  #
84
- # @param names Array<String> the names of addons to require.
99
+ # @param names [Array<String>] the names of addons to require.
85
100
  # They correspond to the name of their class with underscore case.
86
101
  # @return [void]
87
102
  def self.require_addons(*names)
@@ -89,8 +104,9 @@ module Diggit
89
104
  end
90
105
 
91
106
  def self.required_addons
92
- return [] if @required_addons.nil?
93
- @required_addons
107
+ base_addons = superclass < Runnable ? superclass.required_addons : []
108
+ return base_addons if @required_addons.nil?
109
+ base_addons + @required_addons
94
110
  end
95
111
  end
96
112
 
@@ -128,7 +144,7 @@ module Diggit
128
144
 
129
145
  # Add an analysis as a required analysis.
130
146
  #
131
- # @param names Array<String> the names of analyses to require.
147
+ # @param names [Array<String>] the names of analyses to require.
132
148
  # They correspond to the name of their class with underscore case.
133
149
  # @return [void]
134
150
  def self.require_analyses(*names)
@@ -169,5 +185,12 @@ module Diggit
169
185
  super(options)
170
186
  @source = nil
171
187
  end
188
+
189
+ # Returns the rugged repository associated to the source.
190
+ #
191
+ # @return [Rugged::Repository]
192
+ def repo
193
+ @source.repository
194
+ end
172
195
  end
173
196
  end
@@ -16,8 +16,7 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  module Diggit
22
- VERSION = "2.0.1"
21
+ VERSION = "2.0.2"
23
22
  end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  require 'mongo'
22
21
 
@@ -26,14 +25,20 @@ require 'mongo'
26
25
  # @!attribute [r] db
27
26
  # @return [Mongo::DB] the mongo database object.
28
27
  class Db < Diggit::Addon
29
- DEFAULT_URL = 'mongodb://127.0.0.1:27017/diggit'
28
+ DEFAULT_SERVER = '127.0.0.1:27017'
29
+ DEFAULT_DB = 'diggit'
30
30
 
31
31
  attr_reader :client
32
32
 
33
33
  def initialize(*args)
34
34
  super
35
- url = DEFAULT_URL
36
- url = @options[:mongo][:url] if @options.key?(:mongo) && @options[:mongo].key?(:url)
37
- @client = Mongo::Client.new(url)
35
+ Mongo::Logger.logger.level = ::Logger::FATAL
36
+ server = read_option(:mongo, :server, DEFAULT_SERVER)
37
+ db = read_option(:mongo, :db, DEFAULT_DB)
38
+ @client = Mongo::Client.new([server], database: db)
39
+ end
40
+
41
+ def insert(collection, data)
42
+ client[collection].bulk_write(data.map { |d| { insert_one: d } }, ordered: true) unless data.empty?
38
43
  end
39
44
  end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  # A output addon for Diggit. The name of the addon is :output, and can be reached in the
22
21
  # addons hash. This addon might use an :output hash in the global options. In this hash, the
@@ -17,7 +17,6 @@
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
19
  # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
- #
21
20
 
22
21
  R = nil # fixing SIGPIPE error in some cases. See http://hfeild-software.blogspot.fr/2013/01/rinruby-woes.html
23
22
 
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of Diggit.
4
+ #
5
+ # Diggit is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Diggit is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
+ # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
+
21
+ # Manages options that are specific to a given source
22
+ class SrcOpt < Diggit::Addon
23
+ SOURCES_OPTIONS_FILE = 'sources_options'
24
+
25
+ def initialize(*args)
26
+ super
27
+ sources_options_path = Diggit::Dig.it.config_path(SOURCES_OPTIONS_FILE)
28
+ @sources_options = {}
29
+ @sources_options = Oj.load_file(sources_options_path) if File.exist? sources_options_path
30
+ end
31
+
32
+ def [](source)
33
+ @sources_options[source.url]
34
+ end
35
+ end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  require 'yaml'
22
21
 
@@ -28,15 +27,22 @@ class Cloc < Diggit::Analysis
28
27
  end
29
28
 
30
29
  def run
31
- cloc = `cloc . --progress-rate=0 --quiet --yaml`
32
- return if cloc.empty?
33
- yaml = YAML.load(cloc.lines[2..-1].join)
34
- yaml.delete('header')
35
- output = { source: @source.url, cloc: yaml }
36
- db.client['cloc'].insert_one(output)
30
+ walker = Rugged::Walker.new(repo)
31
+ walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
32
+ walker.push(repo.head.name)
33
+ walker.each do |c|
34
+ repo.checkout(c.oid, { strategy: [:force, :remove_untracked] })
35
+ cloc = `cloc #{@source.folder} --progress-rate=0 --quiet --yaml`
36
+ next if cloc.empty?
37
+ yaml = YAML.load(cloc.lines[2..-1].join)
38
+ yaml.delete('header')
39
+ output = { source: @source.url, commit: c.oid, cloc: yaml }
40
+ db.client['cloc'].insert_one(output)
41
+ end
37
42
  end
38
43
 
39
44
  def clean
40
- db.client['cloc'].find({ source: @source.url }).delete_one
45
+ db.client['cloc'].find({ source: @source.url }).delete_many
46
+ repo.checkout('master')
41
47
  end
42
48
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of Diggit.
4
+ #
5
+ # Diggit is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Diggit is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
+ # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
+
21
+ class ClocPerFile < Diggit::Analysis
22
+ require_addons 'db', 'src_opt'
23
+
24
+ def run
25
+ commit_oid = src_opt[@source]["cloc-commit-id"] unless src_opt[@source].nil?
26
+ commit_oid = 'HEAD' if commit_oid.nil?
27
+ repo.checkout(commit_oid, { strategy: [:force, :remove_untracked] })
28
+ folder = File.expand_path(@source.folder)
29
+ cloc = `cloc #{folder} --progress-rate=0 --quiet --by-file --yaml --script-lang=Python,python`
30
+ return if cloc.empty?
31
+ yaml = YAML.load(cloc.lines[2..-1].join)
32
+ yaml.delete('header')
33
+ yaml.delete('SUM')
34
+ cloc_a = []
35
+ yaml.each do |key, value|
36
+ # transform the hash so the filenames are not keys anymore (as they may contain a '.' it is incompatible with mongo)
37
+ path = File.expand_path(key).gsub(folder, '').gsub(%r{^/}, '')
38
+ cloc_a << value.merge({ path: path })
39
+ end
40
+ output = { source: @source.url, commit_oid: commit_oid.to_s, cloc: cloc_a }
41
+ col = db.client['cloc-file']
42
+ col.insert_one(output)
43
+ end
44
+
45
+ def clean
46
+ db.client['cloc-file'].find({ source: @source.url }).delete_one
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of Diggit.
4
+ #
5
+ # Diggit is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Diggit is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
+
20
+ require 'fileutils'
21
+
22
+ class Tex < Diggit::Analysis
23
+ require_addons 'out'
24
+
25
+ def initialize(options)
26
+ super(options)
27
+ end
28
+
29
+ def run
30
+ walker = Rugged::Walker.new(repo)
31
+ walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
32
+ walker.push(repo.head.name)
33
+ walker.each do |c|
34
+ repo.checkout(c.oid, { strategy: [:force, :remove_untracked] })
35
+ words = Dir["**/*.tex"].reduce(0) { |a, e| a + `cat "#{e}" | wc -w`.to_i }
36
+ File.open(file, 'a') { |f| f.puts("#{source.url};#{c.oid};#{words}\n") }
37
+ end
38
+ end
39
+
40
+ def clean
41
+ FileUtils.rm_rf(file)
42
+ repo.checkout("master")
43
+ end
44
+
45
+ def file
46
+ "#{out.out}/words.csv"
47
+ end
48
+ end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  require 'spec_helper'
22
21
  require 'fileutils'
@@ -110,9 +109,10 @@ RSpec.describe Diggit::Dig do
110
109
 
111
110
  it "should perform analyses in order" do
112
111
  Diggit::Dig.it.config.add_analysis("test_analysis")
112
+ expect_any_instance_of(TestAnalysis).to receive(:run)
113
113
  Diggit::Dig.it.config.add_analysis("test_analysis_with_addon")
114
+ expect_any_instance_of(TestAnalysisWithAddon).to receive(:run)
114
115
  Diggit::Dig.it.analyze
115
- # expect(TestAnalysis.state).to eq("runned")
116
116
  expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].all_analyses).to eq(%w(test_analysis test_analysis_with_addon))
117
117
  Diggit::Dig.init("spec/dgit")
118
118
  expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].all_analyses).to eq(%w(test_analysis test_analysis_with_addon))
@@ -130,10 +130,38 @@ RSpec.describe Diggit::Dig do
130
130
  it "should perform joins" do
131
131
  Diggit::Dig.it.config.add_join("test_join")
132
132
  Diggit::Dig.it.config.add_join("test_join_with_addon")
133
+ expect_any_instance_of(TestJoin).to receive(:run)
134
+ expect_any_instance_of(TestJoinWithAddon).not_to receive(:run)
133
135
  Diggit::Dig.it.join
134
136
  expect(Diggit::Dig.it.journal.join?("test_join")).to be true
135
- expect(TestJoin.sources.size).to eq 1
136
- expect(TestJoin.sources[0].url).to eq TEST_URL
137
137
  expect(Diggit::Dig.it.journal.join?("test_join_with_addon")).to be false
138
138
  end
139
+
140
+ it "should clean joins" do
141
+ expect_any_instance_of(TestJoin).to receive(:clean)
142
+ expect_any_instance_of(TestJoinWithAddon).to receive(:clean)
143
+ Diggit::Dig.it.join([], [], :clean)
144
+ end
145
+
146
+ it "should clean analyses" do
147
+ expect_any_instance_of(TestAnalysis).to receive(:clean)
148
+ expect_any_instance_of(TestAnalysisWithAddon).to receive(:clean)
149
+ Diggit::Dig.it.analyze([], [], :clean)
150
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].all_analyses).to eq([])
151
+ end
152
+
153
+ it "should read source options" do
154
+ File.open("spec/dgit/.dgit/sources_options", "w") do |f|
155
+ f.write('{
156
+ "https://github.com/jrfaller/test-git.git":{
157
+ "myOption":"myValue"
158
+ }
159
+ }')
160
+ end
161
+
162
+ Diggit::Dig.it.config.add_analysis("test_analysis_with_sources_options")
163
+ expect { Diggit::Dig.it.analyze }.to output(/myValue/).to_stdout
164
+ Diggit::Dig.it.analyze([], [], :clean)
165
+ Diggit::Dig.it.config.del_analysis("test_analysis_with_sources_options")
166
+ end
139
167
  end
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestAddon < Diggit::Addon
22
21
  def foo
@@ -17,7 +17,6 @@
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
19
  # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
- #
21
20
 
22
21
  class DuplicateAnalysis < Diggit::Analysis
23
22
  def run
@@ -17,7 +17,6 @@
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
19
  # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
- #
21
20
 
22
21
  module MyModule
23
22
  class DuplicateAnalysis < Diggit::Analysis
@@ -17,7 +17,6 @@
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
19
  # Copyright 2015 Matthieu Foucault <foucaultmatthieu@gmail.com>
20
- #
21
20
 
22
21
  module MyModule
23
22
  class OtherAnalysis < Diggit::Analysis
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestAnalysis < Diggit::Analysis
22
21
  def run
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestAnalysisWithAddon < Diggit::Analysis
22
21
  require_addons "test_addon"
@@ -16,7 +16,6 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestAnalysisWithError < Diggit::Analysis
22
21
  def run
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of Diggit.
4
+ #
5
+ # Diggit is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Diggit is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
+ #
20
+
21
+ class TestAnalysisWithSourcesOptions < Diggit::Analysis
22
+ require_addons "src_opt"
23
+
24
+ def initialize(*args)
25
+ super(args)
26
+ end
27
+
28
+ def run
29
+ p(src_opt[@source]["myOption"])
30
+ end
31
+
32
+ def clean
33
+ end
34
+ end
@@ -16,18 +16,13 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestJoin < Diggit::Join
22
21
  require_analyses 'test_analysis'
23
22
 
24
- class << self
25
- attr_accessor :sources
23
+ def run
26
24
  end
27
25
 
28
- @sources = nil
29
-
30
- def run
31
- self.class.sources = @sources
26
+ def clean
32
27
  end
33
28
  end
@@ -16,9 +16,14 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
20
19
 
21
20
  class TestJoinWithAddon < Diggit::Join
22
21
  require_addons 'test_addon'
23
22
  require_analyses 'test_analysis_with_error'
23
+
24
+ def run
25
+ end
26
+
27
+ def clean
28
+ end
24
29
  end
@@ -16,7 +16,7 @@
16
16
  # along with Diggit. If not, see <http://www.gnu.org/licenses/>.
17
17
  #
18
18
  # Copyright 2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
19
- #
19
+
20
20
  require 'coveralls'
21
21
  Coveralls.wear!
22
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diggit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Rémy Falleri
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-05 00:00:00.000000000 Z
12
+ date: 2015-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rugged
@@ -173,7 +173,10 @@ files:
173
173
  - plugins/addon/db.rb
174
174
  - plugins/addon/out.rb
175
175
  - plugins/addon/r.rb
176
+ - plugins/addon/src_opt.rb
176
177
  - plugins/analysis/cloc.rb
178
+ - plugins/analysis/cloc_per_file.rb
179
+ - plugins/analysis/tex.rb
177
180
  - spec/core_spec.rb
178
181
  - spec/dgit/plugins/addon/test_addon.rb
179
182
  - spec/dgit/plugins/analysis/duplicate_analysis.rb
@@ -182,6 +185,7 @@ files:
182
185
  - spec/dgit/plugins/analysis/test_analysis.rb
183
186
  - spec/dgit/plugins/analysis/test_analysis_with_addon.rb
184
187
  - spec/dgit/plugins/analysis/test_analysis_with_error.rb
188
+ - spec/dgit/plugins/analysis/test_analysis_with_sources_options.rb
185
189
  - spec/dgit/plugins/join/test_join.rb
186
190
  - spec/dgit/plugins/join/test_join_with_addon.rb
187
191
  - spec/spec_helper.rb
@@ -205,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
209
  version: '0'
206
210
  requirements: []
207
211
  rubyforge_project:
208
- rubygems_version: 2.4.5
212
+ rubygems_version: 2.4.5.1
209
213
  signing_key:
210
214
  specification_version: 4
211
215
  summary: A Git repository analysis tool.