diff --git a/.gitignore b/.gitignore index 707a05e..9c23ca8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store -pkg .idea/ -Gemfile.lock -.ruby-version .ruby-gemset +.ruby-version .yardoc/ +Gemfile.lock +pkg diff --git a/.travis.yml b/.travis.yml index 182cbf1..4361926 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,10 @@ language: ruby cache: bundler rvm: - - 2.2 - - 2.3.3 - - 2.4.0 - - jruby-9 + - 2.4.5 + - 2.5.5 + - 2.6.2 + - jruby-9.2.6.0 script: - bundle exec rake diff --git a/CHANGELOG.md b/CHANGELOG.md index e09f241..4da051f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,22 @@ The format is based on [Keep a Changelog][keep] and this project adheres to ## [Unreleased] -[Unreleased]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.6...master +[Unreleased]: https://github.com/SimeonC/danger-angular_commit_lint/compare/v1.2.0...master + +## [1.2.0] - 2019-05-05 + +### Changed + +* Ignore git generated subject in commit messages [#21][] +* Express danger plugin dependency in terms of plugin api [#24][] + +[1.2.0]: https://github.com/SimeonC/danger-angular_commit_lint/compare/v0.0.6...v1.2.0 +[#21]: https://github.com/jonallured/danger-commit_lint/pull/21 +[#24]: https://github.com/jonallured/danger-commit_lint/pull/24 + +### Removed + +* Drop Ruby 2.3 from Travis [1aa9cff][1aa9cff] ## [0.0.6] - 2017-04-27 diff --git a/README.md b/README.md index e22fecb..176d317 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ That will check each commit in the PR to ensure the following is true: * Commit subject follows the angular pattern of `(): ` * Commit begins with a capital letter (`subject_cap`) -* Commit is more than one word (`subject_word`) +* Commit is more than one word (`subject_words`) * Commit is no longer than 50 characters (`subject_length`) * Commit does not end in a period (`subject_period`) * Commit and body are separated by an empty line (`empty_line`) diff --git a/Rakefile b/Rakefile index 07dba4a..39e5e30 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) -task default: [:spec, :rubocop, :spec_docs] +task default: %i[rubocop spec spec_docs] desc 'Run RuboCop on the lib/specs directory' RuboCop::RakeTask.new(:rubocop) do |task| diff --git a/danger-angular_commit_lint.gemspec b/danger-angular_commit_lint.gemspec index 000caaa..e3d4c84 100644 --- a/danger-angular_commit_lint.gemspec +++ b/danger-angular_commit_lint.gemspec @@ -1,5 +1,4 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'angular_commit_lint/gem_version.rb' @@ -13,17 +12,17 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/simeonc/danger-angular_commit_lint' spec.license = 'MIT' - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'danger', '~> 5.0' + spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0' - spec.add_development_dependency 'bundler', '~> 1.3' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'rspec', '~> 3.4' - spec.add_development_dependency "rubocop", "~> 0.41" - spec.add_development_dependency "yard", "~> 0.8" + spec.add_development_dependency 'bundler' spec.add_development_dependency 'pry' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'yard' end diff --git a/lib/angular_commit_lint/gem_version.rb b/lib/angular_commit_lint/gem_version.rb index cac17a6..0cbc1db 100644 --- a/lib/angular_commit_lint/gem_version.rb +++ b/lib/angular_commit_lint/gem_version.rb @@ -1,3 +1,3 @@ module AngularCommitLint - VERSION = '1.1.2'.freeze + VERSION = '1.2.0'.freeze end diff --git a/lib/angular_commit_lint/plugin.rb b/lib/angular_commit_lint/plugin.rb index 1f5bd22..93fa19a 100644 --- a/lib/angular_commit_lint/plugin.rb +++ b/lib/angular_commit_lint/plugin.rb @@ -127,6 +127,7 @@ def disabled_checks def warning_checks return checks if @config[:warn] == :all + @config[:warn] || [] end diff --git a/lib/angular_commit_lint/subject_length_check.rb b/lib/angular_commit_lint/subject_length_check.rb index 2477d83..fe617b4 100644 --- a/lib/angular_commit_lint/subject_length_check.rb +++ b/lib/angular_commit_lint/subject_length_check.rb @@ -6,6 +6,10 @@ class SubjectLengthCheck < CommitCheck # :nodoc: def message 'Please limit commit subject line to 50 characters.'.freeze end + GIT_GENERATED_SUBJECT = /^Merge branch \'.+\' into\ /.freeze + GITHUB_GENERATED_SUBJECT = /^Merge pull request #\d+ from\ /.freeze + + attr_reader :subject def self.type :subject_length @@ -16,7 +20,11 @@ def initialize(message, _config = {}) end def fail? - @subject.length > 50 + subject.length > 50 && !merge_commit? + end + + def merge_commit? + subject =~ /#{GIT_GENERATED_SUBJECT}|#{GITHUB_GENERATED_SUBJECT}/ end end end diff --git a/spec/commit_lint_spec.rb b/spec/commit_lint_spec.rb index 0ed3b62..7f90976 100644 --- a/spec/commit_lint_spec.rb +++ b/spec/commit_lint_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../spec_helper', __FILE__) +require File.expand_path('spec_helper', __dir__) # rubocop:disable Metrics/LineLength @@ -10,7 +10,7 @@ subject_period: 'fix: This subject line ends in a period.', empty_line: "fix: This subject line is fine\nBut then I forgot the empty line separating the subject and the body.", all_errors: "this is a really long subject and it even ends in a period.\nNot to mention the missing empty line!", - valid: "fix: This is a valid message\n\nYou can tell because it meets all the criteria and the linter does not complain." + valid: "fix: This is a valid message\n\nYou can tell because it meets all the criteria and the linter does not complain." }.freeze BLANK_MESSAGE = { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a97360..e7b75ca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'pathname' -ROOT = Pathname.new(File.expand_path('../../', __FILE__)) +ROOT = Pathname.new(File.expand_path('..', __dir__)) $LOAD_PATH.unshift((ROOT + 'lib').to_s) $LOAD_PATH.unshift((ROOT + 'spec').to_s) diff --git a/spec/subject_length_check_spec.rb b/spec/subject_length_check_spec.rb new file mode 100644 index 0000000..5b3273f --- /dev/null +++ b/spec/subject_length_check_spec.rb @@ -0,0 +1,43 @@ +require File.expand_path('spec_helper', __dir__) + +describe Danger::DangerAngularCommitLint::SubjectLengthCheck do + describe '#fail?' do + let(:commit_subject) { 'This is a common valid commit message' } + + let(:message) do + { + subject: commit_subject + } + end + + subject do + described_class.new(message).fail? + end + + it { expect(subject).to be_falsy } + + context 'when message is invalid' do + let(:commit_subject) do + 'This is a really long subject line and should result in an error' + end + + it { expect(subject).to be_truthy } + end + + context 'when message is a merge commit generated by git' do + let(:commit_subject) do + "Merge branch 'ignore-length-on-git-merge-commits' into master" + end + + it { expect(subject).to be_falsy } + end + + context 'when message is a merge commit generated by GitHub' do + let(:commit_subject) do + 'Merge pull request #1234 from jonallured/ignore-length-merge-commits' + end + + it { expect(subject).to be_falsy } + end + end +end