diggit 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'formatador'
4
+
5
+ class Formatador
6
+ def self.info_i(str, indent = 1)
7
+ info("#{'\t' * indent}#{str}")
8
+ end
9
+
10
+ def self.info(str)
11
+ Formatador.display_line(str)
12
+ end
13
+
14
+ def self.ok_i(str, indent = 1)
15
+ ok("#{'\t' * indent}#{str}")
16
+ end
17
+
18
+ def self.ok(str)
19
+ Formatador.display_line("[green]#{str}[/]")
20
+ end
21
+
22
+ def self.error_i(str, indent = 1)
23
+ error("#{'\t' * indent}#{str}")
24
+ end
25
+
26
+ def self.error(str)
27
+ Formatador.display_line("[red]#{str}[/]")
28
+ end
29
+ end
30
+
31
+ Log = Formatador
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'core'
4
+
5
+ module Diggit
6
+ class Plugin
7
+ attr_reader :options
8
+
9
+ def initialize(options)
10
+ @options = options
11
+ end
12
+
13
+ def name
14
+ self.class.name
15
+ end
16
+
17
+ def self.name
18
+ to_s.underscore
19
+ end
20
+ end
21
+
22
+ class Addon < Plugin
23
+ def initialize(options)
24
+ super(options)
25
+ end
26
+ end
27
+
28
+ class Runnable < Plugin
29
+ attr_reader :addons
30
+
31
+ def initialize(options)
32
+ super(options)
33
+ @addons = {}
34
+ self.class.required_addons.each { |a| @addons[a] = Dig.it.plugin_loader.load_plugin(a, :addon, true) }
35
+ @addons.each_key { |a| self.class.class_eval { define_method(a) { return @addons[a] } } }
36
+ end
37
+
38
+ def run
39
+ end
40
+
41
+ def clean
42
+ end
43
+
44
+ def self.required_addons
45
+ return [] if @required_addons.nil?
46
+ @required_addons
47
+ end
48
+
49
+ def self.require_addons(*names)
50
+ @required_addons = names
51
+ end
52
+ end
53
+
54
+ class Join < Runnable
55
+ attr_accessor :sources
56
+
57
+ def initialize(options)
58
+ super(options)
59
+ @sources = []
60
+ end
61
+
62
+ def self.required_analyses
63
+ return [] if @required_analyses.nil?
64
+ @required_analyses
65
+ end
66
+
67
+ def self.require_analyses(*names)
68
+ @required_analyses = names
69
+ end
70
+ end
71
+
72
+ class Analysis < Runnable
73
+ attr_accessor :source
74
+
75
+ def initialize(options)
76
+ super(options)
77
+ @source = nil
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Diggit
4
+ VERSION = "2.0.0"
5
+ end
data/spec/core_spec.rb ADDED
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'fileutils'
5
+
6
+ FileUtils.rm_rf('spec/dgit/.dgit')
7
+ FileUtils.rm_rf('spec/dgit/sources')
8
+
9
+ RSpec.describe Diggit::Dig do
10
+ it "should refuse to be launched outside a dgit folder" do
11
+ expect { Diggit::Dig.init("spec/dgit") }.to raise_error(/is not a diggit folder/)
12
+ end
13
+
14
+ it "should initialize a dgit folder" do
15
+ expect { Diggit::Dig.init("spec/dgit") }.to raise_error(/is not a diggit folder/)
16
+ Diggit::Dig.init_dir("spec/dgit")
17
+ diggit = Diggit::Dig.init("spec/dgit")
18
+ expect(diggit.config.to_hash).to eq(Diggit::Config.empty_config)
19
+ end
20
+
21
+ it "should not load a plugin with bad type" do
22
+ expect { Diggit::Dig.it.plugin_loader.load_plugin("test_addon", :foo) }.to raise_error(/Unknown plugin type/)
23
+ expect { Diggit::Dig.it.plugin_loader.load_plugin("test_addon", :analysis) }.to raise_error(/not found./)
24
+ end
25
+
26
+ it "should load an addon" do
27
+ addon = Diggit::Dig.it.plugin_loader.load_plugin("test_addon", :addon)
28
+ expect(addon.to_s).to eq("TestAddon")
29
+ addon2 = Diggit::Dig.it.plugin_loader.load_plugin("test_addon", :addon)
30
+ expect(addon2.to_s).to eq("TestAddon")
31
+ end
32
+
33
+ it "should load an analysis" do
34
+ analysis = Diggit::Dig.it.plugin_loader.load_plugin("test_analysis", :analysis)
35
+ expect(analysis.to_s).to eq('TestAnalysis')
36
+ analysis = Diggit::Dig.it.plugin_loader.load_plugin("test_analysis_with_addon", :analysis)
37
+ expect(analysis.to_s).to eq('TestAnalysisWithAddon')
38
+ analysis_instance = analysis.new({})
39
+ expect(analysis_instance.test_addon.foo).to eq("Foo.")
40
+ end
41
+
42
+ it "should load a join" do
43
+ join = Diggit::Dig.it.plugin_loader.load_plugin("test_join", :join)
44
+ expect(join.to_s).to eq('TestJoin')
45
+ join = Diggit::Dig.it.plugin_loader.load_plugin("test_join_with_addon", :join)
46
+ expect(join.to_s).to eq('TestJoinWithAddon')
47
+ join_instance = join.new({})
48
+ expect(join_instance.test_addon.foo).to eq("Foo.")
49
+ end
50
+
51
+ it "should store analyses and joins" do
52
+ Diggit::Dig.it.config.add_analysis("test_analysis")
53
+ Diggit::Dig.init("spec/dgit")
54
+ expect(Diggit::Dig.it.config.to_hash).to eq({ analyses: ['test_analysis'], joins: [] })
55
+ Diggit::Dig.it.config.del_analysis("test_analysis")
56
+ Diggit::Dig.init("spec/dgit")
57
+ expect(Diggit::Dig.it.config.to_hash).to eq({ analyses: [], joins: [] })
58
+ Diggit::Dig.it.config.add_join("test_join")
59
+ Diggit::Dig.init("spec/dgit")
60
+ expect(Diggit::Dig.it.config.to_hash).to eq({ analyses: [], joins: ['test_join'] })
61
+ Diggit::Dig.it.config.del_join("test_join")
62
+ Diggit::Dig.init("spec/dgit")
63
+ expect(Diggit::Dig.it.config.to_hash).to eq({ analyses: [], joins: [] })
64
+ end
65
+
66
+ it "should store sources" do
67
+ Diggit::Dig.it.journal.add_source(TEST_URL)
68
+ Diggit::Dig.init("spec/dgit")
69
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].url).to eq TEST_URL
70
+ end
71
+
72
+ it "should clone sources" do
73
+ Diggit::Dig.it.clone
74
+ expect(File.exist?("spec/dgit/sources/#{TEST_URL.id}/.git")).to be true
75
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].url).to eq TEST_URL
76
+ Diggit::Dig.it.journal.sources_by_ids(0)[0].state = :new
77
+ Diggit::Dig.it.clone
78
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].url).to eq TEST_URL
79
+ Diggit::Dig.init("spec/dgit")
80
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].url).to eq TEST_URL
81
+ end
82
+
83
+ it "should perform analyses" do
84
+ Diggit::Dig.it.config.add_analysis("test_analysis")
85
+ Diggit::Dig.it.analyze
86
+ # expect(TestAnalysis.state).to eq("runned")
87
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].analysis?('test_analysis')).to be true
88
+ Diggit::Dig.init("spec/dgit")
89
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].analysis?('test_analysis')).to be true
90
+ end
91
+
92
+ it "should handle analyses with error" do
93
+ Diggit::Dig.it.config.add_analysis("test_analysis_with_error")
94
+ Diggit::Dig.it.analyze
95
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].analysis?('test_analysis')).to be true
96
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].error?).to be true
97
+ expect(Diggit::Dig.it.journal.sources_by_ids(0)[0].error[:message]).to eq("Error!")
98
+ end
99
+
100
+ it "should perform joins" do
101
+ Diggit::Dig.it.config.add_join("test_join")
102
+ Diggit::Dig.it.config.add_join("test_join_with_addon")
103
+ Diggit::Dig.it.join
104
+ expect(Diggit::Dig.it.journal.join?("test_join")).to be true
105
+ expect(TestJoin.sources.size).to eq 1
106
+ expect(TestJoin.sources[0].url).to eq TEST_URL
107
+ expect(Diggit::Dig.it.journal.join?("test_join_with_addon")).to be false
108
+ end
109
+ end
@@ -1,13 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class TestAddon < Diggit::Addon
4
-
5
- def initialize(*args)
6
- super
7
- end
8
-
9
- def name
10
- :test
4
+ def foo
5
+ "Foo."
11
6
  end
