taeval 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +37 -0
  8. data/LICENSE +201 -0
  9. data/README.md +36 -0
  10. data/Rakefile +31 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bin/taeval +9 -0
  14. data/config/config.yml +27 -0
  15. data/config/hadolint.yml +10 -0
  16. data/config/plagium.yml +12 -0
  17. data/config/report.csv +0 -0
  18. data/config/students.csv +4 -0
  19. data/config/taeval +11 -0
  20. data/config/unittest.yml +8 -0
  21. data/lib/taeval.rb +27 -0
  22. data/lib/taeval/cli.rb +26 -0
  23. data/lib/taeval/config_manager.rb +33 -0
  24. data/lib/taeval/executor.rb +29 -0
  25. data/lib/taeval/file_helper.rb +40 -0
  26. data/lib/taeval/git_checkout/bitbucket_repo.rb +74 -0
  27. data/lib/taeval/git_checkout/config.rb +35 -0
  28. data/lib/taeval/git_checkout/github_repo.rb +65 -0
  29. data/lib/taeval/git_checkout/gitlab_repo.rb +86 -0
  30. data/lib/taeval/git_checkout/repo_factory.rb +25 -0
  31. data/lib/taeval/git_checkout/runner.rb +40 -0
  32. data/lib/taeval/hadolint/config.rb +23 -0
  33. data/lib/taeval/hadolint/runner.rb +29 -0
  34. data/lib/taeval/output.rb +17 -0
  35. data/lib/taeval/plagium/config.rb +28 -0
  36. data/lib/taeval/plagium/runner.rb +46 -0
  37. data/lib/taeval/reporter.rb +27 -0
  38. data/lib/taeval/runner_factory.rb +29 -0
  39. data/lib/taeval/runner_wrapper.rb +14 -0
  40. data/lib/taeval/static_code_analysis/runner.rb +15 -0
  41. data/lib/taeval/unittest/config.rb +21 -0
  42. data/lib/taeval/unittest/runner.rb +59 -0
  43. data/lib/taeval/version.rb +3 -0
  44. data/taeval.gemspec +36 -0
  45. metadata +147 -0
