rubocop-changed 0.0.2 → 0.0.4

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: 8649e7a626497e84a5a036b3914c58730983db8eb18daf7ca36eaad53931c03d
4
- data.tar.gz: 94cfdabd8eca2087ce11767a219429da91fedeeaf08de0f65564c8a99e702532
3
+ metadata.gz: '09483b56d167f91f1954a53c6e9c073195d31701b34db56502ecf9a5ffefc397'
4
+ data.tar.gz: 3be0d8c2565f4339a5e6dccacc064daec628613c9991b4bc51b54e8d8828db5c
5
5
  SHA512:
6
- metadata.gz: 4d85ad0827e304a6c83fd8fc59c703a0c13b3ce1670c56e97873f81f96264ff8c05acc9838f16b62318ab2aaa0889469c896365491aa6a2a414403172f55ed38
7
- data.tar.gz: 979f5697bcda191823041b345adbc3e63ccfdc19eb1a7e8c6a253f8f0a78c9fd706fe39ab5f3dd2e24d8ae5bb00b07499153c1620f564d507a85074d47e4cbbd
6
+ metadata.gz: 17ac53cd4aa5c7d6699160fce359444d9a4c03347698a4c9a16020547a2847e6a5359adbe4f90304b8a32273bb3f8a340a2fc9a35d49be7af1002d94aeb1a1d9
7
+ data.tar.gz: 2aa6cf3ff10ea4a7c7b736bf6180d4998c119f3678582f94440a15457272ef40e62f250b9a2cbcc7b0dcfc2ad192f40af3420e2d3a6dfe68ed2b97ee08dfaf27
@@ -6,23 +6,30 @@ module RuboCop
6
6
  class CommandError < StandardError
7
7
  ISSUE_URL = 'https://github.com/dukaev/rubocop-changed/issues'
8
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.'
9
+ 'git: not found' =>
10
+ 'The git binary is not available in the PATH. You may need to install git or update the PATH variable to ' \
11
+ 'include the installation directory.',
12
+ 'fatal: not a git repository' =>
13
+ 'The .git directory was not found. Rubocop-changed only works with projects in a git repository.',
14
+ 'fatal: ambiguous argument' =>
15
+ 'The set branch was not found. Ensure that the branch has a local tracking branch or specify the full ' \
16
+ 'reference in the RUBOCOP_CHANGED_BRANCH_NAME environment variable.'
12
17
  }.freeze
13
18
 
14
19
  def initialize(output, cmd)
15
20
  key = MESSAGES.keys.find { |error| output.include?(error) }
16
- msg = MESSAGES[key] || default_message(cmd, output)
17
-
18
- super(msg)
21
+ message = MESSAGES[key] || "Unknown error. Please, create issue on #{ISSUE_URL}."
22
+ super(exception_message(cmd, output, message))
19
23
  end
20
24
 
21
- def default_message(cmd, output)
25
+ def exception_message(cmd, output, message)
22
26
  <<~HEREDOC
23
- Unknown error. Please, create issue on #{ISSUE_URL}.
24
- Command: #{cmd}
25
- Message: #{output}
27
+ #{message}
28
+ Command:
29
+ #{cmd}
30
+ Output:
31
+ #{output}
32
+
26
33
  HEREDOC
27
34
  end
28
35
  end
@@ -11,11 +11,16 @@ module RuboCop
11
11
  GIT_COMMANDS = {
12
12
  changed_files: 'git diff-tree -r --no-commit-id --name-status %<compared_branch>s %<current_branch>s',
13
13
  current_branch: 'git rev-parse --abbrev-ref HEAD',
14
- default_branch: 'git symbolic-ref refs/remotes/origin/HEAD'
14
+ default_branch: 'git symbolic-ref refs/remotes/origin/HEAD',
15
+ new_files: 'git status --porcelain=v1'
15
16
  }.freeze
16
17
 
17
18
  class << self
18
19
  def changed_files(branch = compared_branch)
20
+ (diffed_files(branch) + new_files).uniq
21
+ end
22
+
23
+ def diffed_files(branch = compared_branch)
19
24
  command = format(
20
25
  GIT_COMMANDS.fetch(:changed_files),
21
26
  compared_branch: branch,
@@ -34,6 +39,12 @@ module RuboCop
34
39
  branch
35
40
  end
36
41
 
42
+ def new_files
43
+ command = format(GIT_COMMANDS.fetch(:new_files))
44
+ run(command).split("\n")
45
+ .map { |file| File.absolute_path(file[3..]) }
46
+ end
47
+
37
48
  private
38
49
 
39
50
  def current_branch
@@ -50,8 +61,10 @@ module RuboCop
50
61
  end
51
62
 
52
63
  def run(cmd)
64
+ warn("COMMAND: #{cmd}") if verbose_logging?
53
65
  output = shell(cmd)
54
- raise Rubocop::Changed::ExecutionError.new(output, cmd) if output.match?(Regexp.union(ERRORS))
66
+ warn("OUTPUT: #{output}\n") if verbose_logging?
67
+ raise CommandError.new(output, cmd) if output.match?(Regexp.union(ERRORS))
55
68
 
56
69
  output
57
70
  end
@@ -59,6 +72,10 @@ module RuboCop
59
72
  def shell(cmd)
60
73
  `#{cmd} 2>&1`
61
74
  end
75
+
76
+ def verbose_logging?
77
+ ENV.fetch('RUBOCOP_CHANGED_VERBOSE_LOGGING', false) != false
78
+ end
62
79
  end
63
80
  end
64
81
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Changed
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-changed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslan Dukaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-13 00:00:00.000000000 Z
11
+ date: 2024-01-27 00:00:00.000000000 Z
12
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: rubocop
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
59
  - !ruby/object:Gem::Version
74
60
  version: '0'
75
61
  requirements: []
76
- rubygems_version: 3.1.4
62
+ rubygems_version: 3.4.10
77
63
  signing_key:
78
64
  specification_version: 4
79
65
  summary: RuboCop extensions for lint only changed files in PRs