Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hook for LicenseFinder #491

Merged
merged 1 commit into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add [`Pronto`](https://github.com/mmozuras/pronto) pre-commit hook
* Add [`hadolint`](https://github.com/lukasmartinelli/hadolint) pre-commit hook
* Add [`license_finder`](https://github.com/pivotal/LicenseFinder) pre-commit hook
* Use the `core.hooksPath` Git configuration option when installing hooks

## 0.39.1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
* [GoLint](lib/overcommit/hook/pre_commit/go_lint.rb)
* [GoVet](lib/overcommit/hook/pre_commit/go_vet.rb)
* [Hadolint](lib/overcommit/hook/pre_commit/hadolint.rb)
* [LicenseFinder](lib/overcommit/hook/pre_commit/license_finder.rb)
* [HamlLint](lib/overcommit/hook/pre_commit/haml_lint.rb)
* [HardTabs](lib/overcommit/hook/pre_commit/hard_tabs.rb)
* [Hlint](lib/overcommit/hook/pre_commit/hlint.rb)
Expand Down
15 changes: 15 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ PreCommit:
install_command: 'gem install json'
include: '**/*.json'

LicenseFinder:
enabled: false
description: 'Analyze with LicenseFinder'
required_executable: 'license_finder'
install_command: 'gem install license_finder'
include:
- 'Gemfile'
- 'requirements.txt'
- 'package.json'
- 'pom.xml'
- 'build.gradle'
- 'bower.json'
- 'Podfile'
- 'rebar.config'

LicenseHeader:
enabled: false
license_file: 'LICENSE.txt'
Expand Down
12 changes: 12 additions & 0 deletions lib/overcommit/hook/pre_commit/license_finder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Overcommit::Hook::PreCommit
# Runs LicenseFinder if any of your package manager declaration files have changed
# See more about LicenseFinder at https://github.com/pivotal/LicenseFinde
class LicenseFinder < Base
def run
result = execute(command)
return :pass if result.success?
output = result.stdout + result.stderr
[:fail, output]
end
end
end
29 changes: 29 additions & 0 deletions spec/overcommit/hook/pre_commit/license_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Overcommit::Hook::PreCommit::LicenseFinder do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

context 'when license_finder exits successfully' do
before do
result = double('result')
result.stub(:success?).and_return(true)
subject.stub(:execute).and_return(result)
end

it { should pass }
end

context 'when license_finder runs unsucessfully' do
before do
result = double('result')
result.stub(:success?).and_return(false)
result.stub(:stdout).and_return('Some error message')
result.stub(:stderr).and_return('')
subject.stub(:execute).and_return(result)
end

it { should fail_hook 'Some error message' }
end
end