项目作者: cerner

项目描述 :
Cerner code owner validator library for inspecting and reporting on issues within the GitHub CODEOWNERS file.
高级语言: Ruby
项目地址: git://github.com/cerner/codeowner_validator.git
创建时间: 2021-02-24T17:20:53Z
项目社区:https://github.com/cerner/codeowner_validator

开源协议:Apache License 2.0

下载


CODEOWNER Validator

Cerner OSS
License
Build Status

This library provides interactions with the GitHub CODEOWNERS file for performing validation tasks that include

  • ownership checks
  • valid syntax
  • missing files
  • duplicate patterns

Usage

The library has been designed in a manner that allows invocation by a consumer in one of two options. The first use case is through the command line
interface (CLI). This allows the consumer to execute a command on the terminal and output a report resulting from the validation tasks. The second use
case allows consumers direct consumption of the methods utilized for the validation tasks to allow for writing their own custom implementation on how
to generate a report.

Command Line Use Case

Installation

Add this line to your application’s Gemfile:

  1. gem 'codeowner_validator'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install codeowner_validator

Execution

  1. codeowner_validator validate

Execution of the validator is against a supplied repository folder location. The business logic for retrieving said repository is up to the consumer.
Upon execution of the validator, the repository location will be asked of the executor. You may enter an absolute location or you could supply a parameter
of -p or --repo-path to avoid the question in the console.

  1. codeowner_validator validate -p /Users/foo/special-repository

Consumer Use Case

Installation

Add this line to your application’s Gemfile:

  1. gem 'codeowner_validator'

And then execute:

  1. $ bundle

Execution

  1. require 'codeowner_validator'
  2. code_owners = CodeownerValidator::CodeOwners.new(
  3. repo_path: "/Users/poloka/application-config"
  4. )
  5. # return an array of patterns that have no files associated to them
  6. code_owners.useless_pattern
  7. # returns a list of files from the repository that do not have an owner assigned
  8. code_owners.missing_assignments

Whitelist

With some projects, not all files within the repository need assignments. In this case, a consumer may define a list of relative path
locations within the repository to be scanned for evaluation. There are a few options and any combination of these options may be used

‘CODEOWNERS_WHITELIST’ file

If the initialization of the whitelist object is provided a repository path, the retrieval of the pathspec will include
entries from the provided file. This file may reside in either the root repository location or within the .github folder.

  1. application-config/
  2. ├── CODEOWNERS_WHITELIST
  3. └── .github/
  4. ├── CODEOWNERS
  5. └── CODEOWNERS_WHITELIST

‘.gitignore’ file

If the initialization of the whitelist object is provided a repository path, all entries from the .gitignore will be added as items to
exclude from ownership evaluations.

ENV[‘CODEOWNERS_WHITELIST’]

This option of an environment variable ‘CODEOWNERS_WHITELIST’ with a comma separated string is allowed.

  1. CODEOWNERS_WHITELIST=config/subfolder_01,config/subfolder_02 codeowner_validator validate -p /Users/foo/special-repository

Building

This project is built using Ruby 2.6+, Rake and Bundler. RSpec is used for unit tests and SimpleCov
is utilized for test coverage. RuboCop is used to monitor the lint and style.

Setup

To setup the development workspace, run the following after checkout:

  1. gem install bundler
  2. bundle install

Tests

To run the RSpec tests, run the following:

  1. bin/rspec

Lint

To analyze the project’s style and lint, run the following:

  1. bin/rubocop

Bundler Audit

To analyze the project’s dependency vulnerabilities, run the following:

  1. bin/bundle audit

Availability

This RubyGem will be available on https://rubygems.org/.

Communication

All questions, bugs, enhancements and pull requests can be submitted here, on GitHub via Issues.

Contributing

See CONTRIBUTING.md

License

Copyright 2020 Cerner Innovation, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

  1. http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Code of Conduct

Everyone interacting in the CodeownerValidator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

References

Shout-out to @jonatas and his project codeowners-checker. The checker provided easy reusage which greatly reduced the
dependencies within this project.