pronto-golang 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0542e6e9b70b08409a682de22445a2a8a279b2352fed6e69bc461e3ee785aba4
4
- data.tar.gz: bdb4f8fe3d184772a0e037f1636fa3a6487f2565f8a09fbf7d55f97c62e872ca
3
+ metadata.gz: bd47b694962afba2ab2b70b52c243f9ee1f0deba76f55d9b9ece5f3ed0e1111b
4
+ data.tar.gz: ebe00aa8879c532f723948a50b75a8a9f99df36c78f1206361e86050cf82e597
5
5
  SHA512:
6
- metadata.gz: ab3887662aa406ea3ef6a1b3a2498fa1683cd5f72ed4599e1ae9aeb28e8c694a4c7ae3cc8e1b5a81d0f4ce146d9402f80a218e12b4b81c9f052f81b56a9904d2
7
- data.tar.gz: 45c1b18511917b2fb85039b8d75770541f17cc65d38172e6f7cda5ef98b7004cfe9e05e61f855b94b98ae03079d72cda6b2688bfb4f613b5fd59f078add1b266
6
+ metadata.gz: 9d28c4bc9ea6c005cf662f33a3e018b9a87b38af0de82955687cd3f100c01084a8f59745dd83c509e91ee079273660f4f5af04adf1b87dc01434171ad45d3297
7
+ data.tar.gz: fae491dea1af02da0a056ceabf214a38a25c9f5b898adc5233c75734d9961779e2157bcb028bc21e3179de1f2f5a8baa9815b1551fd6f7fc2440f157f00a5d9a
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://golang.org) tools
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,9 +41,21 @@ 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
  file_path, line_number, _, message = line.split(':', 4)
42
53
 
54
+ dir = directory('')
55
+ if dir != ''
56
+ file_path = File.join(dir, file_path)
57
+ end
58
+
43
59
  return file_path, line_number, :warning, message.to_s.strip
44
60
  end
45
61
  end
@@ -4,6 +4,10 @@ module Pronto
4
4
  def self.base_command
5
5
  'golangci-lint'
6
6
  end
7
+
8
+ def execution_mode
9
+ 'project'
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module GolangVersion
3
- VERSION = '0.0.13'.freeze
3
+ VERSION = '0.0.14'.freeze
4
4
  end
5
5
  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
- .select { |patch| valid_patch?(patch) }
22
- .map { |patch| inspect(patch) }
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 inspect(patch)
32
- escaped_path = Shellwords.escape(patch.new_file_full_path.to_s)
37
+ def patch_file_path(patch)
38
+ return Shellwords.escape(patch.new_file_full_path.to_s)
39
+ end
33
40
 
34
- messages = []
41
+ def run_tools_for_projects
42
+ collected_findings = []
35
43
 
36
44
  available_tools.each do |tool|
37
- # Skip the patch if the filepath is blacklisted in the 'blacklisted_files' config
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
- Open3.popen3("#{tool.command(escaped_path)}") do |stdin, stdout, stderr, wait_thr|
44
- [stdout, stderr].each do |result_text|
45
- while output_line = result_text.gets
46
- next if output_line.strip == 'exit status 1'
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
- messages << process_line(patch, tool, output_line)
49
- end
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
- while output_line = stderr.gets
53
- process_line(patch, tool, output_line)
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.13
4
+ version: 0.0.14
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-01-16 00:00:00.000000000 Z
11
+ date: 2023-04-24 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.0
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.0
32
+ version: 0.11.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement