code_ownership 1.32.4 → 1.32.6

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: f304bfe47eb64942fd8bb38849942a508c37fb9a531397071fea5375fd7430cb
4
- data.tar.gz: 9f24b0084e84b9856f50a119178f661d7b09c50c4c5e2ff48a078dd4276674fd
3
+ metadata.gz: 51a1c1b52a35af9d0c7c7a48101ccd18cd120577bfd038ce83e6552e8b40e878
4
+ data.tar.gz: dc7ed2634d7adf107d59b4a4d9480429894e168b203c9ddc12767743ba52e12e
5
5
  SHA512:
6
- metadata.gz: 384aa25cbb2b268bf9b820de2065783c506b46b560efdec3cc7dc2761dbeab0755d6a5bdc6c8c19b5932f9e36ce581ea13d4f14bfbf138d787977e78e7fa95e1
7
- data.tar.gz: 5917554485514a031239bc110b5ce99f4e84ef9b9a1af69df0564e552889be4fb5d7081d4708961f28ff497607e678c72e0ca19ceda573b6e75b81f85ac675e0
6
+ metadata.gz: 0aa8dd88901d526386ea1f3aae175f013e32e77cbfe7e36b2113ea8c3efccc4e8950f12f09bb01f9b3756a8de9cbe03ae470eee8de5a8bf64d599e8dab1eebf1
7
+ data.tar.gz: be6d7103274d1c628db0d28d1497b62364b5998540ba5e69bcd6ba0d9c2a5d5f834fe3b7aaa70654db7cfb9bbbd3af88c3c1ac9b055de0cf8475d1a9971f1435
@@ -13,7 +13,16 @@ module CodeOwnership
13
13
 
14
14
  sig { returns(T::Array[String]) }
15
15
  def self.actual_contents_lines
16
- (path.exist? ? path.read : "").split("\n")
16
+ if !path.exist?
17
+ [""]
18
+ else
19
+ content = path.read
20
+ lines = path.read.split("\n")
21
+ if content.end_with?("\n")
22
+ lines << ""
23
+ end
24
+ lines
25
+ end
17
26
  end
18
27
 
19
28
  sig { returns(T::Array[T.nilable(String)]) }
@@ -64,9 +73,9 @@ module CodeOwnership
64
73
 
65
74
  [
66
75
  *header.split("\n"),
67
- nil, # For line between header and codeowners_file_lines
76
+ "", # For line between header and codeowners_file_lines
68
77
  *codeowners_file_lines,
69
- nil, # For end-of-file newline
78
+ "", # For end-of-file newline
70
79
  ]
71
80
  end
72
81
 
@@ -10,22 +10,19 @@ module CodeOwnership
10
10
 
11
11
  sig { override.params(files: T::Array[String], autocorrect: T::Boolean, stage_changes: T::Boolean).returns(T::Array[String]) }
12
12
  def validation_errors(files:, autocorrect: true, stage_changes: true)
13
- allow_list = Dir.glob(Private.configuration.unowned_globs)
14
13
  files_by_mapper = Private.glob_cache.files_by_mapper
15
14
 
16
15
  files_not_mapped_at_all = files.select do |file|
17
16
  files_by_mapper.fetch(file, []).count == 0
18
17
  end
19
18
 
20
- files_without_owners = files_not_mapped_at_all - allow_list
21
-
22
19
  errors = T.let([], T::Array[String])
23
20
 
24
- if files_without_owners.any?
21
+ if files_not_mapped_at_all.any?
25
22
  errors << <<~MSG
26
23
  Some files are missing ownership:
27
24
 
28
- #{files_without_owners.map { |file| "- #{file}" }.join("\n")}
25
+ #{files_not_mapped_at_all.map { |file| "- #{file}" }.join("\n")}
29
26
  MSG
30
27
  end
31
28
 
@@ -14,8 +14,10 @@ module CodeOwnership
14
14
 
15
15
  actual_content_lines = CodeownersFile.actual_contents_lines
16
16
  expected_content_lines = CodeownersFile.expected_contents_lines
17
- codeowners_up_to_date = actual_content_lines == expected_content_lines
17
+ missing_lines = expected_content_lines - actual_content_lines
18
+ extra_lines = actual_content_lines - expected_content_lines
18
19
 
20
+ codeowners_up_to_date = !missing_lines.any? && !extra_lines.any?
19
21
  errors = T.let([], T::Array[String])
20
22
 
21
23
  if !codeowners_up_to_date
@@ -26,8 +28,6 @@ module CodeOwnership
26
28
  end
27
29
  else
28
30
  # If there is no current file or its empty, display a shorter message.
29
- missing_lines = expected_content_lines - actual_content_lines
30
- extra_lines = actual_content_lines - expected_content_lines
31
31
 
32
32
  missing_lines_text = if missing_lines.any?
33
33
  <<~COMMENT
@@ -53,7 +53,7 @@ module CodeOwnership
53
53
  ""
54
54
  end
55
55
 
56
- if actual_content_lines == []
56
+ if actual_content_lines == [""]
57
57
  errors << <<~CODEOWNERS_ERROR
58
58
  CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
59
59
  CODEOWNERS_ERROR
@@ -76,7 +76,7 @@ module CodeOwnership
76
76
  sig { returns(T::Array[String]) }
77
77
  def self.tracked_files
78
78
  @tracked_files ||= T.let(@tracked_files, T.nilable(T::Array[String]))
79
- @tracked_files ||= Dir.glob(configuration.owned_globs)
79
+ @tracked_files ||= Dir.glob(configuration.owned_globs) - Dir.glob(configuration.unowned_globs)
80
80
  end
81
81
 
82
82
  sig { params(team_name: String, location_of_reference: String).returns(CodeTeams::Team) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.4
4
+ version: 1.32.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers