danger-missing_codeowners 1.0.2 → 1.0.3

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: c96c6f07f74d912ae60feb08a802ebd4a1aa7807ece970520614c77a5847ec13
4
+ data.tar.gz: a872b00996c8a7c42e3d73c648fb792a3e22acadb340cc53ff8865f54d43408c
5
5
  SHA512:
6
- metadata.gz: 66f7283e8e7997bec66ecfbfa1ce6a19ce19c5e784c900996504e1880df45e0eadbe4c43a85c7976de76bf8ae429b2d7ae63d262bba5debcdfec948e9f157ddb
7
- data.tar.gz: 9f7d00160a6b909e7d0ab2be5e0f29c30b0ecef12a4de87db2ede4c1e7cc98ce82aa5d45c61af29ac141ff4f25d7e6241eee2ee4fad8255801d96e197458f506
6
+ metadata.gz: 0ee3995c868961f7431b131748fe39e2b4f24689dd1fe1563e3de74bb33a6bb512fbc0a955029083933ae664193022f929dfc3040c9a8447a5affe62940a1388
7
+ data.tar.gz: 52a36f59123b2ff15bc68af51a2f2bd93efab45c6f4c3d7e25f525cab493b326db3e8f7886c3690a4e1d4677a415b825f28524cdc4a93ac5bfccf55240515961
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-missing_codeowners (1.0.1)
4
+ danger-missing_codeowners (1.0.3)
5
5
  danger-plugin-api (~> 1.0)
6
6
  pathspec (~> 1.0.0)
7
7
 
@@ -20,7 +20,7 @@ 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 (8.4.2)
24
24
  claide (~> 1.0)
25
25
  claide-plugins (>= 0.9.2)
26
26
  colored2 (~> 3.1)
@@ -36,7 +36,7 @@ GEM
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)
39
+ faraday (1.8.0)
40
40
  faraday-em_http (~> 1.0)
41
41
  faraday-em_synchrony (~> 1.0)
42
42
  faraday-excon (~> 1.1)
@@ -141,7 +141,7 @@ GEM
141
141
  addressable (>= 2.3.5)
142
142
  faraday (> 0.8, < 2.0)
143
143
  shellany (0.0.1)
144
- terminal-table (3.0.1)
144
+ terminal-table (3.0.2)
145
145
  unicode-display_width (>= 1.1.1, < 3)
146
146
  thor (1.1.0)
147
147
  unicode-display_width (2.0.0)
@@ -163,4 +163,4 @@ DEPENDENCIES
163
163
  yard
164
164
 
165
165
  BUNDLED WITH
166
- 2.2.18
166
+ 2.2.28
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.0.3"
5
5
  end
@@ -40,26 +40,31 @@ module Danger
40
40
  # @return [Bool]
41
41
  attr_accessor :verbose
42
42
 
43
- # Verifies git added and modified files for missing owners.
43
+ # Verifies files for missing owners.
44
44
  # Generates a `markdown` list of warnings for the prose in a corpus of
45
45
  # .markdown and .md files.
46
46
  #
47
+ # @param [String] files
48
+ # The list of files you want to verify, defaults to nil.
49
+ # if nil, modified and added files from the diff will be used.
50
+ #
47
51
  # @return [void]
48
52
  #
49
- def verify
53
+ def verify(files = nil)
50
54
  @verify_all_files ||= false
51
55
  @max_number_of_files_to_report ||= 100
52
56
  @severity ||= "error"
53
57
  @verbose ||= false
54
58
 
55
- files = files_to_verify
59
+ files_to_verify = files || files_from_git
60
+
56
61
  log "Files to verify:"
57
- log files.join("\n")
62
+ log files_to_verify.join("\n")
58
63
 
59
64
  codeowners_path = find_codeowners_file
60
65
  codeowners_lines = read_codeowners_file(codeowners_path)
61
66
  codeowners_spec = parse_codeowners_spec(codeowners_lines)
62
- @files_missing_codeowners = files.reject { |file| codeowners_spec.match file }
67
+ @files_missing_codeowners = files_to_verify.reject { |file| codeowners_spec.match file }
63
68
 
64
69
  if @files_missing_codeowners.any?
65
70
  log "Files missing CODEOWNERS:"
@@ -77,12 +82,15 @@ module Danger
77
82
 
78
83
  private
79
84
 
80
- def files_to_verify
85
+ def files_from_git
81
86
  @verify_all_files == true ? git_all_files : git_modified_files
82
87
  end
83
88
 
84
89
  def git_modified_files
85
- git.added_files + git.modified_files
90
+ # This algorithm detects added files, modified files and renamed/moved files
91
+ renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h
92
+ post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
93
+ (post_rename_modified_files - git.deleted_files) + git.added_files
86
94
  end
87
95
 
88
96
  def git_all_files
@@ -112,9 +120,9 @@ module Danger
112
120
  else
113
121
  pattern = components[0]
114
122
 
115
- # There is a different between .gitignore spec and CODEOWNERS in regards to nested directories
123
+ # There is a difference between .gitignore spec and CODEOWNERS in regards to nested directories
116
124
  # See frotz/ example in https://git-scm.com/docs/gitignore
117
- # foo/bar (CODEOWNERS) == **/foo/bar (.gitignore)
125
+ # foo/bar (CODEOWNERS) equals **/foo/bar (.gitignore)
118
126
  if pattern.match(%r{^[^/*].*/.+})
119
127
  pattern = "**/#{pattern}"
120
128
  end
@@ -128,6 +128,33 @@ 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
131
158
  end
132
159
 
133
160
  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.0.3
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: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api