Skip to content

Commit cfab3cc

Browse files
ajgontrotzig
authored andcommitted
Moved Commitplease hook from CommitMsg to PostCommit (sds#455)
`CommitMsg` hook works only on commit messages. Unfortunately `commitplease` does not allow to pass a message directly on it, it only works on posted commits. That's why this hooks needs to be moved to `PostCommit` section - `commitplease` needs to actually see the commit.
1 parent 5415335 commit cfab3cc

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* Moved `CommitPlease` from `CommitMsg` to `PostCommit` hook
78
* Add `skip_file_checkout` hook setting for `PostCheckout` hooks
89

910
## 0.37.0

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ a task ID is included for tracking purposes, or ensuring your commit messages
391391
follow [proper formatting guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
392392

393393
* [`*`CapitalizedSubject](lib/overcommit/hook/commit_msg/capitalized_subject.rb)
394-
* [Commitplease](lib/overcommit/hook/commit_msg/commitplease.rb)
395394
* [`*`EmptyMessage](lib/overcommit/hook/commit_msg/empty_message.rb)
396395
* [GerritChangeId](lib/overcommit/hook/commit_msg/gerrit_change_id.rb)
397396
* [HardTabs](lib/overcommit/hook/commit_msg/hard_tabs.rb)
@@ -421,6 +420,7 @@ however, it can be used to alert the user to some issue.
421420

422421
* [BowerInstall](lib/overcommit/hook/post_commit/bower_install.rb)
423422
* [BundleInstall](lib/overcommit/hook/post_commit/bundle_install.rb)
423+
* [Commitplease](lib/overcommit/hook/post_commit/commitplease.rb)
424424
* [GitGuilt](lib/overcommit/hook/post_commit/git_guilt.rb)
425425
* [IndexTags](lib/overcommit/hook/post_commit/index_tags.rb)
426426
* [NpmInstall](lib/overcommit/hook/post_commit/npm_install.rb)

config/default.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ CommitMsg:
114114
enabled: true
115115
description: 'Check for trailing periods in subject'
116116

117-
Commitplease:
118-
enabled: false
119-
description: 'Analyze with Commitplease'
120-
required_executable: './node_modules/.bin/commitplease'
121-
install_command: 'npm install --save-dev commitplease'
122-
123117
# Hooks that are run after `git commit` is executed, before the commit message
124118
# editor is displayed. These hooks are ideal for syntax checkers, linters, and
125119
# other checks that you want to run before you allow a commit object to be
@@ -747,6 +741,13 @@ PostCommit:
747741
- 'Gemfile.lock'
748742
- '*.gemspec'
749743

744+
Commitplease:
745+
enabled: false
746+
description: 'Analyze with Commitplease'
747+
required_executable: './node_modules/.bin/commitplease'
748+
install_command: 'npm install --save-dev commitplease'
749+
flags: ['-1']
750+
750751
GitGuilt:
751752
enabled: false
752753
description: 'Calculate changes in blame since last commit'

lib/overcommit/hook/commit_msg/commitplease.rb lib/overcommit/hook/post_commit/commitplease.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Overcommit::Hook::CommitMsg
1+
module Overcommit::Hook::PostCommit
22
# Check that a commit message conforms to a certain style
33
#
44
# @see https://www.npmjs.com/package/commitplease
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCommit::Commitplease do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when commitplease exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
result.stub(:stderr).and_return('')
18+
end
19+
20+
it { should pass }
21+
end
22+
23+
context 'when commitplease exits unsuccessfully' do
24+
before do
25+
result.stub(success?: false, stderr: normalize_indent(<<-OUT))
26+
- First line must be <type>(<scope>): <subject>
27+
Need an opening parenthesis: (
28+
OUT
29+
end
30+
31+
it { should fail_hook }
32+
end
33+
end

0 commit comments

Comments
 (0)