construi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +4 -0
  7. data/Rakefile +7 -0
  8. data/VERSION +1 -0
  9. data/bin/construi +6 -0
  10. data/construi.gemspec +29 -0
  11. data/lib/construi.rb +36 -0
  12. data/lib/construi/config.rb +36 -0
  13. data/lib/construi/container.rb +69 -0
  14. data/lib/construi/image.rb +74 -0
  15. data/lib/construi/version.rb +3 -0
  16. data/spec/sanity_spec.rb +7 -0
  17. data/spec/spec_helper.rb +78 -0
  18. data/vendor/bundle/ruby/1.9.1/build_info/codeclimate-test-reporter-0.4.6.info +1 -0
  19. data/vendor/bundle/ruby/1.9.1/cache/codeclimate-test-reporter-0.4.6.gem +0 -0
  20. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.gitignore +18 -0
  21. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.rspec +2 -0
  22. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.travis.yml +8 -0
  23. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/Gemfile +12 -0
  24. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/LICENSE.txt +40 -0
  25. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/README.md +131 -0
  26. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/Rakefile +6 -0
  27. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/bin/cc-tddium-post-worker +24 -0
  28. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/codeclimate-test-reporter.gemspec +29 -0
  29. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/config/cacert.pem +3895 -0
  30. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter.rb +56 -0
  31. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb +39 -0
  32. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/ci.rb +89 -0
  33. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/client.rb +99 -0
  34. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/configuration.rb +57 -0
  35. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/exception_message.rb +74 -0
  36. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/formatter.rb +114 -0
  37. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/git.rb +68 -0
  38. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb +59 -0
  39. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/version.rb +5 -0
  40. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/codeclimate-test-reporter.rb +8 -0
  41. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/fixtures/encoding_test.rb +6 -0
  42. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/fixtures/encoding_test_iso.rb +6 -0
  43. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/calculate_blob_spec.rb +27 -0
  44. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/ci_spec.rb +26 -0
  45. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/client_spec.rb +24 -0
  46. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/configuration_spec.rb +75 -0
  47. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/formatter_spec.rb +141 -0
  48. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/git_spec.rb +39 -0
  49. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/payload_validator_spec.rb +89 -0
  50. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/test_reporter_spec.rb +36 -0
  51. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/spec_helper.rb +46 -0
  52. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/Makefile +174 -0
  53. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/ext/generator/Makefile +221 -0
  54. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/ext/parser/Makefile +221 -0
  55. data/vendor/bundle/ruby/1.9.1/specifications/codeclimate-test-reporter-0.4.6.gemspec +50 -0
  56. metadata +199 -0
