Module: Codecov

Defined in:
lib/global-codecov.rb

Overview

Codecov module for executing codecov coverage for any platform independently

Constant Summary collapse

NAME =

Gem information

'global-codecov'.freeze
VERSION =
'1.0.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.CODECOV_DESTINATIONObject

Returns the value of attribute CODECOV_DESTINATION.



17
18
19
# File 'lib/global-codecov.rb', line 17

def CODECOV_DESTINATION
  @CODECOV_DESTINATION
end

.SCRIPT_ENDPOINTObject

Returns the value of attribute SCRIPT_ENDPOINT.



18
19
20
# File 'lib/global-codecov.rb', line 18

def SCRIPT_ENDPOINT
  @SCRIPT_ENDPOINT
end

Class Method Details

.as_flags(params) ⇒ Object

Transforms the params into flags

Parameters:

  • params

    nonnull map of <k,v>



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/global-codecov.rb', line 89

def self.as_flags(params)
	return '' if params.nil?

	return params.map { |k,v|
		case
			when v.nil?
				"-#{k.to_s.shellescape}"
			when v.is_a?(String)
				"-#{k.to_s.shellescape} #{v.to_s.shellescape}"
			when v.is_a?(Array)
				v.flat_map { |iv| [ "-#{k.to_s.shellescape}", iv.to_s.shellescape ] }[0..-1].join(' ')
			else 
				raise "Cant understand '#{k}' => '#{v}'"
		end
	}.join(' ')
end

.download_scriptObject

PRIVATE. This method is for the api, avoid using it

Downloads the SCRIPT_ENDPOINT into the CODECOV_DESTINATION This method doesnt have behavior if the CODECOV_DESTINATION already exists



113
114
115
116
117
118
# File 'lib/global-codecov.rb', line 113

def self.download_script()
	unless File.file? self.CODECOV_DESTINATION
		download = open(self.SCRIPT_ENDPOINT)
		IO.copy_stream(download, self.CODECOV_DESTINATION)
	end
end

.run(params = nil) ⇒ Object

PUBLIC

Runs codecov

Eg. params = {

'c' => nil,
'empty' => '',
'X' => [ 'gcov', 'coveragepy', 'fix' ],
'R' => 'root_dir',
't' => 'MY_ACCESS_TOKEN'

}

Translates to: bash <(codecov.io/bash) -c -empty ” -X gcov -X coveragepy

-X fix -R root_dir -t MY_ACCESS_TOKEN

Notes: This will shellescape ALL, since this is still a shell so using $MY_VAR wont work. If you want to pass a variable use ENV and pass that in the map.

For information about all the params codecov supports, refer to the bash script -h function :)



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/global-codecov.rb', line 73

def self.run(params = nil)
	download_script unless File.file? self.CODECOV_DESTINATION

	flags = ''
	flags << as_flags(params) unless params.nil?

	command = "bash #{self.CODECOV_DESTINATION} #{flags}"

	system command
	return command
end

.set_script_destination(dest) ⇒ Object

PUBLIC

Set the script destination path. We will download the bash script in this path

for the bash script

Defaults to “codecov_script.sh”

Parameters:

  • dest

    String with the absolute file path, used as destination



42
43
44
# File 'lib/global-codecov.rb', line 42

def self.set_script_destination(dest)
	self.CODECOV_DESTINATION = dest.to_s.shellescape
end