pronto-golang 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/pronto/golang/tools/base.rb +31 -2
- data/lib/pronto/golang/tools/golangci_lint.rb +4 -0
- data/lib/pronto/golang/tools/govet.rb +0 -12
- data/lib/pronto/golang/version.rb +1 -1
- data/lib/pronto/golang.rb +69 -17
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99782fed6e8a0a6a565488fd9f3ececa73181aab83bfd2f4793c837a994675e4
|
4
|
+
data.tar.gz: e0c7358dd1a811668440662b2f55cdae3200a7e55fc64c458311ab2a80325c4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 753150d7f9d86546cb64e47217b87ddb409cbb20604067f90edd20726cf2c69762ae27d32654a92248d00b9d6823291cdd18d9cbf4bb3b474b21dd1a353a58c6
|
7
|
+
data.tar.gz: 214f5868ac6890a2f90073fb47c9c59af255cfc3c575cd4c0a5024ba262d7ccf1d91f77d6f011ad1be1244fd531006ad0b47b46c002ca92a79e8ced5ef867795
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
![Build Status](https://github.com/viafintech/pronto-golang/actions/workflows/test.yml/badge.svg) [![RubyDoc](https://img.shields.io/badge/ruby-doc-green.svg)](http://rubydoc.info/github/Barzahlen/pronto-golang)
|
4
4
|
|
5
|
-
Pronto runner for [Golang](https://
|
5
|
+
[Pronto](https://github.com/prontolabs/pronto) runner for [Golang](https://go.dev) tools
|
6
6
|
|
7
7
|
## Tools
|
8
8
|
|
@@ -14,7 +14,11 @@ module Pronto
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def command(file_path)
|
17
|
-
"#{base_command} #{parameters} #{file_path}"
|
17
|
+
"cd #{directory} && #{base_command} #{parameters} #{file_path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def directory(default = '.')
|
21
|
+
@config.fetch('execution_directory', default)
|
18
22
|
end
|
19
23
|
|
20
24
|
def parameters
|
@@ -37,8 +41,33 @@ module Pronto
|
|
37
41
|
@config.fetch('enabled', true) # Default to true if the key is not configured
|
38
42
|
end
|
39
43
|
|
44
|
+
# Supported options:
|
45
|
+
# - file
|
46
|
+
# - project
|
47
|
+
def execution_mode
|
48
|
+
'file'
|
49
|
+
end
|
50
|
+
|
40
51
|
def parse_line(line)
|
41
|
-
|
52
|
+
elements = line.split(':')
|
53
|
+
file_path = elements[0]
|
54
|
+
line_number = elements[1]
|
55
|
+
|
56
|
+
case elements.count
|
57
|
+
when 3
|
58
|
+
message = elements[-1]
|
59
|
+
else
|
60
|
+
if elements[2].strip =~ /^\d+$/
|
61
|
+
message = elements[3..].join(':')
|
62
|
+
else
|
63
|
+
message = elements[2..].join(':')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
dir = directory('')
|
68
|
+
if dir != ''
|
69
|
+
file_path = File.join(dir, file_path)
|
70
|
+
end
|
42
71
|
|
43
72
|
return file_path, line_number, :warning, message.to_s.strip
|
44
73
|
end
|
@@ -8,18 +8,6 @@ module Pronto
|
|
8
8
|
def available?
|
9
9
|
enabled?
|
10
10
|
end
|
11
|
-
|
12
|
-
def parse_line(line)
|
13
|
-
# Support handling messages like
|
14
|
-
# - spec/fixtures/test.git/main.go:18:2: unreachable code
|
15
|
-
# - spec/fixtures/test.git/main.go:18: something else
|
16
|
-
elements = line.split(':')
|
17
|
-
file_path = elements[0]
|
18
|
-
line_number = elements[1]
|
19
|
-
message = elements[-1]
|
20
|
-
|
21
|
-
return file_path, line_number, :warning, message.to_s.strip
|
22
|
-
end
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
data/lib/pronto/golang.rb
CHANGED
@@ -17,9 +17,15 @@ module Pronto
|
|
17
17
|
def run
|
18
18
|
return [] unless @patches
|
19
19
|
|
20
|
-
@patches
|
21
|
-
|
22
|
-
|
20
|
+
valid_patches = @patches.select { |patch| valid_patch?(patch) }
|
21
|
+
patch_file_paths = valid_patches.map { |patch| patch_file_path(patch) }
|
22
|
+
|
23
|
+
collected_findings = []
|
24
|
+
collected_findings += run_tools_for_projects
|
25
|
+
collected_findings += run_tools_for_files(patch_file_paths)
|
26
|
+
|
27
|
+
valid_patches
|
28
|
+
.map { |patch| inspect(patch, collected_findings) }
|
23
29
|
.flatten
|
24
30
|
.compact
|
25
31
|
end
|
@@ -28,31 +34,77 @@ module Pronto
|
|
28
34
|
patch.additions > 0 && go_file?(patch.new_file_full_path)
|
29
35
|
end
|
30
36
|
|
31
|
-
def
|
32
|
-
|
37
|
+
def patch_file_path(patch)
|
38
|
+
return Shellwords.escape(patch.new_file_full_path.to_s)
|
39
|
+
end
|
33
40
|
|
34
|
-
|
41
|
+
def run_tools_for_projects
|
42
|
+
collected_findings = []
|
35
43
|
|
36
44
|
available_tools.each do |tool|
|
37
|
-
|
38
|
-
# Note: this defaults to '.*' and therefore matches everything by default
|
39
|
-
if tool.blacklisted_files_regexp.match?(escaped_path)
|
45
|
+
if tool.execution_mode != 'project'
|
40
46
|
next
|
41
47
|
end
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
collected_findings += run_command(tool, tool.command(''))
|
50
|
+
end
|
51
|
+
|
52
|
+
return collected_findings
|
53
|
+
end
|
54
|
+
|
55
|
+
def run_tools_for_files(filepaths)
|
56
|
+
collected_findings = []
|
47
57
|
|
48
|
-
|
49
|
-
|
58
|
+
available_tools.each do |tool|
|
59
|
+
if tool.execution_mode != 'file'
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
63
|
+
filepaths.each do |filepath|
|
64
|
+
# Skip the patch if the filepath is blacklisted in the 'blacklisted_files' config
|
65
|
+
# Note: this defaults to '.*' and therefore matches everything by default
|
66
|
+
if tool.blacklisted_files_regexp.match?(filepath)
|
67
|
+
next
|
50
68
|
end
|
51
69
|
|
52
|
-
|
53
|
-
|
70
|
+
collected_findings += run_command(tool, tool.command(filepath))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
return collected_findings
|
75
|
+
end
|
76
|
+
|
77
|
+
def run_command(tool, command)
|
78
|
+
collected_findings = []
|
79
|
+
|
80
|
+
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
81
|
+
[stdout, stderr].each do |result_text|
|
82
|
+
while output_line = result_text.gets
|
83
|
+
next if output_line.strip == 'exit status 1'
|
84
|
+
|
85
|
+
collected_findings << {
|
86
|
+
line: output_line,
|
87
|
+
tool: tool,
|
88
|
+
}
|
54
89
|
end
|
55
90
|
end
|
91
|
+
|
92
|
+
while output_line = stderr.gets
|
93
|
+
collected_findings << {
|
94
|
+
line: output_line,
|
95
|
+
tool: tool,
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
return collected_findings
|
101
|
+
end
|
102
|
+
|
103
|
+
def inspect(patch, findings)
|
104
|
+
messages = []
|
105
|
+
|
106
|
+
findings.each do |finding|
|
107
|
+
messages << process_line(patch, finding[:tool], finding[:line])
|
56
108
|
end
|
57
109
|
|
58
110
|
return messages
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pronto-golang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schoknecht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pronto
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 0.9.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.11.
|
22
|
+
version: 0.11.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 0.9.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.11.
|
32
|
+
version: 0.11.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|