code_ownership 1.26.0 → 1.27.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: 988c067afbabcc65d5b697aea162ba1c288787e4d7d9a84a261b00f76859aa6b
4
- data.tar.gz: 6a504214d4470cfd2d1ab103f201069367e39962a390d34382410587a6067e40
3
+ metadata.gz: a58e46098c8c50b7888308dff49901380c69ccad8211946ff5c67d94bfd9c541
4
+ data.tar.gz: 68078aa4407fa01ad485574543dc47af49039d9b0b8a8e55af75a81ff4018ef6
5
5
  SHA512:
6
- metadata.gz: 16b3e48c3cb734857dd66cf03f9d43d89bb92ee3ab92abfc0550004274531e03eef4abc9157fab33e25d815dd5b5c6f055d65987e7526dcb4952212930935678
7
- data.tar.gz: 0f0cc9f4a1b8938e088bc258d5b247d633beaac3c68ddf37ea269fa3740d27d796b9773354e47855e79ecd5e958b49d97fd9f231f42502e62eab508d1d8ea9a1
6
+ metadata.gz: 8cbdffd0dc477b6ed6c69dd61df2d2f6f732b3ae90acb141193e3ec1f3bd6af364c199c3abf2b29f4faddf393e75f39438aacc9f51590b3cc20736fb7deeda3d
7
+ data.tar.gz: e9604ec12ccbe6e1ae14fec8222a7cc93887d7e1ababbbcf318b7a3bbd6277f98add5ff47ff3244b068b030364177460022a8a2419a398c819d227396d2d19ee
@@ -25,24 +25,66 @@ module CodeOwnership
25
25
  # https://help.github.com/en/articles/about-code-owners
26
26
  HEADER
27
27
 
28
- contents = [
29
- header,
28
+ expected_content_lines = [
29
+ *header.split("\n"),
30
+ nil, # For line between header and codeowners_file_lines
30
31
  *codeowners_file_lines,
31
32
  nil, # For end-of-file newline
32
- ].join("\n")
33
+ ]
34
+
35
+ expected_contents = expected_content_lines.join("\n")
36
+ actual_contents = codeowners_filepath.exist? ? codeowners_filepath.read : ""
37
+ actual_content_lines = actual_contents.split("\n")
33
38
 
34
- codeowners_up_to_date = codeowners_filepath.exist? && codeowners_filepath.read == contents
39
+ codeowners_up_to_date = actual_contents == expected_contents
35
40
 
36
41
  errors = T.let([], T::Array[String])
37
42
 
38
43
  if !codeowners_up_to_date
39
44
  if autocorrect
40
- codeowners_filepath.write(contents)
45
+ codeowners_filepath.write(expected_contents)
41
46
  if stage_changes
42
47
  `git add #{codeowners_filepath}`
43
48
  end
44
49
  else
45
- errors << "CODEOWNERS out of date. Ensure pre-commit hook is set up correctly and used. You can also run bin/codeownership validate to update the CODEOWNERS file\n"
50
+ # If there is no current file or its empty, display a shorter message.
51
+ missing_lines = expected_content_lines - actual_content_lines
52
+ extra_lines = actual_content_lines - expected_content_lines
53
+ missing_lines_text = if missing_lines.any?
54
+ <<~COMMENT
55
+ CODEOWNERS should contain the following lines, but does not:
56
+ #{(expected_content_lines - actual_content_lines).map { |line| "- \"#{line}\""}.join("\n")}
57
+ COMMENT
58
+ end
59
+
60
+ extra_lines_text = if extra_lines.any?
61
+ <<~COMMENT
62
+ CODEOWNERS should not contain the following lines, but it does:
63
+ #{(actual_content_lines - expected_content_lines).map { |line| "- \"#{line}\""}.join("\n")}
64
+ COMMENT
65
+ end
66
+
67
+ diff_text = if missing_lines_text && extra_lines_text
68
+ "#{missing_lines_text}\n#{extra_lines_text}".chomp
69
+ elsif missing_lines_text
70
+ missing_lines_text
71
+ elsif extra_lines_text
72
+ extra_lines_text
73
+ else
74
+ ""
75
+ end
76
+
77
+ if actual_contents == ""
78
+ errors << <<~CODEOWNERS_ERROR
79
+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
80
+ CODEOWNERS_ERROR
81
+ else
82
+ errors << <<~CODEOWNERS_ERROR
83
+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
84
+
85
+ #{diff_text.chomp}
86
+ CODEOWNERS_ERROR
87
+ end
46
88
  end
47
89
  end
48
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.26.0
4
+ version: 1.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigrails-teams