check-ahead 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 31dc9c420a4e762f5127520aea444dfd5e97ccf614cd61379ebe85a789448ca2
4
+ data.tar.gz: f3a028ea3a805d7f3a98231d19f823dbb16d72d340ccffaeaa6f1e098814e01c
5
+ SHA512:
6
+ metadata.gz: d26310b43c061cf8c4162a539630119d475abee61036a525819c54d2d7d1ac8b9d11b506ec48131b29ce9426c5cbdd862ea1422a6d8b0c7c3c80edfea27289c0
7
+ data.tar.gz: f6bc0e25bb49f157b0bad38d9f47fce7db662c73d9e05bf1abda51f2ac38c2afbe9dd087df5ff7233d1ee150d62cff025556bcd7144e2b91d63acc52a7ba84dc
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: RSpec Ruby
3
+
4
+ on: [push]
5
+
6
+ jobs:
7
+ rspec:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: [2.4, 2.5, 2.6, 2.7]
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - name: Set up Ruby
16
+ uses: eregon/use-ruby-action@master
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+
20
+ - name: install bundler and gems
21
+ run: |
22
+ gem install bundler
23
+ bundle install --jobs 3 --retry 3
24
+
25
+ - name: run RSpec
26
+ run: |
27
+ bundle exec rspec
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: Lint Ruby
3
+
4
+ on: [push]
5
+
6
+ jobs:
7
+ rubocop:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v1
11
+ - name: Set up Ruby 2.6
12
+ uses: actions/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.6.x
15
+
16
+ - name: install bundler and gems
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 3 --retry 3
20
+
21
+ - name: Rubocop check
22
+ run: |
23
+ bundle exec rubocop -D
@@ -0,0 +1,11 @@
1
+ # bundler
2
+ .bundle
3
+ Gemfile.local
4
+
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
@@ -0,0 +1,19 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+ - rubocop-performance
5
+
6
+ Metrics/MethodLength:
7
+ Enabled: false
8
+ Style/Documentation:
9
+ Enabled: false
10
+ Metrics/AbcSize:
11
+ Enabled: false
12
+ Metrics/ClassLength:
13
+ Enabled: false
14
+ Style/RescueModifier:
15
+ Enabled: false
16
+ Layout/LineLength:
17
+ Max: 120
18
+ Naming/FileName:
19
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gheorghe.popescu@puppet.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in check-ahead.gemspec
6
+ gemspec
7
+
8
+ group :developmen, :test do
9
+ gem 'pry-byebug'
10
+ gem 'rubocop', require: false
11
+ gem 'rubocop-performance', require: false
12
+ gem 'rubocop-rspec', require: false
13
+ end
14
+
15
+ local_gemfile = File.expand_path('Gemfile.local', __dir__)
16
+ eval_gemfile local_gemfile if File.exist?(local_gemfile)
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ check-ahead (0.1.0)
5
+ dry-cli (~> 0.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ byebug (11.0.1)
12
+ coderay (1.1.2)
13
+ concurrent-ruby (1.1.5)
14
+ diff-lcs (1.3)
15
+ dry-cli (0.5.0)
16
+ concurrent-ruby (~> 1.0)
17
+ jaro_winkler (1.5.4)
18
+ method_source (0.9.2)
19
+ parallel (1.19.1)
20
+ parser (2.7.0.2)
21
+ ast (~> 2.4.0)
22
+ pry (0.12.2)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.9.0)
25
+ pry-byebug (3.7.0)
26
+ byebug (~> 11.0)
27
+ pry (~> 0.10)
28
+ rainbow (3.0.0)
29
+ rake (10.5.0)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.1)
35
+ rspec-support (~> 3.9.1)
36
+ rspec-expectations (3.9.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.2)
43
+ rubocop (0.79.0)
44
+ jaro_winkler (~> 1.5.1)
45
+ parallel (~> 1.10)
46
+ parser (>= 2.7.0.1)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 1.7)
50
+ rubocop-performance (1.5.2)
51
+ rubocop (>= 0.71.0)
52
+ rubocop-rspec (1.37.1)
53
+ rubocop (>= 0.68.1)
54
+ ruby-progressbar (1.10.1)
55
+ unicode-display_width (1.6.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+ x86_64-darwin-18
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 2.0)
63
+ check-ahead!
64
+ pry-byebug
65
+ rake (~> 10.0)
66
+ rspec (~> 3.7)
67
+ rubocop
68
+ rubocop-performance
69
+ rubocop-rspec
70
+
71
+ BUNDLED WITH
72
+ 2.1.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 gimmy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,125 @@
1
+ # check-ahead ![badge](https://action-badges.now.sh/gimmyxd/check-ahead)
2
+
3
+ Helps you create consistent and transparent rules for checking commit messages.
4
+
5
+ ## Rake Tasks
6
+
7
+ `check-ahead:commits` - checks the commits against defined rules
8
+
9
+ `check-ahead:generate_rules` - generate rules from input
10
+
11
+ **check-ahead** uses your **CONTRIBUTING.md** file
12
+
13
+ ```
14
+ ### Commit Message
15
+ Accepted commits messages:
16
+ <commits>
17
+
18
+ * PA-\<digits>
19
+ * maint
20
+ * docs
21
+ </commits>
22
+ ```
23
+
24
+ The accepted content is defined between `<commits></commits>` tag and `<digits>` will be translated to the correspunding regex: `d+`.
25
+
26
+ Check [example CONTRIBUTING.md](spec/fixtures/CONTRIBUTING.md)
27
+
28
+ This will be used by `check-ahead:commits` which allows only commit messages that match `(PA-\d+|maint|docs)`
29
+
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'check-ahead'
37
+ ```
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install check-ahead
46
+
47
+ ## Usage
48
+ ### CLI
49
+ ```ruby
50
+ CLI - based on dry-cli
51
+ - check-ahead --help # available commands
52
+ - check-ahead command --help # help for specicif commands
53
+
54
+ Implemented commands:
55
+ - check-ahead check_commits
56
+ - check-ahead generate_rules TAGS
57
+ ```
58
+ ### Tasks
59
+ ```ruby
60
+ # usually in your Rakefile
61
+
62
+ require 'check-ahead'
63
+ CheckAhead.load_tasks # loads rake task on demand
64
+
65
+ # alternative loading
66
+ require 'check-ahead'
67
+ include CheckAhead # loads rake task on project initialization
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ The gem supports configuration for: commit\_range, CONTRIBUTING.md path, base_tags
73
+
74
+ Example:
75
+
76
+ ```ruby
77
+ # inside your ruby project
78
+
79
+ CheckAhead.configure do |config|
80
+ config.commit_range = 'master..HEAD'
81
+ config.contributing_md = "/docs/CONTRIBUTING.md"
82
+ config.base_tags = [revert]
83
+ config.max_length = 100
84
+ config.checking_max_length = true
85
+ end
86
+ ```
87
+
88
+ or **ENVIRONMENT** variables:
89
+
90
+ ```ruby
91
+ ENV['BASE_TAGS']
92
+ ENV['CONTRIBUTING_MD']
93
+ ENV['COMMIT_RANGE']
94
+ ENV['MAX_LENGTH']
95
+ ENV['CHECK_MAX_LENGTH']
96
+ ```
97
+
98
+ Defaults:
99
+
100
+ ```ruby
101
+ base_tags = %w[revert merge]
102
+ contributing_md = File.join('project_root/CONTRIBUTING.md')
103
+ commit_range = 'master..HEAD'
104
+ max_length = 50
105
+ check_max_length = false
106
+ ```
107
+
108
+ ## Development
109
+
110
+ 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.
111
+
112
+ To install this gem onto your local machine, run `bundle exec rake install`.
113
+
114
+
115
+ ## Contributing
116
+
117
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gimmyxd/check-ahead. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
122
+
123
+ ## Code of Conduct
124
+
125
+ Everyone interacting in the CheckAhead project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gimmyxd/check-ahead/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'check-ahead'
4
+
5
+ require 'bundler/gem_tasks'
6
+ task default: :spec
7
+
8
+ CheckAhead.load_tasks
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'check-ahead'
7
+ require 'check-ahead/cli'
8
+
9
+ CheckAhead::CLI::Application.start
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'check-ahead'
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'check-ahead/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'check-ahead'
9
+ spec.version = CheckAhead::VERSION
10
+ spec.authors = ['gimmy']
11
+ spec.email = ['gheorghe.popescu@puppet.com']
12
+
13
+ spec.summary = 'Guard against unwanted commits'
14
+ spec.description = 'CheckAhead let you define rules to guard against unwanted commits'
15
+ spec.homepage = 'https://github.com/gimmyxd/check-ahead'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/gimmyxd/check-ahead'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/gimmyxd/check-ahead/blob/master/CHANGELONG.md'
21
+
22
+ spec.bindir = 'bin'
23
+ spec.executables << 'check-ahead'
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.required_ruby_version = '~> 2.3'
34
+
35
+ spec.add_runtime_dependency 'dry-cli', ' ~> 0.4'
36
+
37
+ spec.add_development_dependency 'bundler', '~> 2.0'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.7'
40
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'validators/commit_summary_validator'
4
+ require 'validators/commit_length_validator'
5
+
6
+ module Actions
7
+ class CheckCommits
8
+ def initialize
9
+ @config = CheckAhead.configuration
10
+ end
11
+
12
+ def execute
13
+ check_commits
14
+ end
15
+
16
+ private
17
+
18
+ def check_commits
19
+ git_log.each_line do |commit_summary|
20
+ commit = Commit.new(commit_summary)
21
+ CommitSummaryValidator.call(commit) if @config.check_commit_message?
22
+ CommitLengthValidator.call(commit) if @config.check_max_length?
23
+ error_message = commit.errors.values.join
24
+
25
+ if error_message.empty?
26
+ STDOUT.puts "PASSED: #{commit_summary}"
27
+ else
28
+ error_message = error_message_header(commit_summary) + error_message
29
+ warn error_message
30
+ exit(false)
31
+ end
32
+ end
33
+ end
34
+
35
+ def git_log
36
+ `git log --no-merges --pretty=%s #{@config.commit_range}`
37
+ end
38
+
39
+ def error_message_header(commit_summary)
40
+ "\n\tCommit summary: #{commit_summary}\n".bold
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Actions
4
+ class GenerateRules
5
+ def initialize(input)
6
+ @input = input
7
+ end
8
+
9
+ def execute
10
+ generate_output.green
11
+ end
12
+
13
+ private
14
+
15
+ def generate_output
16
+ "#{header}" \
17
+ "<commits>\n\n" \
18
+ "#{split_input}\n" \
19
+ "</commits>\n"
20
+ end
21
+
22
+ def split_input
23
+ @input.gsub('<digits>', '\\<digits>')
24
+ .split(',').map { |node| "* #{node}" }.join("\n")
25
+ end
26
+
27
+ def header
28
+ "### Commit Message\n" \
29
+ "Accepted commits messages:\n"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry-byebug'
4
+
5
+ require 'core_extensions/string'
6
+ require 'check-ahead/version'
7
+ require 'check-ahead/configuration'
8
+ require 'data/commit'
9
+ require 'data/contributing_md'
10
+
11
+ module CheckAhead
12
+ class << self
13
+ def load_tasks
14
+ Dir["#{File.dirname(__dir__)}/lib/tasks/**/*.rake"].each { |file| load file }
15
+ end
16
+
17
+ def included(_base)
18
+ load_tasks
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/cli'
4
+ require 'cli/commands'
5
+
6
+ module CheckAhead
7
+ module CLI
8
+ class Application < Dry::CLI
9
+ def self.start
10
+ new.call
11
+ end
12
+
13
+ def self.new(commands = CLI::Commands)
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckAhead
4
+ class Configuration
5
+ DEFAULT_ATTRS = {
6
+ base_tags: %w[revert merge],
7
+ contributing_md: File.join(Dir.pwd, 'CONTRIBUTING.md'),
8
+ commit_range: 'HEAD~1..HEAD',
9
+ max_length: 50,
10
+ check_max_length: false,
11
+ check_commit_message: true
12
+ }.freeze
13
+
14
+ ATTRS = DEFAULT_ATTRS.keys
15
+
16
+ attr_accessor(*ATTRS)
17
+
18
+ def initialize
19
+ DEFAULT_ATTRS.each do |attribute, value|
20
+ send("#{attribute}=", ENV[attribute.to_s.upcase] || value)
21
+ end
22
+ end
23
+
24
+ ATTRS.select { |attribute| attribute.to_s.start_with?('check') }.each do |attribute|
25
+ define_method("#{attribute}?") do
26
+ ['true', true].include?(send(attribute))
27
+ end
28
+ end
29
+ end
30
+
31
+ class << self
32
+ attr_writer :configuration
33
+
34
+ def configuration
35
+ @configuration ||= Configuration.new
36
+ end
37
+
38
+ def configure
39
+ yield configuration
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckAhead
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'dry/cli'
5
+ require 'actions/check_commits'
6
+ require 'actions/generate_rules'
7
+
8
+ module CheckAhead
9
+ module CLI
10
+ module Commands
11
+ extend Dry::CLI::Registry
12
+
13
+ class CheckCommits < Dry::CLI::Command
14
+ desc 'verify that commit messages match CONTRIBUTING.md requirements'
15
+
16
+ def call(*)
17
+ Actions::CheckCommits.new.execute
18
+ end
19
+ end
20
+
21
+ class GenerateRules < Dry::CLI::Command
22
+ desc 'generate the commits requirements to be added in CONTRIBUTING.md'
23
+ argument :tags,
24
+ required: true,
25
+ desc: 'tags separated by ",", used to generate rules, Example: PA-<digits>,maint,bump'
26
+
27
+ def call(tags:, **)
28
+ STDOUT.puts("\n\nGenerated output - please add it to CONTRIBUTING.md \n\n")
29
+ STDOUT.puts Actions::GenerateRules.new(tags).execute
30
+ end
31
+ end
32
+
33
+ register 'check_commits', CheckCommits
34
+ register 'generate_rules', GenerateRules
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def black
5
+ "\e[30m#{self}\e[0m"
6
+ end
7
+
8
+ def red
9
+ "\e[31m#{self}\e[0m"
10
+ end
11
+
12
+ def green
13
+ "\e[32m#{self}\e[0m"
14
+ end
15
+
16
+ def cyan
17
+ "\e[36m#{self}\e[0m"
18
+ end
19
+
20
+ def bold
21
+ "\e[1m#{self}\e[22m"
22
+ end
23
+
24
+ def italic
25
+ "\e[3m#{self}\e[23m"
26
+ end
27
+
28
+ def blink
29
+ "\e[5m#{self}\e[25m"
30
+ end
31
+
32
+ def no_colors
33
+ gsub(/\e\[\d+m/, '')
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Commit
4
+ attr_accessor :summary, :errors
5
+
6
+ def initialize(summary, errors = {})
7
+ @summary = summary
8
+ @errors = errors
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ContributingMd
4
+ class << self
5
+ def accepted_tags
6
+ @accepted_tags ||= accepted_commits_section
7
+ .delete("\n*")
8
+ .gsub("\<digits>", 'd+')
9
+ .split
10
+ .join('|')
11
+ end
12
+
13
+ def accepted_commits_section
14
+ accepted_commits_section = contributing_file.match(%r{<commits>(.*)</commits>}m)
15
+ if accepted_commits_section
16
+ accepted_commits_section[1].chomp.strip
17
+ else
18
+ raise 'information not found in CONTRIBUTING.md, ' \
19
+ 'please run check-ahead:generate_rules'
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def contributing_file
26
+ @contributing_file ||= begin
27
+ path = CheckAhead.configuration.contributing_md
28
+ raise IOError, "CONTRIBUTING.md not found in #{path}" unless File.exist?(path)
29
+
30
+ @contributing_file = File.read(path)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'actions/check_commits'
4
+ require 'actions/generate_rules'
5
+
6
+ namespace :'check-ahead' do
7
+ desc 'verify that commit messages match CONTRIBUTING.md requirements'
8
+ task :commits do
9
+ Actions::CheckCommits.new.execute
10
+ end
11
+
12
+ desc 'generate the commits requirements to be added in CONTRIBUTING.md'
13
+ task :generate_rules do
14
+ STDOUT.puts("Enter the tags separated by \",\" \nExample: PA-<digits>,maint,bump")
15
+
16
+ input = STDIN.gets.strip
17
+
18
+ abort('Bad input'.bold.red) if input.empty?
19
+
20
+ STDOUT.puts("\n\nGenerated output - please add it to CONTRIBUTING.md \n\n")
21
+ STDOUT.puts Actions::GenerateRules.new(input).execute
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CommitLengthValidator
4
+ class << self
5
+ def call(record)
6
+ return if record.summary.length < CheckAhead.configuration.max_length
7
+
8
+ record.errors[:length] = error_message(record.summary.length)
9
+ end
10
+
11
+ private
12
+
13
+ def error_message(length)
14
+ "\n\tThis commit summary is too long: #{length}/#{CheckAhead.configuration.max_length}\n\n"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CommitSummaryValidator
4
+ class << self
5
+ def call(record)
6
+ return if record.summary =~ rules
7
+
8
+ record.errors[:summary] = error_message
9
+ end
10
+
11
+ private
12
+
13
+ def rules
14
+ /^\((#{ContributingMd.accepted_tags})\)|#{CheckAhead.configuration.base_tags.join('|')}/i
15
+ end
16
+
17
+ def error_message
18
+ "\tThe commit summary (i.e. the first line of the commit message) must start with one of:\n\n" \
19
+ "#{ContributingMd.accepted_commits_section.delete('\\').split('*').join("\t\t")}\n" \
20
+ "\t\t #{CheckAhead.configuration.base_tags.join("\n\t\t ")}\n" \
21
+ "\n\tThis test for the commit summary is case-insensitive.\n"
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check-ahead
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gimmy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ description: CheckAhead let you define rules to guard against unwanted commits
70
+ email:
71
+ - gheorghe.popescu@puppet.com
72
+ executables:
73
+ - check-ahead
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/rspec.yml"
78
+ - ".github/workflows/rubocop.yml"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".rubocop.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/check-ahead
89
+ - bin/console
90
+ - bin/setup
91
+ - check-ahead.gemspec
92
+ - lib/actions/check_commits.rb
93
+ - lib/actions/generate_rules.rb
94
+ - lib/check-ahead.rb
95
+ - lib/check-ahead/cli.rb
96
+ - lib/check-ahead/configuration.rb
97
+ - lib/check-ahead/version.rb
98
+ - lib/cli/commands.rb
99
+ - lib/core_extensions/string.rb
100
+ - lib/data/commit.rb
101
+ - lib/data/contributing_md.rb
102
+ - lib/tasks/check-ahead.rake
103
+ - lib/validators/commit_length_validator.rb
104
+ - lib/validators/commit_summary_validator.rb
105
+ homepage: https://github.com/gimmyxd/check-ahead
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://github.com/gimmyxd/check-ahead
110
+ source_code_uri: https://github.com/gimmyxd/check-ahead
111
+ changelog_uri: https://github.com/gimmyxd/check-ahead/blob/master/CHANGELONG.md
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '2.3'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Guard against unwanted commits
131
+ test_files: []