fasterer-github 0.1.1 → 0.2.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/README.md +33 -1
- data/lib/fasterer/github/api_wrapper.rb +13 -12
- data/lib/fasterer/github/gh_traverser.rb +10 -6
- data/lib/fasterer/github/output_composer.rb +8 -2
- data/lib/fasterer/github/scanner.rb +28 -2
- data/lib/fasterer/github/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d42b5a400f4bf2d8acc16a2b30826fee2e9153
|
4
|
+
data.tar.gz: e66809d510a4ba74194471a9561c60d94330c9e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6d0dfa7d0265abc82e5ea80cbd54baff7053eb119d4d007d0f0fefa6f635cdefe06ca5fbbd8a3bd0ead3969ad1101ee02b9245ea0f2f5793e85c1a69cfc8268
|
7
|
+
data.tar.gz: b63b791420162a94eae825e58d69f56b068e07af1bc9c39289df01fc036a68dbdd06cc4140322b4e7f03929435a2c4dce8bb056f72c2a083cda3cad9a9b62c8c
|
data/README.md
CHANGED
@@ -44,6 +44,38 @@ Fasterer::Github.configure do |config|
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
+
Additional configuration can be done using `.fasterer.yml` file, which has to be placed in the root folder of your project.
|
48
|
+
Possible options:
|
49
|
+
* turn off speed suggestions
|
50
|
+
* blacklist files or complete folder paths
|
51
|
+
|
52
|
+
```yaml
|
53
|
+
speedups:
|
54
|
+
parallel_assignment: false
|
55
|
+
rescue_vs_respond_to: true
|
56
|
+
module_eval: true
|
57
|
+
shuffle_first_vs_sample: true
|
58
|
+
for_loop_vs_each: true
|
59
|
+
each_with_index_vs_while: false
|
60
|
+
map_flatten_vs_flat_map: true
|
61
|
+
reverse_each_vs_reverse_each: true
|
62
|
+
select_first_vs_detect: true
|
63
|
+
sort_vs_sort_by: true
|
64
|
+
fetch_with_argument_vs_block: true
|
65
|
+
keys_each_vs_each_key: true
|
66
|
+
hash_merge_bang_vs_hash_brackets: true
|
67
|
+
block_vs_symbol_to_proc: true
|
68
|
+
proc_call_vs_yield: true
|
69
|
+
gsub_vs_tr: true
|
70
|
+
select_last_vs_reverse_detect: true
|
71
|
+
getter_vs_attr_reader: true
|
72
|
+
setter_vs_attr_writer: true
|
73
|
+
|
74
|
+
exclude_paths:
|
75
|
+
- 'vendor/'
|
76
|
+
- 'db/schema.rb'
|
77
|
+
```
|
78
|
+
|
47
79
|
## Usage
|
48
80
|
|
49
81
|
To scan whole repo, run:
|
@@ -51,7 +83,7 @@ To scan whole repo, run:
|
|
51
83
|
Fasterer::Github.scan('owner', 'repo')
|
52
84
|
```
|
53
85
|
|
54
|
-
|
86
|
+
Or scan specific file:
|
55
87
|
```ruby
|
56
88
|
Fasterer::Github.scan('owner', 'repo', 'lib/fasterer-github.rb')
|
57
89
|
```
|
@@ -3,7 +3,7 @@ require 'httparty'
|
|
3
3
|
module Fasterer
|
4
4
|
module Github
|
5
5
|
class ApiWrapper
|
6
|
-
|
6
|
+
BASE_URI = 'https://api.github.com'
|
7
7
|
|
8
8
|
def initialize(owner, repo)
|
9
9
|
@owner = owner
|
@@ -14,27 +14,28 @@ module Fasterer
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def contents(path)
|
17
|
-
|
18
|
-
HTTParty.get(url)
|
17
|
+
HTTParty.get(build_uri(path), query: authorization_params)
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
22
21
|
|
23
22
|
attr_reader :owner, :repo, :path, :client_id, :client_secret, :access_token
|
24
23
|
|
25
|
-
def
|
26
|
-
|
27
|
-
return add_access_token(url) if access_token != ''
|
28
|
-
return add_client_id_and_secret(url) if client_id != '' && client_secret != ''
|
29
|
-
url
|
24
|
+
def build_uri(path)
|
25
|
+
BASE_URI + "/repos/#{owner}/#{repo}/contents/#{path}"
|
30
26
|
end
|
31
27
|
|
32
|
-
def
|
33
|
-
|
28
|
+
def authorization_params
|
29
|
+
return access_token_hash unless access_token.empty?
|
30
|
+
return client_id_secret_hash unless client_id.empty? && client_secret.empty?
|
34
31
|
end
|
35
32
|
|
36
|
-
def
|
37
|
-
|
33
|
+
def access_token_hash
|
34
|
+
{ 'access_token' => access_token }
|
35
|
+
end
|
36
|
+
|
37
|
+
def client_id_secret_hash
|
38
|
+
{ 'client_id' => client_id, 'client_secret' => client_secret }
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -3,10 +3,11 @@ require_relative 'api_wrapper'
|
|
3
3
|
module Fasterer
|
4
4
|
module Github
|
5
5
|
class GhTraverser
|
6
|
-
def initialize(owner, repo, path)
|
6
|
+
def initialize(owner, repo, path, ignored_paths)
|
7
7
|
@owner = owner
|
8
8
|
@repo = repo
|
9
9
|
@path = path.to_s
|
10
|
+
@ignored_paths = ignored_paths.map { |i| i.chomp("/") }
|
10
11
|
end
|
11
12
|
|
12
13
|
def traverse
|
@@ -23,7 +24,7 @@ module Fasterer
|
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
attr_reader :owner, :repo, :path
|
27
|
+
attr_reader :owner, :repo, :path, :ignored_paths
|
27
28
|
|
28
29
|
def wrapper
|
29
30
|
@wrapper ||= Fasterer::Github::ApiWrapper.new(owner, repo)
|
@@ -35,10 +36,13 @@ module Fasterer
|
|
35
36
|
parsed_response = response.parsed_response
|
36
37
|
|
37
38
|
if parsed_response.is_a?(Hash)
|
38
|
-
return unless match_regex?(parsed_response['path'])
|
39
39
|
store_data(parsed_response)
|
40
40
|
else
|
41
|
-
parsed_response.each
|
41
|
+
parsed_response.each do |item|
|
42
|
+
next if ignored_paths.include?(item['path'])
|
43
|
+
next if item['type'] == 'file' && !ruby_file?(item['path'])
|
44
|
+
collect_data(item['path'])
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -57,8 +61,8 @@ module Fasterer
|
|
57
61
|
collected_data << file_data
|
58
62
|
end
|
59
63
|
|
60
|
-
def
|
61
|
-
file_name =~
|
64
|
+
def ruby_file?(file_name)
|
65
|
+
file_name =~ /\.rb$/
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
module Fasterer
|
2
2
|
module Github
|
3
3
|
class OutputComposer
|
4
|
-
|
4
|
+
|
5
|
+
CONFIG_FILE_NAME = '.fasterer.yml'
|
6
|
+
SPEEDUPS_KEY = 'speedups'
|
7
|
+
|
8
|
+
def initialize(owner, repo, ignored_offences)
|
5
9
|
@repo_owner = owner
|
6
10
|
@repo_name = repo
|
11
|
+
@ignored_offences = ignored_offences
|
7
12
|
end
|
8
13
|
|
9
14
|
def add_offences(offences, path)
|
10
15
|
offences.each do |offence_name, lines|
|
11
16
|
details = { path: path, lines: lines }
|
17
|
+
next if ignored_offences.include?(offence_name)
|
12
18
|
(fasterer_offences[offence_name] ||= []) << details
|
13
19
|
end
|
14
20
|
end
|
@@ -33,7 +39,7 @@ module Fasterer
|
|
33
39
|
|
34
40
|
private
|
35
41
|
|
36
|
-
attr_accessor :repo_owner, :repo_name
|
42
|
+
attr_accessor :repo_owner, :repo_name, :ignored_offences
|
37
43
|
|
38
44
|
def fasterer_offences
|
39
45
|
@fasterer_offenses ||= {}
|
@@ -5,6 +5,11 @@ require 'fasterer/github/analyzer_extension'
|
|
5
5
|
module Fasterer
|
6
6
|
module Github
|
7
7
|
class Scanner
|
8
|
+
|
9
|
+
CONFIG_FILE_NAME = '.fasterer.yml'
|
10
|
+
SPEEDUPS_KEY = 'speedups'
|
11
|
+
EXCLUDE_PATHS_KEY = 'exclude_paths'
|
12
|
+
|
8
13
|
def initialize(owner, repo, path)
|
9
14
|
@owner = owner
|
10
15
|
@repo = repo
|
@@ -25,11 +30,11 @@ module Fasterer
|
|
25
30
|
attr_reader :owner, :repo, :path
|
26
31
|
|
27
32
|
def traverser
|
28
|
-
@traverser ||= Fasterer::Github::GhTraverser.new(owner, repo, path)
|
33
|
+
@traverser ||= Fasterer::Github::GhTraverser.new(owner, repo, path, ignored_paths)
|
29
34
|
end
|
30
35
|
|
31
36
|
def output_composer
|
32
|
-
@output_composer ||= Fasterer::Github::OutputComposer.new(owner, repo)
|
37
|
+
@output_composer ||= Fasterer::Github::OutputComposer.new(owner, repo, ignored_offences)
|
33
38
|
end
|
34
39
|
|
35
40
|
def traverse_and_collect_data
|
@@ -46,6 +51,27 @@ module Fasterer
|
|
46
51
|
else
|
47
52
|
output_composer.add_offences(analyzer.offences, data[:path])
|
48
53
|
end
|
54
|
+
|
55
|
+
def ignored_offences
|
56
|
+
loaded_config_file[SPEEDUPS_KEY].select { |_, v| v == false }.keys.map(&:to_sym)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ignored_paths
|
60
|
+
loaded_config_file[EXCLUDE_PATHS_KEY]
|
61
|
+
end
|
62
|
+
|
63
|
+
def loaded_config_file
|
64
|
+
@loaded_config_file ||= load_config_file
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_config_file
|
68
|
+
path_to_config = File.join(Dir.pwd, CONFIG_FILE_NAME)
|
69
|
+
if File.exist?(path_to_config)
|
70
|
+
YAML.load_file(path_to_config)
|
71
|
+
else
|
72
|
+
{ SPEEDUPS_KEY => {}, EXCLUDE_PATHS_KEY => [] }
|
73
|
+
end
|
74
|
+
end
|
49
75
|
end
|
50
76
|
end
|
51
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kacper Goliński
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -171,4 +171,3 @@ signing_key:
|
|
171
171
|
specification_version: 4
|
172
172
|
summary: Fasterer extension which allows to scan github repo.
|
173
173
|
test_files: []
|
174
|
-
has_rdoc:
|