12
-
13
7
  end
@@ -1,13 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class TestAnalysis < Diggit::Analysis
4
-
5
4
  def run
6
- puts "TestAnalysis performed"
5
+ @state = "runned"
7
6
  end
8
7
 
9
8
  def clean
10
- puts "TestAnalysis cleaned on #{@source}"
9
+ @state = "cleaned"
11
10
  end
12
-
13
11
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ class TestAnalysisWithAddon < Diggit::Analysis
4
+ require_addons "test_addon"
5
+
6
+ attr_reader :foo
7
+
8
+ def initialize(*args)
9
+ super(args)
10
+ @foo = nil
11
+ end
12
+
13
+ def run
14
+ @foo = "foo"
15
+ end
16
+
17
+ def clean
18
+ @foo = nil
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class TestAnalysisWithError < Diggit::Analysis
4
+ def run
5
+ raise "Error!"
6
+ end
7
+
8
+ def clean
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ class TestJoin < Diggit::Join
4
+ require_analyses 'test_analysis'
5
+
6
+ class << self
7
+ attr_accessor :sources
8
+ end
9
+
10
+ @sources = nil
11
+
12
+ def run
13
+ self.class.sources = @sources
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ class TestJoinWithAddon < Diggit::Join
4
+ require_addons 'test_addon'
5
+ require_analyses 'test_analysis_with_error'
6
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,31 +1,7 @@
1
- require 'oj'
1
+ # encoding: utf-8
2
+ require 'coveralls'
3
+ Coveralls.wear!
2
4
 
