danger-missing_codeowners 1.0.2 → 1.1.0

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: 8d13b891d9d0d127146fdcce5e71490ece5feb8ea2d0c9bcfb6bddcd44f83f80
4
- data.tar.gz: f9e6c3ecddc3e1941cfcc12550d3c064fd5af29058eaf726eadeecbcb07238aa
3
+ metadata.gz: 9e93a3e15840e49e1966b6bfae9e59a8bfff84539b3cc1314e6224fab84464d9
4
+ data.tar.gz: 9288cb2e4e84f5c5dd09e4d0363f28276e3241d56c509f03075088401124fb4c
5
5
  SHA512:
6
- metadata.gz: 66f7283e8e7997bec66ecfbfa1ce6a19ce19c5e784c900996504e1880df45e0eadbe4c43a85c7976de76bf8ae429b2d7ae63d262bba5debcdfec948e9f157ddb
7
- data.tar.gz: 9f7d00160a6b909e7d0ab2be5e0f29c30b0ecef12a4de87db2ede4c1e7cc98ce82aa5d45c61af29ac141ff4f25d7e6241eee2ee4fad8255801d96e197458f506
6
+ metadata.gz: 173a41e2f5fe25c8a953e2bd1dfc78900ee4012604f70692785f8475ffae110e8a7ddb21fc20c0f70dd50093c1102804d46566ad89e401f3fd6198d70c0f50df
7
+ data.tar.gz: 4e5a963fb0242853a0a0ad88637f05c2e3ae0c8ff69d8b124e403b79cbccecec866b9f23ea37512b0cdd5594e5a1f0ef6e14b79a9dd6c00e2cbc67f6de2ab06f
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-missing_codeowners (1.0.1)
4
+ danger-missing_codeowners (1.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
  pathspec (~> 1.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.8.0)
12
- public_suffix (>= 2.0.2, < 5.0)
11
+ addressable (2.8.4)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
13
  ast (2.4.2)
14
- claide (1.0.3)
14
+ claide (1.1.0)
15
15
  claide-plugins (0.9.2)
16
16
  cork
17
17
  nap
@@ -20,46 +20,32 @@ GEM
20
20
  colored2 (3.1.2)
21
21
  cork (0.3.0)
22
22
  colored2 (~> 3.1)
23
- danger (8.3.1)
23
+ danger (9.3.0)
24
24
  claide (~> 1.0)
25
25
  claide-plugins (>= 0.9.2)
26
26
  colored2 (~> 3.1)
27
27
  cork (~> 0.1)
28
- faraday (>= 0.9.0, < 2.0)
28
+ faraday (>= 0.9.0, < 3.0)
29
29
  faraday-http-cache (~> 2.0)
30
- git (~> 1.7)
30
+ git (~> 1.13.0)
31
31
  kramdown (~> 2.3)
32
32
  kramdown-parser-gfm (~> 1.0)
33
33
  no_proxy_fix
34
- octokit (~> 4.7)
34
+ octokit (~> 5.0)
35
35
  terminal-table (>= 1, < 4)
36
36
  danger-plugin-api (1.0.0)
37
37
  danger (> 2.0)
38
38
  diff-lcs (1.4.4)
39
- faraday (1.6.0)
40
- faraday-em_http (~> 1.0)
41
- faraday-em_synchrony (~> 1.0)
42
- faraday-excon (~> 1.1)
43
- faraday-httpclient (~> 1.0.1)
44
- faraday-net_http (~> 1.0)
45
- faraday-net_http_persistent (~> 1.1)
46
- faraday-patron (~> 1.0)
47
- faraday-rack (~> 1.0)
48
- multipart-post (>= 1.2, < 3)
39
+ faraday (2.7.5)
40
+ faraday-net_http (>= 2.0, < 3.1)
49
41
  ruby2_keywords (>= 0.0.4)
50
- faraday-em_http (1.0.0)
51
- faraday-em_synchrony (1.0.0)
52
- faraday-excon (1.1.0)
53
- faraday-http-cache (2.2.0)
42
+ faraday-http-cache (2.5.0)
54
43
  faraday (>= 0.8)
55
- faraday-httpclient (1.0.1)
56
- faraday-net_http (1.0.1)
57
- faraday-net_http_persistent (1.2.0)
58
- faraday-patron (1.0.0)
59
- faraday-rack (1.0.0)
44
+ faraday-net_http (3.0.2)
60
45
  ffi (1.15.3)
61
46
  formatador (0.3.0)
62
- git (1.9.1)
47
+ git (1.13.2)
48
+ addressable (~> 2.8)
63
49
  rchardet (~> 1.8)
64
50
  guard (2.18.0)
65
51
  formatador (>= 0.2.4)
@@ -75,7 +61,7 @@ GEM
75
61
  guard (~> 2.1)
76
62
  guard-compat (~> 1.1)
77
63
  rspec (>= 2.99.0, < 4.0)
78
- kramdown (2.3.1)
64
+ kramdown (2.4.0)
79
65
  rexml
80
66
  kramdown-parser-gfm (1.1.0)
81
67
  kramdown (~> 2.0)
@@ -84,16 +70,15 @@ GEM
84
70
  rb-inotify (>= 0.9.7)
85
71
  lumberjack (1.2.8)
86
72
  method_source (1.0.0)
87
- multipart-post (2.1.1)
88
73
  nap (1.1.0)
89
74
  nenv (0.3.0)
90
75
  no_proxy_fix (0.1.2)
91
76
  notiffany (0.1.3)
92
77
  nenv (~> 0.1)
93
78
  shellany (~> 0.0)
94
- octokit (4.21.0)
95
- faraday (>= 0.9)
96
- sawyer (~> 0.8.0, >= 0.5.3)
79
+ octokit (5.6.1)
80
+ faraday (>= 1, < 3)
81
+ sawyer (~> 0.9)
97
82
  open4 (1.3.4)
98
83
  parallel (1.20.1)
99
84
  parser (3.0.2.0)
@@ -102,7 +87,7 @@ GEM
102
87
  pry (0.14.1)
103
88
  coderay (~> 1.1)
104
89
  method_source (~> 1.0)
105
- public_suffix (4.0.6)
90
+ public_suffix (5.0.1)
106
91
  rainbow (3.0.0)
107
92
  rake (10.5.0)
108
93
  rb-fsevent (0.11.0)
@@ -137,17 +122,18 @@ GEM
137
122
  parser (>= 3.0.1.1)
138
123
  ruby-progressbar (1.11.0)
139
124
  ruby2_keywords (0.0.5)
140
- sawyer (0.8.2)
125
+ sawyer (0.9.2)
141
126
  addressable (>= 2.3.5)
142
- faraday (> 0.8, < 2.0)
127
+ faraday (>= 0.17.3, < 3)
143
128
  shellany (0.0.1)
144
- terminal-table (3.0.1)
129
+ terminal-table (3.0.2)
145
130
  unicode-display_width (>= 1.1.1, < 3)
146
131
  thor (1.1.0)
147
132
  unicode-display_width (2.0.0)
148
133
  yard (0.9.26)
149
134
 
150
135
  PLATFORMS
136
+ arm64-darwin-21
151
137
  x86_64-darwin-20
152
138
 
153
139
  DEPENDENCIES
@@ -163,4 +149,4 @@ DEPENDENCIES
163
149
  yard
164
150
 
165
151
  BUNDLED WITH
166
- 2.2.18
152
+ 2.2.29
data/README.md CHANGED
@@ -14,7 +14,7 @@ gem 'danger-missing_codeowners'
14
14
 
15
15
  ## Usage
16
16
 
17
- Just call the `verify` methd in your Dangerfile:
17
+ Just call the `verify` method in your Dangerfile:
18
18
 
19
19
  ```rb
20
20
  missing_codeowners.verify
@@ -29,6 +29,12 @@ missing_codeowners.verify_all_files = true
29
29
  missing_codeowners.verify
30
30
  ```
31
31
 
32
+ If you want to control exactly which files should be checked, provide the files to the `verify` function:
33
+
34
+ ```rb
35
+ missing_codeowners.verify(['my_file.swift'])
36
+ ```
37
+
32
38
  You can also adjust the severity of the execution. Possible valures are `error` (default) and `warning`:
33
39
 
34
40
  ```rb
@@ -36,6 +42,18 @@ missing_codeowners.severity = 'warning'
36
42
  missing_codeowners.verify
37
43
  ```
38
44
 
45
+ ### Integration Tips
46
+
47
+ After adding this plugin you may find a lot of files without CODEOWNERS. To help you during this process, you may find useful to bump the maximum number of files the plugin reports per run:
48
+
49
+ ```rb
50
+ missing_codeowners.max_number_of_files_to_report = 500
51
+ ```
52
+
53
+ You can also try to execute Danger locally (create a new Dangerfile with only this plugin, as other plugins may not work locally):
54
+
55
+ `danger dry_run --dangerfile=<your dangerfile> --base=<your base branch, usually main>`
56
+
39
57
  ## Development
40
58
 
41
59
  1. Clone this repo
@@ -43,6 +61,19 @@ missing_codeowners.verify
43
61
  3. Run `bundle exec rake spec` to run the tests.
44
62
  4. Use `bundle exec guard` to automatically have tests run as you make changes.
45
63
 
64
+ ## Troubleshooting
65
+
66
+ ### Error: invalid byte sequence in US-ASCII
67
+
68
+ Danger requires the filesystem to be encoded with UTF-8, which is usually the default.
69
+
70
+ You can try adding these lines to the top of your Dangerfile:
71
+
72
+ ```rb
73
+ Encoding.default_external = Encoding::UTF_8
74
+ Encoding.default_internal = Encoding::UTF_8
75
+ ```
76
+
46
77
  ## License
47
78
 
48
79
  MIT
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MissingCodeowners
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -40,26 +40,44 @@ module Danger
40
40
  # @return [Bool]
41
41
  attr_accessor :verbose
42
42
 
43
- # Verifies git added and modified files for missing owners.
43
+ # The list of files to ignore. These are naive prefixes, so `foo/`
44
+ # will match `foo/bar`. No globbing.
45
+ #
46
+ # @return [Array<String>]
47
+ attr_accessor :ignored_files
48
+
49
+ # Verifies files for missing owners.
44
50
  # Generates a `markdown` list of warnings for the prose in a corpus of
45
51
  # .markdown and .md files.
46
52
  #
53
+ # @param [String] files
54
+ # The list of files you want to verify, defaults to nil.
55
+ # if nil, modified and added files from the diff will be used.
56
+ # @param [String] ignored_files
57
+ # The list of files you want to ignore, defaults to [].
58
+ # The files are treated as prefixes, so `foo/` will match `foo/bar`.
59
+ #
47
60
  # @return [void]
48
61
  #
49
- def verify
62
+ def verify(*opts)
50
63
  @verify_all_files ||= false
51
64
  @max_number_of_files_to_report ||= 100
52
65
  @severity ||= "error"
53
66
  @verbose ||= false
67
+ @ignored_files ||= opts.first.kind_of?(Hash) ? opts.first[:ignored_files] : []
68
+ files = opts.first.kind_of?(Hash) ? opts.first[:files] : opts.first
69
+
70
+ files_to_verify = (files || files_from_git).delete_if do |file|
71
+ @ignored_files.any? { |ignored_file| file.start_with?(ignored_file) }
72
+ end
54
73
 
55
- files = files_to_verify
56
74
  log "Files to verify:"
57
- log files.join("\n")
75
+ log files_to_verify.join("\n")
58
76
 
59
77
  codeowners_path = find_codeowners_file
60
78
  codeowners_lines = read_codeowners_file(codeowners_path)
61
79
  codeowners_spec = parse_codeowners_spec(codeowners_lines)
62
- @files_missing_codeowners = files.reject { |file| codeowners_spec.match file }
80
+ @files_missing_codeowners = files_to_verify.reject { |file| codeowners_spec.match file }
63
81
 
64
82
  if @files_missing_codeowners.any?
65
83
  log "Files missing CODEOWNERS:"
@@ -77,12 +95,15 @@ module Danger
77
95
 
78
96
  private
79
97
 
80
- def files_to_verify
98
+ def files_from_git
81
99
  @verify_all_files == true ? git_all_files : git_modified_files
82
100
  end
83
101
 
84
102
  def git_modified_files
85
- git.added_files + git.modified_files
103
+ # This algorithm detects added files, modified files and renamed/moved files
104
+ renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h
105
+ post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
106
+ (post_rename_modified_files - git.deleted_files) + git.added_files
86
107
  end
87
108
 
88
109
  def git_all_files
@@ -112,9 +133,9 @@ module Danger
112
133
  else
113
134
  pattern = components[0]
114
135
 
115
- # There is a different between .gitignore spec and CODEOWNERS in regards to nested directories
136
+ # There is a difference between .gitignore spec and CODEOWNERS in regards to nested directories
116
137
  # See frotz/ example in https://git-scm.com/docs/gitignore
117
- # foo/bar (CODEOWNERS) == **/foo/bar (.gitignore)
138
+ # foo/bar (CODEOWNERS) equals **/foo/bar (.gitignore)
118
139
  if pattern.match(%r{^[^/*].*/.+})
119
140
  pattern = "**/#{pattern}"
120
141
  end
@@ -128,6 +128,42 @@ module Danger
128
128
  expect(@dangerfile.status_report[:markdowns].first.to_s).to include("2 other files")
129
129
  expect(@my_plugin.files_missing_codeowners.length).to eq(3)
130
130
  end
131
+
132
+ it "verifies added/modified/renamed files correctly when verify_all_files is false" do
133
+ @my_plugin.verify_all_files = false
134
+
135
+ allow(@my_plugin.git).to receive(:modified_files).and_return(["file_renamed_to_something_else.swift", "modified_file.swift"])
136
+ allow(@my_plugin.git).to receive(:renamed_files).and_return([{ before: "file_renamed_to_something_else.swift", after: "renamed_file.swift" }])
137
+ allow(@my_plugin.git).to receive(:added_files).and_return(["added_file.swift"])
138
+ allow(@my_plugin.git).to receive(:deleted_files).and_return(["deleted_file.swift"])
139
+
140
+ @my_plugin.verify
141
+
142
+ expect(@my_plugin.files_missing_codeowners).to include("added_file.swift")
143
+ expect(@my_plugin.files_missing_codeowners).to include("modified_file.swift")
144
+ expect(@my_plugin.files_missing_codeowners).to include("renamed_file.swift")
145
+ expect(@my_plugin.files_missing_codeowners.length).to eq(3)
146
+ end
147
+
148
+ it "verifies only the provided files" do
149
+ @my_plugin.verify_all_files = true
150
+
151
+ allow(@my_plugin.git).to receive(:added_files).and_return(["added_file.swift"])
152
+
153
+ @my_plugin.verify(["added_file2.swift"])
154
+
155
+ expect(@my_plugin.files_missing_codeowners).to include("added_file2.swift")
156
+ expect(@my_plugin.files_missing_codeowners.length).to eq(1)
157
+ end
158
+
159
+ it "ignores explicitly ignored files" do
160
+ allow(@my_plugin).to receive(:git_modified_files).and_return(["ignored_file.swift", "added_file.swift"])
161
+
162
+ @my_plugin.verify(ignored_files: ["ignored_file.swift"])
163
+
164
+ expect(@my_plugin.files_missing_codeowners).to include("added_file.swift")
165
+ expect(@my_plugin.files_missing_codeowners.length).to eq(1)
166
+ end
131
167
  end
132
168
 
133
169
  context "and invalid CODEOWNERS file" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-missing_codeowners
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - andre-alves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-06 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.0.3
212
+ rubygems_version: 3.2.15
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: A Danger plugin for checking if files have owners.