@@ -0,0 +1,25 @@
1
+
2
+ require 'taeval/git_checkout/github_repo'
3
+ require 'taeval/git_checkout/gitlab_repo'
4
+ require 'taeval/git_checkout/bitbucket_repo'
5
+
6
+ module Taeval
7
+ module GitCheckout
8
+ class RepoFactory
9
+
10
+ def self.create(config, output, reporter)
11
+ case config[:host].to_sym
12
+ when :github
13
+ Taeval::GitCheckout::GithubRepo.new(config, output, reporter)
14
+ when :gitlab
15
+ Taeval::GitCheckout::GitlabRepo.new(config, output, reporter)
16
+ when :bitbucket
17
+ Taeval::GitCheckout::BitbucketRepo.new(config, output, reporter)
18
+ else
19
+ reporter.add(repo: config[:id], runner: :git_checkout, msg: "#{config[:host]} is not supported")
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+
2
+ require 'open3'
3
+ require 'json'
4
+
5
+ require 'taeval/git_checkout/config'
6
+ require 'taeval/git_checkout/repo_factory'
7
+
8
+ module Taeval
9
+ module GitCheckout
10
+ class Runner
11
+
12
+ def initialize(config, output, reporter)
13
+ @config = Config.new(config)
14
+ @output = output
15
+ @reporter = reporter
16
+ end
17
+
18
+ def run
19
+ @config.source.each do |source|
20
+ repo = RepoFactory.create(
21
+ {host: source[:host],
22
+ id: source[:id],
23
+ user: source[:user],
24
+ repo: source[:repo],
25
+ prefix: @config.prefix,
26
+ branch: @config.branch,
27
+ token: @config.tokens[source[:host]],
28
+ attr: @config.attr,
29
+ solution: @config.solution},
30
+ @output,
31
+ @reporter
32
+ )
33
+ repo.validate
34
+ repo.clone
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module Taeval
3
+ module Hadolint
4
+ class Config
5
+ include Taeval::FileHelper
6
+
7
+ attr_reader :path, :solutions
8
+
9
+ def initialize(conf_h)
10
+ @path = path_of(conf_h.fetch('path', ''))
11
+ if !File.exist?(@path)
12
+ raise "Path of hadolint (#{@path}) does not exist."
13
+ end
14
+
15
+ @solutions = path_of(conf_h.dig('solution', 'path'))
16
+ if !File.exist?(@solutions)
17
+ raise "Path of solutions (#{@solutions}) does not exist."
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'open3'
3
+ require 'taeval/hadolint/config'
4
+
5
+ module Taeval
6
+ module Hadolint
7
+ class Runner
8
+ def initialize(config, output, reporter)
9
+ @config = Config.new(config)
10
+ @output = output
11
+ @reporter = reporter
12
+ end
13
+
14
+ def run
15
+ solutions = Dir.glob("#{@config.solutions}/*")
16
+ solutions.each do |repo|
17
+ cmd = "docker run --rm -i -v #{@config.path}:/root/.config/hadolint.yaml hadolint/hadolint < #{repo}/docker/Dockerfile"
18
+ stdout, stderr, status = Open3.capture3(cmd)
19
+ @output.print "hadolint #{repo}/Dockerfile", stdout, stderr
20
+
21
+ if 0 != status
22
+ @reporter.add(repo: repo, runner: :hadolint, msg: "Status: #{status} Error: #{stderr}.") if !stderr.empty?
23
+ @reporter.add(repo: repo, runner: :hadolint, msg: "Status: #{status} Message: #{stdout}.") if !stdout.empty?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Taeval
3
+ class Output
4
+ def initialize(conf_h)
5
+ @verbose = conf_h.fetch('verbose', false)
6
+ end
7
+
8
+ def print(header, stdout = '', stderr = '')
9
+ if @verbose
10
+ puts "\e[95m#{header}\e[0m"
11
+ puts "\e[97m#{stdout}\e[0m" if !stdout.nil? && !stdout.empty?
12
+ puts "\e[91m#{stderr}\e[0m" if !stderr.nil? && !stderr.empty?
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+
2
+ module Taeval
3
+ module Plagium
4
+ class Config
5
+ include Taeval::FileHelper
6
+
7
+ attr_reader :solutions, :id, :language, :max_matches, :show_num_matches, :comment, :output, :reject
8
+
9
+ def initialize(conf_h)
10
+ @id = conf_h.fetch('id', '')
11
+ @language = conf_h.fetch('language', 'ascii')
12
+ @max_matches = conf_h.fetch('max_matches', 10)
13
+ @show_num_matches = conf_h.fetch('show_num_matches', 250)
14
+ @comment = conf_h.fetch('comment', '')
15
+
16
+ output_path = conf_h.fetch('output', '')
17
+ @output = File.new(path_of(output_path), 'w')
18
+
19
+ @reject = conf_h.fetch('reject', '')
20
+ @solutions = path_of(conf_h.dig('solution', 'path'))
21
+ if !File.exist?(@solutions)
22
+ raise "Plagium: Path of input solutions not exists: #{@solutions}"
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+
2
+ require 'moss_ruby'
3
+ require 'taeval/plagium/config'
4
+
5
+ module Taeval
6
+ module Plagium
7
+ class Runner
8
+
9
+ def initialize(config, output, reporter)
10
+ @config = Config.new(config)
11
+ @output = output
12
+ @reporter = reporter
13
+ end
14
+
15
+ def run
16
+ moss = MossRuby.new(@config.id)
17
+
18
+ # Set options -- the options will already have these default values
19
+ moss.options[:max_matches] = @config.max_matches
20
+ moss.options[:show_num_matches] = @config.show_num_matches
21
+ moss.options[:comment] = @config.comment
22
+ moss.options[:language] = @config.language
23
+
24
+ @output.print "checking similarity"
25
+ to_check = MossRuby.empty_file_hash
26
+
27
+ solutions = Dir.glob("#{@config.solutions}/**/*.#{@config.language}")
28
+ .reject { |file| @config.reject.any? { |pattern| file.include?(pattern) } }
29
+
30
+ solutions.each do |file|
31
+ MossRuby.add_file(to_check, file)
32
+ end
33
+
34
+ # Get server to process files
35
+ url = moss.check(to_check)
36
+ @output.print "url: #{url}"
37
+
38
+ @config.output.puts(@config.comment)
39
+ @config.output.puts(url)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+
46
+
@@ -0,0 +1,27 @@
1
+
2
+ require 'json'
3
+ require 'taeval/file_helper'
4
+
5
+ module Taeval
6
+ class Reporter
7
+ include Taeval::FileHelper
8
+
9
+ def initialize(conf_h)
10
+ @path = path_of(conf_h.dig('report', 'path'))
11
+ @records = {}
12
+ end
13
+
14
+ def add(data)
15
+ @records[data[:repo]] = {} if !@records.has_key?(data[:repo])
16
+ @records[data[:repo]][data[:runner]] = [] if !@records[data[:repo]].has_key?(data[:runner])
17
+ @records[data[:repo]][data[:runner]] << data[:msg]
18
+ end
19
+
20
+ def save
21
+ p "Reporter#save..."
22
+ File.open(@path,'w') do |f|
23
+ f.write(@records.to_json)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'taeval/git_checkout/runner'
3
+ require 'taeval/plagium/runner'
4
+ require 'taeval/static_code_analysis/runner'
5
+ require 'taeval/unittest/runner'
6
+ require 'taeval/hadolint/runner'
7
+
8
+ module Taeval
9
+ class RunnerFactory
10
+
11
+ def self.create(runner, *config, output, reporter)
12
+ case runner
13
+ when :git_checkout
14
+ Taeval::GitCheckout::Runner.new(*config, output, reporter)
15
+ when :plagium
16
+ Taeval::Plagium::Runner.new(*config, output, reporter)
17
+ #when :static_code_analysis
18
+ # Taeval::Runners::StaticCodeAnalysis.new(*config)
19
+ when :unittest
20
+ Taeval::Unittest::Runner.new(*config, output, reporter)
21
+ when :hadolint
22
+ Taeval::Hadolint::Runner.new(*config, output, reporter)
23
+ else
24
+ raise "Runner does not exist. (#{ runner })"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module Taeval
3
+ class RunnerWrapper
4
+
5
+ def initialize(executor)
6
+ @executor = executor
7
+ end
8
+
9
+ def run(runner)
10
+ @executor.add(runner)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module Taeval
3
+ module Runners
4
+ class StaticCodeAnalysis
5
+
6
+ def initialize(*config)
7
+ @config = config
8
+ end
9
+
10
+ def run
11
+ p "StaticCodeAnalysis#run"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module Taeval
3
+ module Unittest
4
+ class Config
5
+ include Taeval::FileHelper
6
+
7
+ attr_reader :tool, :cmd, :solutions, :original
8
+
9
+ def initialize(conf_h)
10
+ @tool = conf_h.dig('build', 'tool')
11
+ @cmd = conf_h.dig('build', 'cmd')
12
+ @original = path_of(conf_h.fetch('original', ''))
13
+ if !File.exist?(@original)
14
+ raise "Unittest: #{@original} does not exist"
15
+ end
16
+ @solutions = path_of(conf_h.dig('solution', 'path'))
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+
2
+ require 'open3'
3
+ require 'taeval/unittest/config'
4
+
5
+ module Taeval
6
+ module Unittest
7
+ class Runner
8
+
9
+
10
+ def initialize(config, output, reporter)
11
+ @config = Config.new(config)
12
+ @output = output
13
+ @reporter = reporter
14
+ end
15
+
16
+ def run
17
+ cp_original
18
+
19
+ if !@config.cmd.nil?
20
+ cmd = @config.cmd
21
+ elsif !@config.tool.nil?
22
+ case @config.tool.to_sym
23
+ when :gradle
24
+ cmd = 'gradle test'
25
+ else
26
+ raise "Unittest: #{@config.tool} is not supported."
27
+ end
28
+ else
29
+ raise 'Unittest: Unittest\'s tool or cmd should be defined.'
30
+ end
31
+
32
+ exec(cmd)
33
+ end
34
+
35
+ private
36
+
37
+ def cp_original
38
+ Dir.glob("#{@config.solutions}/*").each do |solution|
39
+ begin
40
+ FileUtils.cp_r(Dir.glob("#{@config.original}/unittest/*"), "#{solution}/unittest")
41
+ rescue => e
42
+ repo = solution.split('/').last
43
+ @reporter.add(repo: repo, runner: :unittest, msg: "#{repo}, #{e.message}")
44
+ end
45
+ end
46
+ end
47
+
48
+ def exec(cmd)
49
+ Dir.glob("#{@config.solutions}/*").each do |solution|
50
+ stdout, stderr, status = Open3.capture3(cmd, chdir: "#{solution}/unittest")
51
+
52
+ @output.print "Executing #{cmd} in #{solution}", stdout, stderr
53
+
54
+ @reporter.add(repo: solution.split('/').last, runner: :unittest, msg: "'#{cmd}' in #{solution}/unittest failed, status = #{status.exitstatus}") if status.exitstatus != 0
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Taeval
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'lib/taeval/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "taeval"
5
+ spec.version = Taeval::VERSION
6
+ spec.authors = ["Torok Mark"]
7
+ spec.email = ["torok.marko@gmail.com"]
8
+
9
+ spec.summary = %q{RubyGem to evaluate homework.}
10
+ spec.description = %q{RubyGem to evaluate test automation homework.}
11
+ spec.homepage = "https://github.com/torokmark/taeval"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ if spec.respond_to?(:metadata)
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+
27
+ spec.require_paths = ["lib", 'bin', 'config']
28
+ spec.bindir = 'bin'
29
+ spec.executables << 'taeval'
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
+ spec.add_development_dependency "rspec", "~> 3.9"
34
+
35
+ spec.add_runtime_dependency "moss_ruby"
36
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taeval
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Torok Mark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: moss_ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: RubyGem to evaluate test automation homework.
70
+ email:
71
+ - torok.marko@gmail.com
72
+ executables:
73
+ - taeval
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - bin/taeval
89
+ - config/config.yml
90
+ - config/hadolint.yml
91
+ - config/plagium.yml
92
+ - config/report.csv
93
+ - config/students.csv
94
+ - config/taeval
95
+ - config/unittest.yml
96
+ - lib/taeval.rb
97
+ - lib/taeval/cli.rb
98
+ - lib/taeval/config_manager.rb
99
+ - lib/taeval/executor.rb
100
+ - lib/taeval/file_helper.rb
101
+ - lib/taeval/git_checkout/bitbucket_repo.rb
102
+ - lib/taeval/git_checkout/config.rb
103
+ - lib/taeval/git_checkout/github_repo.rb
104
+ - lib/taeval/git_checkout/gitlab_repo.rb
105
+ - lib/taeval/git_checkout/repo_factory.rb
106
+ - lib/taeval/git_checkout/runner.rb
107
+ - lib/taeval/hadolint/config.rb
108
+ - lib/taeval/hadolint/runner.rb
109
+ - lib/taeval/output.rb
110
+ - lib/taeval/plagium/config.rb
111
+ - lib/taeval/plagium/runner.rb
112
+ - lib/taeval/reporter.rb
113
+ - lib/taeval/runner_factory.rb
114
+ - lib/taeval/runner_wrapper.rb
115
+ - lib/taeval/static_code_analysis/runner.rb
116
+ - lib/taeval/unittest/config.rb
117
+ - lib/taeval/unittest/runner.rb
118
+ - lib/taeval/version.rb
119
+ - taeval.gemspec
120
+ homepage: https://github.com/torokmark/taeval
121
+ licenses: []
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ homepage_uri: https://github.com/torokmark/taeval
125
+ source_code_uri: https://github.com/torokmark/taeval
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ - bin
131
+ - config
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.3.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.1.4
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: RubyGem to evaluate homework.
147
+ test_files: []