gitab_codeowners_checker 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +9 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +42 -0
- data/README.md +51 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/gitlab-codeowners-checker +37 -0
- data/gitab_codeowners_checker.gemspec +26 -0
- data/lib/gitab_codeowners_checker/checkers/no_owner.rb +20 -0
- data/lib/gitab_codeowners_checker/codeowners_file.rb +26 -0
- data/lib/gitab_codeowners_checker/pattern.rb +21 -0
- data/lib/gitab_codeowners_checker/project.rb +26 -0
- data/lib/gitab_codeowners_checker/version.rb +5 -0
- data/lib/gitab_codeowners_checker.rb +10 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 248bb34aa3abedfe0a23e84f69b414a163dec461d08ad3cfc0791e7e6054705f
|
4
|
+
data.tar.gz: 850e195414b819b11d3d656ed900e64a57edb7d32f3c605c9b989c9f8d85c111
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 866c40d6768afa3988c636fba6014733b25dbe1f5af203c12bc02ca35658393e12ec783ab060d8477842ca3a8e6d008f61ca6d560d2811273dad1b04b721325f
|
7
|
+
data.tar.gz: d5fdc32df5bb6a918b05ca7e83d5f2835ac3e51bddf626a72fc3d514a6b64e26581971497baf738ffd7b971bc74de438e9b842fbec430d7daed258b9022c28ce
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Exclude:
|
9
|
+
- "gitlab_codeowners_checker.gemspec"
|
10
|
+
|
11
|
+
Style/CommentedKeyword:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Layout/ArgumentAlignment:
|
15
|
+
EnforcedStyle: with_fixed_indentation
|
16
|
+
|
17
|
+
Layout/ParameterAlignment:
|
18
|
+
EnforcedStyle: with_fixed_indentation
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 120
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.8
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gitab_codeowners_checker (0.1.0)
|
5
|
+
thor (> 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
parallel (1.22.1)
|
12
|
+
parser (3.1.2.1)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.1.1)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.5.0)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rubocop (0.93.1)
|
19
|
+
parallel (~> 1.10)
|
20
|
+
parser (>= 2.7.1.5)
|
21
|
+
rainbow (>= 2.2.2, < 4.0)
|
22
|
+
regexp_parser (>= 1.8)
|
23
|
+
rexml
|
24
|
+
rubocop-ast (>= 0.6.0)
|
25
|
+
ruby-progressbar (~> 1.7)
|
26
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
27
|
+
rubocop-ast (1.17.0)
|
28
|
+
parser (>= 3.1.1.0)
|
29
|
+
ruby-progressbar (1.11.0)
|
30
|
+
thor (1.1.0)
|
31
|
+
unicode-display_width (1.8.0)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
x86_64-darwin-21
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
gitab_codeowners_checker!
|
38
|
+
rake (~> 13.0)
|
39
|
+
rubocop (~> 0.81)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.3.15
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# GitabCodeownersChecker
|
2
|
+
|
3
|
+
GitabCodeownersChecker is a CLI utility that is aimed to help with:
|
4
|
+
|
5
|
+
- finding project files without CODEOWNERS mention
|
6
|
+
- checking if CODEOWNERS references are set for specific files
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```
|
13
|
+
gem install 'gitab_codeowners_checker' --source 'https://nexus.sbmt.io/repository/ruby-gems-sbermarket/'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
## Getting help
|
19
|
+
|
20
|
+
```shell
|
21
|
+
gitlab-codeowners-checker help check_codeowners
|
22
|
+
```
|
23
|
+
|
24
|
+
## List project files without owners
|
25
|
+
|
26
|
+
```shell
|
27
|
+
gitlab-codeowners-checker check_codeowners -p app/controllers app/jobs app/consumers -i app/controllers/concerns -e rb -r /app/instamart/
|
28
|
+
```
|
29
|
+
|
30
|
+
## Checking specific files
|
31
|
+
|
32
|
+
```shell
|
33
|
+
gitlab-codeowners-checker check_codeowners -r /app/instamart/ --files app/jobs/shoppers/separate_reviews/export_shipment_review_rate_job.rb app/jobs/shipments/store_fiscal_data_job.rb
|
34
|
+
```
|
35
|
+
|
36
|
+
### Checking files changed within MR
|
37
|
+
|
38
|
+
```shell
|
39
|
+
gitlab-codeowners-checker check_codeowners -r /app/instamart/ --files $({ git diff $(git merge-base --fork-point origin/master) --name-only --diff-filter=MA | uniq | grep '\.rb$'; })
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.sbmt.io/nstmrt/rubygems/gitlab-codeowners-checker.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'gitab_codeowners_checker'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'thor'
|
6
|
+
require_relative '../lib/gitab_codeowners_checker'
|
7
|
+
|
8
|
+
class CLI < Thor
|
9
|
+
desc 'check_codeowners', 'check codowners'
|
10
|
+
method_option :files, aliases: '-f', type: :array, desc: 'a list of files to check'
|
11
|
+
method_option :root_path, aliases: '-r', desc: 'path to application root folder', default: Dir.pwd
|
12
|
+
method_option :file_ext, aliases: '-e', desc: 'a file extenstion to filter files (example - "rb")'
|
13
|
+
method_option :paths, aliases: '-p', type: :array, desc: 'a list of paths to select'
|
14
|
+
method_option :ignore_paths, aliases: '-i', type: :array, desc: 'a list of paths to ignore'
|
15
|
+
def check_codeowners # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
16
|
+
opts = {
|
17
|
+
root_path: options.fetch(:root_path) || '.',
|
18
|
+
paths: options[:paths],
|
19
|
+
ignore_paths: options[:ignore_paths],
|
20
|
+
file_ext: options[:file_ext] || ''
|
21
|
+
}.compact
|
22
|
+
|
23
|
+
project = GitlabCodeownersChecks::Project.new(opts)
|
24
|
+
checker = GitlabCodeownersChecker::Checkers::NoOwner.new(
|
25
|
+
files: options[:files] || project.file_paths,
|
26
|
+
codeowners: project.codeowners
|
27
|
+
)
|
28
|
+
|
29
|
+
return if checker.files_without_owner.empty?
|
30
|
+
|
31
|
+
warn('Files without codeowners:')
|
32
|
+
checker.files_without_owner.each { |file| warn file }
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
CLI.start(ARGV)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/gitab_codeowners_checker/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'gitab_codeowners_checker'
|
7
|
+
spec.version = GitabCodeownersChecker::VERSION
|
8
|
+
spec.authors = ['Nikita Babushkin']
|
9
|
+
spec.email = ['nikita.babushkin@sbermarket.ru']
|
10
|
+
|
11
|
+
spec.summary = 'Check every project file has codeowners.'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://gitlab.sbmt.io/nstmrt/rubygems/gitlab-codeowners-checker'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'thor', '> 1'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.81'
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../project'
|
4
|
+
|
5
|
+
module GitlabCodeownersChecker
|
6
|
+
module Checkers
|
7
|
+
class NoOwner
|
8
|
+
def initialize(files:, codeowners:)
|
9
|
+
@files = files
|
10
|
+
@codeowners = codeowners
|
11
|
+
end
|
12
|
+
|
13
|
+
def files_without_owner
|
14
|
+
@files_without_owner ||= @files.each_with_object([]) do |f, acc|
|
15
|
+
acc.push(f) unless @codeowners.patterns.find { |p| p.match?(f) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './pattern'
|
4
|
+
|
5
|
+
module GitlabCodeownersChecker
|
6
|
+
class CodeownersFile
|
7
|
+
def initialize(path)
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
def patterns
|
13
|
+
@patterns ||= begin
|
14
|
+
File.readlines(@path).each_with_object([]) do |line, acc|
|
15
|
+
acc.push(Pattern.from_file_line(line)) if contains_pattern?(line)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def contains_pattern?(str)
|
23
|
+
str.include?('@')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabCodeownersChecker
|
4
|
+
class Pattern
|
5
|
+
def self.from_file_line(str)
|
6
|
+
path, *owners = str.split(' ')
|
7
|
+
pattern = path[-1] == '/' ? /\A#{Regexp.escape(path)}.+/ : path
|
8
|
+
new(pattern, owners)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(pattern, owners)
|
12
|
+
@pattern = pattern
|
13
|
+
@owners = owners
|
14
|
+
end
|
15
|
+
attr_reader :pattern, :owners
|
16
|
+
|
17
|
+
def match?(str)
|
18
|
+
@pattern.is_a?(Regexp) ? @pattern.match?(str) : str == @pattern
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabCodeownersChecks
|
4
|
+
class Project
|
5
|
+
def initialize(root_path:, codeowners_path: nil, paths: [''], ignore_paths: [], file_ext: '')
|
6
|
+
@root_path = root_path
|
7
|
+
@paths = paths
|
8
|
+
@ignore_paths = ignore_paths
|
9
|
+
@file_ext = file_ext
|
10
|
+
codeowners_path ||= 'CODEOWNERS'
|
11
|
+
@codeowners = GitlabCodeownersChecker::CodeownersFile.new(
|
12
|
+
Pathname.new(codeowners_path).absolute? ? codeowners_path : File.join(@root_path, codeowners_path)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
attr_reader :root_path, :codeowners
|
16
|
+
|
17
|
+
def file_paths
|
18
|
+
@file_paths ||= @paths.flat_map do |ptc|
|
19
|
+
abs_path = File.join(@root_path, ptc, "**/*#{@file_ext}")
|
20
|
+
Dir.glob(abs_path).map { |path| path.sub(@root_path, '') }.reject do |path|
|
21
|
+
@ignore_paths.any? { |pti| path.start_with?(pti) }
|
22
|
+
end
|
23
|
+
end.sort
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'gitab_codeowners_checker/version'
|
4
|
+
require_relative 'gitab_codeowners_checker/codeowners_file'
|
5
|
+
require_relative 'gitab_codeowners_checker/checkers/no_owner'
|
6
|
+
|
7
|
+
module GitabCodeownersChecker
|
8
|
+
class Error < StandardError; end
|
9
|
+
# Your code goes here...
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitab_codeowners_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikita Babushkin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.81'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.81'
|
41
|
+
description: Check every project file has codeowners.
|
42
|
+
email:
|
43
|
+
- nikita.babushkin@sbermarket.ru
|
44
|
+
executables:
|
45
|
+
- gitlab-codeowners-checker
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".gitlab-ci.yml"
|
51
|
+
- ".rubocop.yml"
|
52
|
+
- ".ruby-version"
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- exe/gitlab-codeowners-checker
|
60
|
+
- gitab_codeowners_checker.gemspec
|
61
|
+
- lib/gitab_codeowners_checker.rb
|
62
|
+
- lib/gitab_codeowners_checker/checkers/no_owner.rb
|
63
|
+
- lib/gitab_codeowners_checker/codeowners_file.rb
|
64
|
+
- lib/gitab_codeowners_checker/pattern.rb
|
65
|
+
- lib/gitab_codeowners_checker/project.rb
|
66
|
+
- lib/gitab_codeowners_checker/version.rb
|
67
|
+
homepage: https://gitlab.sbmt.io/nstmrt/rubygems/gitlab-codeowners-checker
|
68
|
+
licenses: []
|
69
|
+
metadata:
|
70
|
+
homepage_uri: https://gitlab.sbmt.io/nstmrt/rubygems/gitlab-codeowners-checker
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.5.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.2.3
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Check every project file has codeowners.
|
90
|
+
test_files: []
|