pronto-golang 0.0.12 → 0.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aef845e2e4afb8599a35044ce4a59a07443dc4d405128dc33c093ee084932a0e
4
- data.tar.gz: c2a3e0095846f6fb6b6c76710e98df3397deed37ada5c674935eeac7d262b54c
3
+ metadata.gz: bd47b694962afba2ab2b70b52c243f9ee1f0deba76f55d9b9ece5f3ed0e1111b
4
+ data.tar.gz: ebe00aa8879c532f723948a50b75a8a9f99df36c78f1206361e86050cf82e597
5
5
  SHA512:
6
- metadata.gz: 9aa29a44ed4283fe5f1a59a85a7112dcfb116cbba9f9a7924e1fa3a8ebabad988fa723cc3042b1ea9ec39bdca642727e1419fe050b1b147c33cae0bced346fc2
7
- data.tar.gz: 04caac74a80c234131b862b78dbc0678deefa765a2816aafc4fb57bcbd063487a88a34265d774c1c5d8d8b9d08ee7feee00f6bb747082c2bbadaaa85bd66b252
6
+ metadata.gz: 9d28c4bc9ea6c005cf662f33a3e018b9a87b38af0de82955687cd3f100c01084a8f59745dd83c509e91ee079273660f4f5af04adf1b87dc01434171ad45d3297
7
+ data.tar.gz: fae491dea1af02da0a056ceabf214a38a25c9f5b898adc5233c75734d9961779e2157bcb028bc21e3179de1f2f5a8baa9815b1551fd6f7fc2440f157f00a5d9a
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2018 Cash Payment Solutions GmbH
3
+ Copyright (c) 2023 viafintech GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # Pronto runner for Golang
2
2
 
3
- [![Build Status](https://travis-ci.org/Barzahlen/pronto-golang.svg?branch=master)](https://travis-ci.org/Barzahlen/pronto-golang) [![RubyDoc](https://img.shields.io/badge/ruby-doc-green.svg)](http://rubydoc.info/github/Barzahlen/pronto-golang)
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
 
9
9
  | Tool | Install |
10
10
  |----------|----------|
11
11
  | go vet | - |
12
- | golint | go get -u golang.org/x/lint/golint |
13
- | gosec | See [Install instructions](https://github.com/securego/gosec#install) |
14
- | staticcheck | go get -u honnef.co/go/tools/cmd/staticcheck |
15
- | golangci-lint | go get -u github.com/golangci/golangci-lint/cmd/golangci-lint |
12
+ | golint | go install golang.org/x/lint/golint@latest |
13
+ | gosec | go install github.com/securego/gosec/v2/cmd/gosec@v2.14.0 |
14
+ | staticcheck | go install honnef.co/go/tools/cmd/staticcheck@latest |
15
+ | golangci-lint | See [Install instructions](https://golangci-lint.run/usage/install/) |
16
16
 
17
17
  ## Configuring tools
18
18
 
@@ -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
@@ -5,6 +5,13 @@ require_relative '../errors'
5
5
  module Pronto
6
6
  module GolangTools
7
7
  class Gosec < Base
8
+
9
+ # Accepts lines of the following format:
10
+ # [path_to_file:<line_number>] -
11
+ GOSEC_LINE_PATTERN = Regexp.new('^\[(\S+):(\d+)\] - (.+)')
12
+
13
+ ANSI_COLOR_CODING_PATTERN = Regexp.new('\e\[\d+(;\d+)?m')
14
+
8
15
  def self.base_command
9
16
  'gosec'
10
17
  end
@@ -14,9 +21,9 @@ module Pronto
14
21
  end
15
22
 
16
23
  def parse_line(line)
17
- # Accepts lines of the following format:
18
- # [path_to_file:<line_number>] -
19
- if line !~ /^\[(\S+):(\d+)\] - (.+)/
24
+ line = line.gsub(ANSI_COLOR_CODING_PATTERN, '')
25
+
26
+ if !GOSEC_LINE_PATTERN.match(line)
20
27
  raise ::Pronto::GolangSupport::UnprocessableLine.new(line)
21
28
  end
22
29
 
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module GolangVersion
3
- VERSION = '0.0.12'.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.12
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-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,37 +29,37 @@ 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
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '12.0'
39
+ version: '13.0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '12.0'
46
+ version: '13.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '3.8'
53
+ version: '3.12'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '3.8'
61
- description:
62
- email: tobias.schoknecht@barzahlen.de
60
+ version: '3.12'
61
+ description:
62
+ email: tobias.schoknecht@viafintech.com
63
63
  executables: []
64
64
  extensions: []
65
65
  extra_rdoc_files:
@@ -79,11 +79,11 @@ files:
79
79
  - lib/pronto/golang/tools/govet.rb
80
80
  - lib/pronto/golang/tools/staticcheck.rb
81
81
  - lib/pronto/golang/version.rb
82
- homepage: https://github.com/Barzahlen/pronto-golang
82
+ homepage: https://github.com/viafintech/pronto-golang
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.0.3
102
- signing_key:
101
+ rubygems_version: 3.1.6
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: Pronto runner for golang tools
105
105
  test_files: []