@@ -0,0 +1,68 @@
1
+ module CodeClimate
2
+ module TestReporter
3
+ class Git
4
+
5
+ class << self
6
+ def info
7
+ {
8
+ head: head,
9
+ committed_at: committed_at,
10
+ branch: branch_from_git,
11
+ }
12
+ end
13
+
14
+ def branch_from_git_or_ci
15
+ clean_service_branch || clean_git_branch || "master"
16
+ end
17
+
18
+ def clean_service_branch
19
+ ci_branch = String(Ci.service_data[:branch])
20
+ clean = ci_branch.strip.sub(/^origin\//, "")
21
+
22
+ clean.size > 0 ? clean : nil
23
+ end
24
+
25
+ def clean_git_branch
26
+ git_branch = String(branch_from_git)
27
+ clean = git_branch.sub(/^origin\//, "") unless git_branch.start_with?("(")
28
+
29
+ clean.size > 0 ? clean : nil
30
+ end
31
+
32
+ private
33
+
34
+ def head
35
+ git("log -1 --pretty=format:'%H'")
36
+ end
37
+
38
+ def committed_at
39
+ committed_at = git('log -1 --pretty=format:%ct')
40
+ committed_at.to_i.zero? ? nil : committed_at.to_i
41
+ end
42
+
43
+ def branch_from_git
44
+ git('rev-parse --abbrev-ref HEAD').chomp
45
+ end
46
+
47
+ def git(command)
48
+ `git --git-dir=#{git_dir}/.git #{command}`
49
+ end
50
+
51
+ def git_dir
52
+ return configured_git_dir unless configured_git_dir.nil?
53
+ rails_git_dir_present? ? Rails.root : '.'
54
+ end
55
+
56
+ def configured_git_dir
57
+ CodeClimate::TestReporter.configuration.git_dir
58
+ end
59
+
60
+ def rails_git_dir_present?
61
+ defined?(Rails) && !Rails.root.nil? &&
62
+ File.directory?(File.expand_path('.git', Rails.root))
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,59 @@
1
+ module CodeClimate
2
+ module TestReporter
3
+ InvalidPayload = Class.new(StandardError)
4
+
5
+ class PayloadValidator
6
+ def initialize(payload)
7
+ @payload = payload
8
+ end
9
+
10
+ def self.validate(payload)
11
+ new(payload).validate
12
+ end
13
+
14
+ def validate
15
+ raise InvalidPayload, "A git commit sha was not found in the test report payload" unless commit_sha
16
+ raise InvalidPayload, "A git commit timestamp was not found in the test report payload" unless committed_at
17
+ raise InvalidPayload, "A run at timestamp was not found in the test report payload" unless run_at
18
+ raise InvalidPayload, "No source files were found in the test report payload" unless source_files?
19
+ raise InvalidPayload, "Invalid source files were found in the test report payload" unless valid_source_files?
20
+ true
21
+ end
22
+
23
+ private
24
+
25
+ def commit_sha
26
+ commit_sha_from_git || commit_sha_from_ci_service
27
+ end
28
+
29
+ def committed_at
30
+ @payload[:git] && @payload[:git][:committed_at]
31
+ end
32
+
33
+ def run_at
34
+ @payload[:run_at]
35
+ end
36
+
37
+ def source_files?
38
+ @payload[:source_files] && @payload[:source_files].any?
39
+ end
40
+
41
+ def valid_source_files?
42
+ @payload[:source_files].all? { |s| valid_source_file?(s) }
43
+ end
44
+
45
+ def valid_source_file?(file)
46
+ file.is_a?(Hash) && file[:coverage] && file[:name]
47
+ end
48
+
49
+ def commit_sha_from_git
50
+ @payload[:git] && @payload[:git][:head]
51
+ end
52
+
53
+ def commit_sha_from_ci_service
54
+ @payload[:ci_service] && @payload[:ci_service][:commit_sha]
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module CodeClimate
2
+ module TestReporter
3
+ VERSION = "0.4.6"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "code_climate/test_reporter"
2
+ require "code_climate/test_reporter/calculate_blob"
3
+ require "code_climate/test_reporter/version"
4
+ require "code_climate/test_reporter/client"
5
+ require "code_climate/test_reporter/formatter"
6
+ require "code_climate/test_reporter/configuration"
7
+ require "code_climate/test_reporter/git"
8
+ require "code_climate/test_reporter/ci"
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ class EncodingTest
3
+ def foo
4
+ "ä"
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: iso-8859-1
2
+ class EncodingTest
3
+ def foo
4
+ "�"
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module CodeClimate::TestReporter
4
+
5
+ describe CalculateBlob do
6
+
7
+ subject { CalculateBlob.new(fixture) }
8
+ let(:fixture) { File.expand_path("../../fixtures/encoding_test.rb", __FILE__) }
9
+
10
+ it 'hex digests content of file' do
11
+ expect(subject.blob_id).to_not be_nil
12
+ end
13
+
14
+ context 'encoding error' do
15
+
16
+ let(:fixture) { File.expand_path("../../fixtures/encoding_test_iso.rb", __FILE__) }
17
+
18
+ it 'falls back to git' do
19
+ expect(File).to receive(:open).and_raise(EncodingError)
20
+ expect(subject.blob_id).to eq('eb82c22dadb9c47a7fed87211623f6856e112f46')
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module CodeClimate::TestReporter
4
+ describe Ci do
5
+
6
+ describe '.service_data' do
7
+ before :each do
8
+ @env = {
9
+ 'SEMAPHORE' => 'yes?',
10
+ 'BRANCH_NAME' => 'master',
11
+ 'SEMAPHORE_BUILD_NUMBER' => '1234'
12
+ }
13
+ end
14
+
15
+ it 'returns a hash of CI environment info' do
16
+ expected_semaphore_hash = {
17
+ name: 'semaphore',
18
+ branch: 'master',
19
+ build_identifier: '1234'
20
+ }
21
+
22
+ expect(Ci.service_data(@env)).to include expected_semaphore_hash
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module CodeClimate::TestReporter
4
+ describe Client do
5
+ it 'sets the http timeout per configuration' do
6
+ new_timeout = 969
7
+ CodeClimate::TestReporter.configure do |config|
8
+ config.timeout = new_timeout
9
+ end
10
+
11
+ response = double(:response, code: 200)
12
+ net_http = double(:net_http, request: response)
13
+ allow(Net::HTTP).to receive(:new).
14
+ and_return(net_http)
15
+
16
+ expect(net_http).to receive(:open_timeout=).
17
+ with(new_timeout)
18
+ expect(net_http).to receive(:read_timeout=).
19
+ with(new_timeout)
20
+
21
+ Client.new.post_results("")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'logger'
3
+
4
+ module CodeClimate::TestReporter
5
+ describe Configuration do
6
+ describe 'none given' do
7
+ before do
8
+ CodeClimate::TestReporter.configure
9
+ end
10
+
11
+ it 'provides defaults' do
12
+ expect(CodeClimate::TestReporter.configuration.branch).to be_nil
13
+ expect(CodeClimate::TestReporter.configuration.logger).to be_instance_of Logger
14
+ expect(CodeClimate::TestReporter.configuration.logger.level).to eq Logger::INFO
15
+ expect(CodeClimate::TestReporter.configuration.profile).to eq('test_frameworks')
16
+ expect(CodeClimate::TestReporter.configuration.path_prefix).to be_nil
17
+ expect(CodeClimate::TestReporter.configuration.skip_token).to eq('nocov')
18
+ expect(CodeClimate::TestReporter.configuration.timeout).to eq(Client::DEFAULT_TIMEOUT)
19
+ end
20
+ end
21
+
22
+ describe 'with config block' do
23
+ after do
24
+ CodeClimate::TestReporter.configure
25
+ end
26
+
27
+ it 'stores logger' do
28
+ logger = Logger.new($stderr)
29
+
30
+ CodeClimate::TestReporter.configure do |config|
31
+ logger.level = Logger::DEBUG
32
+ config.logger = logger
33
+ end
34
+
35
+ expect(CodeClimate::TestReporter.configuration.logger).to eq logger
36
+ end
37
+
38
+ it 'stores branch' do
39
+ CodeClimate::TestReporter.configure do |config|
40
+ config.branch = :master
41
+ end
42
+
43
+ expect(CodeClimate::TestReporter.configuration.branch).to eq :master
44
+ end
45
+
46
+ it 'stores profile' do
47
+ CodeClimate::TestReporter.configure do |config|
48
+ config.profile = 'custom'
49
+ end
50
+
51
+ expect(CodeClimate::TestReporter.configuration.profile).to eq('custom')
52
+ end
53
+
54
+ it 'stores path prefix' do
55
+ CodeClimate::TestReporter.configure do |config|
56
+ config.path_prefix = 'custom'
57
+ end
58
+
59
+ expect(CodeClimate::TestReporter.configuration.path_prefix).to eq('custom')
60
+
61
+ CodeClimate::TestReporter.configure do |config|
62
+ config.path_prefix = nil
63
+ end
64
+ end
65
+
66
+ it 'stores timeout' do
67
+ CodeClimate::TestReporter.configure do |config|
68
+ config.timeout = 666
69
+ end
70
+
71
+ expect(CodeClimate::TestReporter.configuration.timeout).to eq(666)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ module CodeClimate::TestReporter
5
+ describe Formatter do
6
+ let(:project_path) { "spec/tmp" }
7
+ let(:project_file) { "fake_project.rb" }
8
+ let(:formatter) { Formatter.new }
9
+ let(:source_files) {
10
+ double(
11
+ :covered_percent => 24.3,
12
+ :covered_strength => 33.2,
13
+ )
14
+ }
15
+ let(:files) {
16
+ [
17
+ double(
18
+ :lines => [double, double, double],
19
+ :covered_lines => [double, double],
20
+ :missed_lines => [double],
21
+ :filename => project_file,
22
+ :coverage => [0,3,2,nil],
23
+ :covered_percent => 33.2,
24
+ :covered_strength => 2
25
+ )
26
+ ]
27
+ }
28
+
29
+ let(:simplecov_result) {
30
+ double(
31
+ :covered_percent => 24.3,
32
+ :covered_strength => 33.2,
33
+ :files => files,
34
+ :source_files => source_files,
35
+ :created_at => Time.at(1379704336),
36
+ :command_name => "rspec"
37
+ )
38
+ }
39
+
40
+ let(:expected_request) {
41
+ {
42
+ "repo_token" => "172754c1bf9a3c698f7770b9fb648f1ebb214425120022d0b2ffc65b97dff531",
43
+ "source_files" =>
44
+ [
45
+ {
46
+ "name" => project_file,
47
+ "blob_id" => "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
48
+ "coverage" => "[0,3,2,null]",
49
+ "covered_percent" => 33.2,
50
+ "covered_strength" => 2.0,
51
+ "line_counts" => {"total"=>3, "covered"=>2, "missed"=>1}
52
+ }
53
+ ],
54
+ "run_at" => 1379704336,
55
+ "covered_percent" => 24.3,
56
+ "covered_strength" => 33.2,
57
+ "line_counts" => {"total" => 3, "covered" => 2, "missed" => 1 },
58
+ "partial"=> false,
59
+ "git" =>
60
+ {
61
+ "head" => @commit_sha,
62
+ "committed_at" => @committed_at.to_i,
63
+ "branch" => "master"
64
+ },
65
+ "environment" =>
66
+ {
67
+ "test_framework" => "rspec",
68
+ "pwd" => Dir.pwd,
69
+ "rails_root" => nil,
70
+ "simplecov_root" => Dir.pwd,
71
+ "gem_version" => VERSION
72
+ },
73
+ }
74
+ }
75
+
76
+ before do
77
+ @old_pwd = Dir.pwd
78
+ FileUtils.mkdir_p(project_path)
79
+ FileUtils.cd(project_path)
80
+ FileUtils.touch(project_file)
81
+ SimpleCov.root(Dir.pwd)
82
+ system("git init")
83
+ system("git add #{project_file}")
84
+ system("git commit -m 'initial commit'")
85
+ @commit_sha = `git log -1 --pretty=format:'%H'`
86
+ @committed_at = `git log -1 --pretty=format:'%ct'`
87
+ end
88
+
89
+ after do
90
+ FileUtils.cd(@old_pwd)
91
+ FileUtils.rm_rf(project_path)
92
+ end
93
+
94
+ it "sends an http request with all the coverage information" do
95
+ allow(CodeClimate::TestReporter).to receive(:run?).and_return(true)
96
+
97
+ app = FakeCodeClimateEndpoint.new
98
+ Artifice.activate_with(app) do
99
+ formatter.format(simplecov_result)
100
+ end
101
+
102
+ expect(app.path_info).to eq("/test_reports")
103
+ expect(app.content_type).to eq("application/json")
104
+ expect(app.http_content_encoding).to eq("gzip")
105
+
106
+ uncompressed = inflate(app.request_body)
107
+
108
+ expected_request.merge!("ci_service" => Ci.service_data)
109
+ expected_json = JSON.parse(expected_request.to_json, symbolize_names: true)
110
+
111
+ expect(JSON.parse(uncompressed, symbolize_names: true)).to eq(expected_json)
112
+ expect(app.http_user_agent).to include("v#{CodeClimate::TestReporter::VERSION}")
113
+ end
114
+
115
+ describe '#short_filename' do
116
+ it 'should return the filename of the file relative to the SimpleCov root' do
117
+ expect(formatter.short_filename('file1')).to eq('file1')
118
+ expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('file1')
119
+ end
120
+
121
+ context "with path prefix" do
122
+ before do
123
+ CodeClimate::TestReporter.configure do |config|
124
+ config.path_prefix = 'custom'
125
+ end
126
+ end
127
+
128
+ after do
129
+ CodeClimate::TestReporter.configure do |config|
130
+ config.path_prefix = nil
131
+ end
132
+ end
133
+
134
+ it 'should include the path prefix if set' do
135
+ expect(formatter.short_filename('file1')).to eq('custom/file1')
136
+ expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('custom/file1')
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end