3
- require_relative('../lib/diggit_cli')
5
+ require_relative('../lib/dgit')
4
6
 
5
- $0 = "grit"
6
- ARGV.clear
7
-
8
- def config
9
- return Oj.load_file(Diggit::DIGGIT_RC)
10
- end
11
-
12
- def log
13
- return Oj.load_file(Diggit::DIGGIT_LOG)
14
- end
15
-
16
- def sources
17
- return IO.readlines(Diggit::DIGGIT_SOURCES).map{ |line| line.strip }
18
- end
19
-
20
- def capture(stream)
21
- begin
22
- stream = stream.to_s
23
- eval "$#{stream} = StringIO.new"
24
- yield
25
- result = eval("$#{stream}").string
26
- ensure
27
- eval("$#{stream} = #{stream.upcase}")
28
- end
29
-
30
- result
31
- end
7
+ TEST_URL = 'https://github.com/jrfaller/test-git.git'
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: 1.0.3
4
+ version: 2.0.0
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-01-01 00:00:00.000000000 Z
12
+ date: 2015-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rugged
@@ -40,35 +40,35 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.10'
42
42
  - !ruby/object:Gem::Dependency
43
- name: thor
43
+ name: gli
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.19'
48
+ version: '2.13'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0.19'
55
+ version: '2.13'
56
56
  - !ruby/object:Gem::Dependency
57
- name: mongo
57
+ name: formatador
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.11'
62
+ version: '0.2'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.11'
69
+ version: '0.2'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rinruby
71
+ name: mongo
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
@@ -109,8 +109,38 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.8'
112
- description: |
113
- The Diggit repository analysis tool is a neat swiss knife to enable the analysis of many Git repositories.
112
+ - !ruby/object:Gem::Dependency
113
+ name: rake
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '10.4'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '10.4'
126
+ - !ruby/object:Gem::Dependency
127
+ name: coveralls
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.8'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.8'
140
+ description: 'The Diggit repository analysis tool is a neat swiss knife to enable
141
+ the analysis of many Git repositories.
142
+
143
+ '
114
144
  email: jr.falleri@gmail.com
115
145
  executables:
116
146
  - dgit
@@ -120,21 +150,18 @@ files:
120
150
  - LICENSE
121
151
  - README.md
122
152
  - bin/dgit
123
- - includes/addons/db.rb
124
- - includes/addons/output.rb
125
- - includes/addons/sources_options.rb
126
- - includes/addons/test.rb
127
- - includes/analyses/authors.rb
128
- - includes/analyses/cloc.rb
129
- - includes/analyses/diff_stats.rb
130
- - includes/analyses/metadata.rb
131
- - includes/analyses/pom.rb
132
- - includes/analyses/test.rb
133
- - includes/joins/diff_size.rb
134
- - includes/joins/test.rb
135
- - lib/diggit_cli.rb
136
- - lib/diggit_core.rb
137
- - spec/diggit_spec.rb
153
+ - lib/dgit.rb
154
+ - lib/dgit/core.rb
155
+ - lib/dgit/formatador.rb
156
+ - lib/dgit/plugins.rb
157
+ - lib/dgit/version.rb
158
+ - spec/core_spec.rb
159
+ - spec/dgit/plugins/addon/test_addon.rb
160
+ - spec/dgit/plugins/analysis/test_analysis.rb
161
+ - spec/dgit/plugins/analysis/test_analysis_with_addon.rb
162
+ - spec/dgit/plugins/analysis/test_analysis_with_error.rb
163
+ - spec/dgit/plugins/join/test_join.rb
164
+ - spec/dgit/plugins/join/test_join_with_addon.rb
138
165
  - spec/spec_helper.rb
139
166
  homepage: https://github.com/jrfaller/diggit
140
167
  licenses: