rubocop-changed 0.0.1
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 +7 -0
- data/lib/rubocop/changed/command_error.rb +30 -0
- data/lib/rubocop/changed/commands.rb +60 -0
- data/lib/rubocop/changed/files.rb +31 -0
- data/lib/rubocop/changed/version.rb +7 -0
- data/lib/rubocop/target_finder.rb +12 -0
- data/lib/rubocop-changed.rb +7 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e0fdb50a8da61fabb8c8f3e568b35eeb96f7a1e2e98c1205f983337d1053f28a
|
4
|
+
data.tar.gz: 830d5e846cadb95e7451acaeb9fe455cb0dd65f4299326116c439c71637162a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0780a055cf605241b78b8c498974bfd29a449a87ceec146f1605e20cd3dc5451a45f83af72d98bab96099f622ab8b4e4d2534ba14d133058525a55337e2b286b'
|
7
|
+
data.tar.gz: 1e270f0df26d920df86b3c15f79b5334b58be5929b6ec9147c6389bb32714b8f21468c733d5951e0199d32035cba91856c544fe0946186a1b5fb7400c7302849
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Changed
|
5
|
+
# This class get changed
|
6
|
+
class CommandError < StandardError
|
7
|
+
ISSUE_URL = 'https://github.com/dukaev/rubocop-changed/issues'
|
8
|
+
MESSAGES = {
|
9
|
+
'git: not found' => 'Git is not installed. Make shure that container has git installed',
|
10
|
+
'fatal: not a git repository' => 'Not found .git directory. Make shure that branch is copied',
|
11
|
+
'fatal: ambiguous argument' => 'Not found setted branch. Make shure that branch is downladed.'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def initialize(output, cmd)
|
15
|
+
key = MESSAGES.keys.find { |error| output.include?(error) }
|
16
|
+
msg = MESSAGES[key] || default_message(cmd, output)
|
17
|
+
|
18
|
+
super(msg)
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_message(cmd, output)
|
22
|
+
<<~HEREDOC
|
23
|
+
Unknown error. Please, create issue on #{ISSUE_URL}.
|
24
|
+
Command: #{cmd}
|
25
|
+
Message: #{output}
|
26
|
+
HEREDOC
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Changed
|
5
|
+
# This class get changed
|
6
|
+
class Commands
|
7
|
+
ERRORS = [
|
8
|
+
'git: command not found',
|
9
|
+
'fatal:'
|
10
|
+
].freeze
|
11
|
+
GIT_COMMANDS = {
|
12
|
+
changed_files: 'git diff-tree -r --no-commit-id --name-only head %s',
|
13
|
+
current_branch: 'git rev-parse --abbrev-ref HEAD',
|
14
|
+
default_branch: 'git symbolic-ref refs/remotes/origin/HEAD'
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def changed_files(branch = compared_branch)
|
19
|
+
run(GIT_COMMANDS.fetch(:changed_files) % branch)
|
20
|
+
.split("\n")
|
21
|
+
.map { |file| File.absolute_path(file) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def compared_branch
|
25
|
+
branch = setted_branch || default_branch
|
26
|
+
raise ArgumentError, 'You can not compare branch with itself' if branch == current_branch
|
27
|
+
|
28
|
+
branch
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def current_branch
|
34
|
+
run(GIT_COMMANDS.fetch(:current_branch))
|
35
|
+
.gsub("\n", '')
|
36
|
+
end
|
37
|
+
|
38
|
+
def setted_branch
|
39
|
+
ENV.fetch('RUBOCOP_CHANGED_BRANCH_NAME', nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_branch
|
43
|
+
run(GIT_COMMANDS.fetch(:default_branch))
|
44
|
+
.gsub(%r{refs/remotes/origin/|\n}, '')
|
45
|
+
end
|
46
|
+
|
47
|
+
def run(cmd)
|
48
|
+
output = shell(cmd)
|
49
|
+
raise Rubocop::Changed::ExecutionError.new(output, cmd) if output.match?(Regexp.union(ERRORS))
|
50
|
+
|
51
|
+
output
|
52
|
+
end
|
53
|
+
|
54
|
+
def shell(cmd)
|
55
|
+
`#{cmd} 2>&1`
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Changed
|
5
|
+
# This class get changed files matching the pattern.
|
6
|
+
class Files
|
7
|
+
class << self
|
8
|
+
def call(patterns)
|
9
|
+
files = RuboCop::Changed::Commands.changed_files
|
10
|
+
filter(patterns, files)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def filter(patterns, files)
|
16
|
+
# Matching Dir.glob by pattern has difference with File.fnmatch.
|
17
|
+
# To match files on first level of directory, we need additional pattern with `*`.
|
18
|
+
# Covers case for find_files(...) in RuboCop::TargetFinder:
|
19
|
+
# `patterns = [File.join(base_dir, '**/*')] if patterns.empty?`
|
20
|
+
if patterns.one? && patterns.first.end_with?('/**/*')
|
21
|
+
pattern = patterns.first.gsub('/**/*', '/*')
|
22
|
+
patterns << pattern
|
23
|
+
end
|
24
|
+
|
25
|
+
union_patterns = "{#{patterns.join(',')}}"
|
26
|
+
files.select { |file| File.fnmatch(union_patterns, file, File::FNM_EXTGLOB) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RuboCop::TargetFinder
|
4
|
+
# Override Dir.glob for find_files method.
|
5
|
+
# Dir.glob calls only with two types of flags.
|
6
|
+
# For case when need to find files will be used RuboCop::Changed::Files.call
|
7
|
+
class Dir < ::Dir
|
8
|
+
def self.glob(patterns, flags)
|
9
|
+
flags == 4 ? RuboCop::Changed::Files.call(patterns) : super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-changed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aslan Dukaev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.12.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- dukaev999@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/rubocop-changed.rb
|
49
|
+
- lib/rubocop/changed/command_error.rb
|
50
|
+
- lib/rubocop/changed/commands.rb
|
51
|
+
- lib/rubocop/changed/files.rb
|
52
|
+
- lib/rubocop/changed/version.rb
|
53
|
+
- lib/rubocop/target_finder.rb
|
54
|
+
homepage: https://github.com/dukaev/rubocop-changed
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
allowed_push_host: https://rubygems.org
|
59
|
+
source_code_uri: https://github.com/dukaev/rubocop-changed
|
60
|
+
rubygems_mfa_required: 'true'
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.6.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.1.4
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: RuboCop extensions for lint only changed files in PRs
|
80
|
+
test_files: []
|