codeclimate 0.52.0 → 0.53.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.
- checksums.yaml +4 -4
- data/lib/cc/cli.rb +1 -0
- data/lib/cc/cli/command.rb +3 -29
- data/lib/cc/cli/file_store.rb +42 -0
- data/lib/cc/cli/global_cache.rb +47 -0
- data/lib/cc/cli/global_config.rb +35 -0
- data/lib/cc/cli/output.rb +34 -0
- data/lib/cc/cli/runner.rb +14 -0
- data/lib/cc/cli/version.rb +0 -2
- data/lib/cc/cli/version_checker.rb +105 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8670c3a5508dcd9868790f63702f25a2bff79ee6
|
4
|
+
data.tar.gz: 5f5837ffb7b352a3eb22e5a6bf2387851770a04b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a7bd69ebf91c8d13a07514c672d6ca57c3db70487f64c3835b8d401647dfe18322330ca08e4f4c8b43b5094b24feff9e046d81f6363c935d5503382a52003dd
|
7
|
+
data.tar.gz: bc155b1de0bdf5912d198415b0f28047df84c25516fd09749746e3b5e135ea2d03742a86b7191f7e443866ada3222e26861f90f19ca987619c9a716062e6b148
|
data/lib/cc/cli.rb
CHANGED
data/lib/cc/cli/command.rb
CHANGED
@@ -2,10 +2,13 @@ require "highline"
|
|
2
2
|
require "active_support"
|
3
3
|
require "active_support/core_ext"
|
4
4
|
require "rainbow"
|
5
|
+
require "cc/cli/output"
|
5
6
|
|
6
7
|
module CC
|
7
8
|
module CLI
|
8
9
|
class Command
|
10
|
+
include CC::CLI::Output
|
11
|
+
|
9
12
|
CODECLIMATE_YAML = ".codeclimate.yml".freeze
|
10
13
|
NAMESPACE = name.split("::")[0..-2].join("::").freeze
|
11
14
|
|
@@ -70,23 +73,6 @@ module CC
|
|
70
73
|
run
|
71
74
|
end
|
72
75
|
|
73
|
-
def success(message)
|
74
|
-
terminal.say colorize(message, :green)
|
75
|
-
end
|
76
|
-
|
77
|
-
def say(message)
|
78
|
-
terminal.say message
|
79
|
-
end
|
80
|
-
|
81
|
-
def warn(message)
|
82
|
-
terminal.say(colorize("WARNING: #{message}", :yellow))
|
83
|
-
end
|
84
|
-
|
85
|
-
def fatal(message)
|
86
|
-
$stderr.puts colorize(message, :red)
|
87
|
-
exit 1
|
88
|
-
end
|
89
|
-
|
90
76
|
def require_codeclimate_yml
|
91
77
|
unless filesystem.exist?(CODECLIMATE_YAML)
|
92
78
|
fatal("No '.codeclimate.yml' file found. Run 'codeclimate init' to generate a config file.")
|
@@ -95,24 +81,12 @@ module CC
|
|
95
81
|
|
96
82
|
private
|
97
83
|
|
98
|
-
def colorize(string, *args)
|
99
|
-
rainbow.wrap(string).color(*args)
|
100
|
-
end
|
101
|
-
|
102
|
-
def rainbow
|
103
|
-
@rainbow ||= Rainbow.new
|
104
|
-
end
|
105
|
-
|
106
84
|
def filesystem
|
107
85
|
@filesystem ||= CC::Analyzer::Filesystem.new(
|
108
86
|
CC::Analyzer::MountedPath.code.container_path,
|
109
87
|
)
|
110
88
|
end
|
111
89
|
|
112
|
-
def terminal
|
113
|
-
@terminal ||= HighLine.new($stdin, $stdout)
|
114
|
-
end
|
115
|
-
|
116
90
|
def engine_registry
|
117
91
|
@engine_registry ||= CC::Analyzer::EngineRegistry.new
|
118
92
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module CC
|
5
|
+
module CLI
|
6
|
+
class FileStore
|
7
|
+
# This class is not supposed to be directly used. It should be sublcassed
|
8
|
+
# and a few constants need to be defined on the sublass to be usable.
|
9
|
+
#
|
10
|
+
# FILE_NAME is the name of the file this class wraps.
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
load_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
return false unless File.exist? self.class::FILE_NAME
|
18
|
+
|
19
|
+
File.open(self.class::FILE_NAME, "w") do |f|
|
20
|
+
YAML.dump data, f
|
21
|
+
end
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :data
|
29
|
+
|
30
|
+
def load_data
|
31
|
+
@data =
|
32
|
+
if File.exist? self.class::FILE_NAME
|
33
|
+
File.open(self.class::FILE_NAME, "r:bom|utf-8") do |f|
|
34
|
+
YAML.safe_load(f, [Time], [], false, self.class::FILE_NAME) || {}
|
35
|
+
end
|
36
|
+
else
|
37
|
+
{}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "cc/cli/file_store"
|
2
|
+
|
3
|
+
module CC
|
4
|
+
module CLI
|
5
|
+
class GlobalCache < FileStore
|
6
|
+
FILE_NAME = "/cache.yml".freeze
|
7
|
+
|
8
|
+
# Cache entries
|
9
|
+
|
10
|
+
def last_version_check
|
11
|
+
data["last-version-check"] || Time.at(0)
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_version_check=(value)
|
15
|
+
data["last-version-check"] =
|
16
|
+
if value.is_a? Time
|
17
|
+
value
|
18
|
+
else
|
19
|
+
Time.at(0)
|
20
|
+
end
|
21
|
+
save
|
22
|
+
value
|
23
|
+
end
|
24
|
+
|
25
|
+
def latest_version
|
26
|
+
data["latest-version"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def latest_version=(value)
|
30
|
+
data["latest-version"] = value
|
31
|
+
save
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
def outdated
|
36
|
+
data["outdated"] == true
|
37
|
+
end
|
38
|
+
alias outdated? outdated
|
39
|
+
|
40
|
+
def outdated=(value)
|
41
|
+
data["outdated"] = value == true
|
42
|
+
save
|
43
|
+
value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "cc/cli/file_store"
|
2
|
+
require "uuid"
|
3
|
+
|
4
|
+
module CC
|
5
|
+
module CLI
|
6
|
+
class GlobalConfig < FileStore
|
7
|
+
FILE_NAME = "/config.yml".freeze
|
8
|
+
|
9
|
+
DEFAULT_CONFIG = {
|
10
|
+
"check-version" => true,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# Config entries
|
14
|
+
|
15
|
+
def check_version
|
16
|
+
data["check-version"]
|
17
|
+
end
|
18
|
+
alias check_version? check_version
|
19
|
+
|
20
|
+
def check_version=(value)
|
21
|
+
data["check-version"] = value == true
|
22
|
+
end
|
23
|
+
|
24
|
+
def uuid
|
25
|
+
data["uuid"] ||= UUID.new.generate
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def load_data
|
31
|
+
@data = DEFAULT_CONFIG.merge(super)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CC
|
2
|
+
module CLI
|
3
|
+
module Output
|
4
|
+
def success(message)
|
5
|
+
terminal.say colorize(message, :green)
|
6
|
+
end
|
7
|
+
|
8
|
+
def say(message)
|
9
|
+
terminal.say message
|
10
|
+
end
|
11
|
+
|
12
|
+
def warn(message)
|
13
|
+
terminal.say colorize("WARNING: #{message}", :yellow)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fatal(message)
|
17
|
+
$stderr.puts colorize(message, :red)
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def colorize(string, *args)
|
22
|
+
rainbow.wrap(string).color(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def rainbow
|
26
|
+
@rainbow ||= Rainbow.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def terminal
|
30
|
+
@terminal ||= HighLine.new($stdin, $stdout)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/cc/cli/runner.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "active_support/core_ext"
|
3
|
+
require "cc/cli/version_checker"
|
3
4
|
|
4
5
|
module CC
|
5
6
|
module CLI
|
@@ -17,6 +18,8 @@ module CC
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def run
|
21
|
+
VersionChecker.new.check if check_version?
|
22
|
+
|
20
23
|
if command_class
|
21
24
|
command = command_class.new(command_arguments)
|
22
25
|
command.execute
|
@@ -56,6 +59,17 @@ module CC
|
|
56
59
|
command_name
|
57
60
|
end
|
58
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def check_version?
|
66
|
+
if ARGV.first == "--no-check-version"
|
67
|
+
ARGV.shift
|
68
|
+
false
|
69
|
+
else
|
70
|
+
true
|
71
|
+
end
|
72
|
+
end
|
59
73
|
end
|
60
74
|
end
|
61
75
|
end
|
data/lib/cc/cli/version.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "cc/cli/global_config"
|
2
|
+
require "cc/cli/global_cache"
|
3
|
+
|
4
|
+
module CC
|
5
|
+
module CLI
|
6
|
+
class VersionChecker
|
7
|
+
include CC::CLI::Output
|
8
|
+
|
9
|
+
VERSION_CHECK_TIMEOUT = 60 * 60 # 1 Hour in seconds
|
10
|
+
DEFAULT_VERSIONS_URL = "https://versions.codeclimate.com".freeze
|
11
|
+
|
12
|
+
def check
|
13
|
+
return unless global_config.check_version?
|
14
|
+
|
15
|
+
print_new_version_message if outdated?
|
16
|
+
|
17
|
+
global_config.save
|
18
|
+
rescue => error
|
19
|
+
CLI.debug(error)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def version_check_is_due?
|
25
|
+
Time.now > global_cache.last_version_check + VERSION_CHECK_TIMEOUT
|
26
|
+
end
|
27
|
+
|
28
|
+
def outdated?
|
29
|
+
if version_check_is_due?
|
30
|
+
api_response["outdated"] == true
|
31
|
+
else
|
32
|
+
global_cache.outdated?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def latest_version
|
37
|
+
if version_check_is_due?
|
38
|
+
api_response["latest"]
|
39
|
+
else
|
40
|
+
global_cache.latest_version
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def print_new_version_message
|
45
|
+
warn "A new version (v#{latest_version}) is available"
|
46
|
+
end
|
47
|
+
|
48
|
+
def api_response
|
49
|
+
@api_response ||=
|
50
|
+
begin
|
51
|
+
cache! JSON.parse(api_response_body)
|
52
|
+
rescue JSON::ParserError => error
|
53
|
+
CLI.debug(error)
|
54
|
+
# We don't know so use cached values or pretend all is peachy. We'll
|
55
|
+
# try again next time.
|
56
|
+
{
|
57
|
+
"latest" => global_cache.latest_version || version,
|
58
|
+
"outdated" => global_cache.outdated || false,
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_response_body
|
64
|
+
if http_response.is_a? Net::HTTPSuccess
|
65
|
+
http_response.body
|
66
|
+
else
|
67
|
+
raise Net::HTTPFatalError.new("HTTP Error", http_response)
|
68
|
+
end
|
69
|
+
rescue Net::HTTPFatalError => error
|
70
|
+
CLI.debug(error)
|
71
|
+
""
|
72
|
+
end
|
73
|
+
|
74
|
+
def http_response
|
75
|
+
@http_response ||=
|
76
|
+
begin
|
77
|
+
uri = URI.parse(ENV.fetch("CODECLIMATE_VERSIONS_URL", DEFAULT_VERSIONS_URL))
|
78
|
+
uri.query = { version: version, uid: global_config.uuid }.to_query
|
79
|
+
Net::HTTP.start(uri.host, uri.port, open_timeout: 5, read_timeout: 5, ssl_timeout: 5, use_ssl: uri.scheme == "https") do |http|
|
80
|
+
http.request_get(uri)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def cache!(data)
|
86
|
+
global_cache.latest_version = data["latest"]
|
87
|
+
global_cache.outdated = data["outdated"] == true
|
88
|
+
global_cache.last_version_check = Time.now
|
89
|
+
data
|
90
|
+
end
|
91
|
+
|
92
|
+
def version
|
93
|
+
@version ||= Version.new.version
|
94
|
+
end
|
95
|
+
|
96
|
+
def global_config
|
97
|
+
@global_config ||= GlobalConfig.new
|
98
|
+
end
|
99
|
+
|
100
|
+
def global_cache
|
101
|
+
@global_cache ||= GlobalCache.new
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.53.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Climate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -146,6 +146,20 @@ dependencies:
|
|
146
146
|
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '3.2'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: uuid
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '2.3'
|
156
|
+
type: :runtime
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - "~>"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '2.3'
|
149
163
|
description: Code Climate command line tool
|
150
164
|
email: hello@codeclimate.com
|
151
165
|
executables:
|
@@ -219,14 +233,19 @@ files:
|
|
219
233
|
- lib/cc/cli/engines/install.rb
|
220
234
|
- lib/cc/cli/engines/list.rb
|
221
235
|
- lib/cc/cli/engines/remove.rb
|
236
|
+
- lib/cc/cli/file_store.rb
|
237
|
+
- lib/cc/cli/global_cache.rb
|
238
|
+
- lib/cc/cli/global_config.rb
|
222
239
|
- lib/cc/cli/help.rb
|
223
240
|
- lib/cc/cli/init.rb
|
241
|
+
- lib/cc/cli/output.rb
|
224
242
|
- lib/cc/cli/prepare.rb
|
225
243
|
- lib/cc/cli/runner.rb
|
226
244
|
- lib/cc/cli/test.rb
|
227
245
|
- lib/cc/cli/upgrade_config_generator.rb
|
228
246
|
- lib/cc/cli/validate_config.rb
|
229
247
|
- lib/cc/cli/version.rb
|
248
|
+
- lib/cc/cli/version_checker.rb
|
230
249
|
- lib/cc/resolv.rb
|
231
250
|
- lib/cc/workspace.rb
|
232
251
|
- lib/cc/workspace/exclusion.rb
|