lcoveralls 0.2.0 → 0.2.1.pre.1
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.
- checksums.yaml +7 -0
- data/lib/lcoveralls/color_formatter.rb +11 -0
- data/lib/lcoveralls/coveralls_request.rb +17 -3
- data/lib/lcoveralls/logger.rb +9 -0
- data/lib/lcoveralls/option_parser.rb +7 -1
- data/lib/lcoveralls/runner.rb +69 -5
- data/lib/lcoveralls/version.rb +2 -1
- metadata +11 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c462ce13fc850020fa683a07e8f892f39b30e380
|
4
|
+
data.tar.gz: 52368ddb0c15c2feb97bdf9ef8987d56e85538fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebd18da325d78de34ed8ff45ce56b6f39c747ede904dca6c3457d04cc917e095996d3ebd732577106d2c0595e2fe1b60de03588c8aa0eee40f3929d4026c96cb
|
7
|
+
data.tar.gz: b9939492b8235f1766a4e570b9eed6f08f2c86efc5d28912fd67721d955914a17bca514a9c31b7e7273aa344a19da0918b5ed5421d97cdc3fc83f9f56e1f8d6e
|
@@ -18,8 +18,10 @@ require 'logger'
|
|
18
18
|
|
19
19
|
module Lcoveralls
|
20
20
|
|
21
|
+
# Adds some color to loggers.
|
21
22
|
class ColorFormatter < Logger::Formatter
|
22
23
|
|
24
|
+
# Maps log severities to color codes.
|
23
25
|
COLOR_CODES = {
|
24
26
|
'Warning' => '35',
|
25
27
|
'Error' => '31',
|
@@ -27,10 +29,19 @@ module Lcoveralls
|
|
27
29
|
'Unknown' => '31;1'
|
28
30
|
}
|
29
31
|
|
32
|
+
# Initializes a new ColorFormatter.
|
33
|
+
#
|
34
|
+
# @param color [Boolean] Whether to enable color output.
|
30
35
|
def initialize(color)
|
31
36
|
@color = color
|
32
37
|
end
|
33
38
|
|
39
|
+
# Invoked by Logger objects to format a log message.
|
40
|
+
#
|
41
|
+
# @param severity [String] Severity of the message to format.
|
42
|
+
# @param datetime [Time] Timestamp for the message to format.
|
43
|
+
# @param progname [String] Name of the program that generated the message.
|
44
|
+
# @param msg [String] The message to format.
|
34
45
|
def call(severity, datetime, progname, msg)
|
35
46
|
severity.capitalize!
|
36
47
|
if severity == 'Warn' then severity = 'Warning' end
|
@@ -19,11 +19,17 @@ require 'net/http'
|
|
19
19
|
|
20
20
|
module Lcoveralls
|
21
21
|
|
22
|
+
# Encapsulates a Coveralls (coverall.io) HTTP POST request.
|
22
23
|
class CoverallsRequest < Net::HTTP::Post
|
23
24
|
|
25
|
+
# Initializes a new CoverallsRequest instance.
|
26
|
+
#
|
27
|
+
# @param job [Hash] The fields of a Coveralls API request. Can be any type
|
28
|
+
# that can be passed to +JSON#generate+.
|
29
|
+
# @param path Optional HTTP request path.
|
24
30
|
def initialize(job, path='/api/v1/jobs')
|
25
31
|
super path
|
26
|
-
@boundary = (1
|
32
|
+
@boundary = (1..70).map { self.class.boundary_chr(rand(62)) }.join
|
27
33
|
set_content_type "multipart/form-data, boundary=#{@boundary}"
|
28
34
|
@body =
|
29
35
|
"--#{@boundary}\r\n" +
|
@@ -32,7 +38,15 @@ module Lcoveralls
|
|
32
38
|
JSON::generate(job) + "\r\n--#{@boundary}--\r\n"
|
33
39
|
end
|
34
40
|
|
35
|
-
#
|
41
|
+
# Returns one of the 74 valid MIME boundary characters.
|
42
|
+
#
|
43
|
+
# @param index [Integer] Index of the boundary character to fetch. Must be
|
44
|
+
# between 0 and 73. *Note*, although indices between 0 and 73 are
|
45
|
+
# valid according to the MIME standard, only indices between 0 and
|
46
|
+
# 61 are valid for HTTP headers. If index is outside the range 0 to
|
47
|
+
# 73, this method will raise a RuntimeError.
|
48
|
+
#
|
49
|
+
# @return [String] a valid MIME boundary character.
|
36
50
|
def self.boundary_chr(index)
|
37
51
|
case index
|
38
52
|
when 0..9
|
@@ -44,7 +58,7 @@ module Lcoveralls
|
|
44
58
|
when 62..73
|
45
59
|
"'()+_,-./:=?"[index - 62]
|
46
60
|
else
|
47
|
-
|
61
|
+
raise "Invalid boundary index #{index}"
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
data/lib/lcoveralls/logger.rb
CHANGED
@@ -16,12 +16,21 @@
|
|
16
16
|
|
17
17
|
require 'logger'
|
18
18
|
|
19
|
+
# Adds {TRACE} severity logging to Ruby's Logger class.
|
19
20
|
class Logger
|
20
21
|
|
22
|
+
# {TRACE} severity is one less than +::Logger::DEBUG+.
|
21
23
|
TRACE = DEBUG - 1
|
22
24
|
|
25
|
+
# Log a {TRACE} message.
|
26
|
+
#
|
27
|
+
# See +::Logger::info+ for more information.
|
23
28
|
def trace(progname = nil, &block)
|
24
29
|
add(TRACE, nil, progname, &block)
|
25
30
|
end
|
26
31
|
|
32
|
+
# Returns +true+ if the current severity level allows for the printing of
|
33
|
+
# {TRACE} messages.
|
34
|
+
def trace?; @level <= TRACE; end
|
35
|
+
|
27
36
|
end
|
@@ -19,8 +19,14 @@ require 'optparse'
|
|
19
19
|
|
20
20
|
module Lcoveralls
|
21
21
|
|
22
|
+
# Parses CLI options for the Lcoveralls application.
|
22
23
|
class OptionParser
|
23
24
|
|
25
|
+
# Destructively parse the command line arguments.
|
26
|
+
#
|
27
|
+
# @params args [Array] Arguments to parse.
|
28
|
+
#
|
29
|
+
# @return [Hash] parsed options.
|
24
30
|
def parse!(args)
|
25
31
|
options = {
|
26
32
|
:color => $stderr.isatty,
|
@@ -90,7 +96,7 @@ module Lcoveralls
|
|
90
96
|
rescue ::OptionParser::InvalidOption => e
|
91
97
|
$stderr.puts parser
|
92
98
|
$stderr.puts e
|
93
|
-
exit
|
99
|
+
exit(false)
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
data/lib/lcoveralls/runner.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
1
|
#
|
3
2
|
# Copyright 2014 Paul Colby
|
4
3
|
#
|
@@ -16,10 +15,14 @@
|
|
16
15
|
#
|
17
16
|
|
18
17
|
require 'find'
|
18
|
+
require 'openssl'
|
19
19
|
|
20
20
|
module Lcoveralls
|
21
|
+
|
22
|
+
# Runs the Lcoveralls application.
|
21
23
|
class Runner
|
22
24
|
|
25
|
+
# Initializes a new Locveralls::Runner instance.
|
23
26
|
def initialize
|
24
27
|
# Parse the command line options.
|
25
28
|
parser = Lcoveralls::OptionParser.new
|
@@ -32,6 +35,21 @@ module Lcoveralls
|
|
32
35
|
@log.debug { "Options: #{@options}" }
|
33
36
|
end
|
34
37
|
|
38
|
+
# Attempts to auto-detect the git repository root.
|
39
|
+
#
|
40
|
+
# This method looks throuhgh all source files covered by the supplied
|
41
|
+
# tracefiles, and for each, check if they are part of a git repository.
|
42
|
+
# The method then returns git repository's root directory.
|
43
|
+
#
|
44
|
+
# If more than one git repository are found to be covered by the tracefiles
|
45
|
+
# then a warning will be logged, and the root of the repository with the
|
46
|
+
# largest number of source files covered will be returned.
|
47
|
+
#
|
48
|
+
# If no git repository roots could be found, then +nil+ is returned.
|
49
|
+
#
|
50
|
+
# @param info_files [Array] A list of LCOV tracefiles (aka *.info files).
|
51
|
+
#
|
52
|
+
# @return [String, nil] A git repository root, if found, otherwise +nil+.
|
35
53
|
def find_root(info_files)
|
36
54
|
# Try source file(s) covered by the lcov tracefile(s).
|
37
55
|
root_dirs = Hash.new(0)
|
@@ -57,6 +75,21 @@ module Lcoveralls
|
|
57
75
|
end
|
58
76
|
end
|
59
77
|
|
78
|
+
# Format a percentage string.
|
79
|
+
#
|
80
|
+
# This method formats the number of lines hit, as a percentage of the total
|
81
|
+
# number of lines, including prepended spaces, and color codes where
|
82
|
+
# appropriate.
|
83
|
+
#
|
84
|
+
# If the percentage cannot be calculated (for example, either parameter is
|
85
|
+
# +nil+, NaN, +/- ininity, etc), then this function will return a 'blank'
|
86
|
+
# string - one with enough spaces to match the width of other valid
|
87
|
+
# percentage strings returned by this function.
|
88
|
+
#
|
89
|
+
# @param lines_hit [Integer, nil] Number of lines hit by unit tests.
|
90
|
+
# @param lines_found [Integer, nil] Number of executable lines.
|
91
|
+
#
|
92
|
+
# @return [String] Percentage of lines overered.
|
60
93
|
def get_percentage(lines_hit, lines_found, bold=false)
|
61
94
|
perc = lines_hit.to_f / lines_found.to_f * 100.0
|
62
95
|
color = case when perc >= 90; 32 when perc >= 75; 33 else 31 end
|
@@ -66,6 +99,16 @@ module Lcoveralls
|
|
66
99
|
perc
|
67
100
|
end
|
68
101
|
|
102
|
+
# Builds a hash of source files matching the Coveralls API.
|
103
|
+
#
|
104
|
+
# This method will build a Hash containing all source files covered by the
|
105
|
+
# supplies LCOV tracefiles, that reside within the specified repository
|
106
|
+
# root directory.
|
107
|
+
#
|
108
|
+
# @param info_file [Array] LCOV tracefiles containing source files to load.
|
109
|
+
# @param root_dir [String] Repository root directory.
|
110
|
+
#
|
111
|
+
# @return [Hash] Source files in Coveralls API structure.
|
69
112
|
def get_source_files(info_files, root_dir)
|
70
113
|
sources = {}
|
71
114
|
total_lines_found = 0
|
@@ -132,6 +175,11 @@ module Lcoveralls
|
|
132
175
|
sources.values
|
133
176
|
end
|
134
177
|
|
178
|
+
# Get git repository information in the Coveralla API structure.
|
179
|
+
#
|
180
|
+
# @param root_dir Git repository root directory.
|
181
|
+
#
|
182
|
+
# @return [Hash] Git repository information.
|
135
183
|
def get_git_info(root_dir)
|
136
184
|
Dir.chdir(root_dir) do
|
137
185
|
info = {
|
@@ -159,7 +207,19 @@ module Lcoveralls
|
|
159
207
|
end if Dir.exist?(root_dir)
|
160
208
|
end
|
161
209
|
|
162
|
-
|
210
|
+
# Should we retry a failed Coveralls API request?
|
211
|
+
#
|
212
|
+
# This method is called by {#run} on internal and server errors to check if
|
213
|
+
# the API request should be retried. Specifically, this function checks the
|
214
|
+
# :retry_count option, and if greater than zero decrements it before
|
215
|
+
# returning +true+.
|
216
|
+
#
|
217
|
+
# Additionally, if retrying is appropriate, and the :retry_interval option
|
218
|
+
# is greater than zero, this function will also sleep for that interval.
|
219
|
+
#
|
220
|
+
# @return [Boolean] +true+ if the caller should retry the API request, or
|
221
|
+
# +false+ if no more retries should be attempted.
|
222
|
+
def should_retry?
|
163
223
|
return false unless @options[:retry_count] > 0
|
164
224
|
@options[:retry_count] = @options[:retry_count] - 1;
|
165
225
|
|
@@ -174,6 +234,10 @@ module Lcoveralls
|
|
174
234
|
true
|
175
235
|
end
|
176
236
|
|
237
|
+
# Runs the Lcoveralls application.
|
238
|
+
#
|
239
|
+
# This method does the real work of building up the Coveralls API request
|
240
|
+
# according to the parsed options, and submitting the request to Coveralls.
|
177
241
|
def run
|
178
242
|
# Find *.info tracefiles if none specified on the command line.
|
179
243
|
Find.find('.') do |path|
|
@@ -225,15 +289,15 @@ module Lcoveralls
|
|
225
289
|
@log.debug { "HTTP response status: #{response.code} #{response.message}" }
|
226
290
|
raise response.code unless response.is_a? Net::HTTPSuccess
|
227
291
|
puts response.body
|
228
|
-
rescue RuntimeError
|
292
|
+
rescue RuntimeError
|
229
293
|
raise unless response
|
230
294
|
@log.error { "Received non-OK response: #{response.code} #{response.message}" }
|
231
295
|
puts response.body
|
232
|
-
retry if should_retry unless response.is_a? Net::HTTPClientError
|
296
|
+
retry if should_retry? unless response.is_a? Net::HTTPClientError
|
233
297
|
exit!
|
234
298
|
rescue SocketError => error
|
235
299
|
@log.error { error }
|
236
|
-
retry if should_retry
|
300
|
+
retry if should_retry?
|
237
301
|
exit!
|
238
302
|
end
|
239
303
|
end
|
data/lib/lcoveralls/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lcoveralls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1.pre.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Paul Colby
|
@@ -19,37 +18,36 @@ executables:
|
|
19
18
|
extensions: []
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
21
|
+
- bin/lcoveralls
|
22
22
|
- lib/lcoveralls.rb
|
23
23
|
- lib/lcoveralls/color_formatter.rb
|
24
|
-
- lib/lcoveralls/
|
25
|
-
- lib/lcoveralls/version.rb
|
24
|
+
- lib/lcoveralls/coveralls_request.rb
|
26
25
|
- lib/lcoveralls/logger.rb
|
26
|
+
- lib/lcoveralls/option_parser.rb
|
27
27
|
- lib/lcoveralls/runner.rb
|
28
|
-
- lib/lcoveralls/
|
29
|
-
- bin/lcoveralls
|
28
|
+
- lib/lcoveralls/version.rb
|
30
29
|
homepage: https://github.com/pcolby/lcoveralls
|
31
30
|
licenses:
|
32
31
|
- Apache-2.0
|
32
|
+
metadata: {}
|
33
33
|
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
38
|
requirements:
|
40
|
-
- -
|
39
|
+
- - ">="
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
43
|
requirements:
|
46
|
-
- -
|
44
|
+
- - ">"
|
47
45
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
46
|
+
version: 1.3.1
|
49
47
|
requirements: []
|
50
48
|
rubyforge_project:
|
51
|
-
rubygems_version:
|
49
|
+
rubygems_version: 2.4.1
|
52
50
|
signing_key:
|
53
|
-
specification_version:
|
51
|
+
specification_version: 4
|
54
52
|
summary: Report Gcov / LCOV (ie C, C++, Go, etc) code coverage to coveralls.io
|
55
53
|
test_files: []
|