Skip to content

Commit bf6a8df

Browse files
Riaz Viranitrotzig
Riaz Virani
authored andcommitted
Add pre-commit hook for LicenseFinder (sds#491)
1 parent af5226f commit bf6a8df

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

CHANGELOG.md

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

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

910
## 0.39.1

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
491491
* [GoLint](lib/overcommit/hook/pre_commit/go_lint.rb)
492492
* [GoVet](lib/overcommit/hook/pre_commit/go_vet.rb)
493493
* [Hadolint](lib/overcommit/hook/pre_commit/hadolint.rb)
494+
* [LicenseFinder](lib/overcommit/hook/pre_commit/license_finder.rb)
494495
* [HamlLint](lib/overcommit/hook/pre_commit/haml_lint.rb)
495496
* [HardTabs](lib/overcommit/hook/pre_commit/hard_tabs.rb)
496497
* [Hlint](lib/overcommit/hook/pre_commit/hlint.rb)

config/default.yml

+15
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ PreCommit:
383383
install_command: 'gem install json'
384384
include: '**/*.json'
385385

386+
LicenseFinder:
387+
enabled: false
388+
description: 'Analyze with LicenseFinder'
389+
required_executable: 'license_finder'
390+
install_command: 'gem install license_finder'
391+
include:
392+
- 'Gemfile'
393+
- 'requirements.txt'
394+
- 'package.json'
395+
- 'pom.xml'
396+
- 'build.gradle'
397+
- 'bower.json'
398+
- 'Podfile'
399+
- 'rebar.config'
400+
386401
LicenseHeader:
387402
enabled: false
388403
license_file: 'LICENSE.txt'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Overcommit::Hook::PreCommit
2+
# Runs LicenseFinder if any of your package manager declaration files have changed
3+
# See more about LicenseFinder at https://github.com/pivotal/LicenseFinde
4+
class LicenseFinder < Base
5+
def run
6+
result = execute(command)
7+
return :pass if result.success?
8+
output = result.stdout + result.stderr
9+
[:fail, output]
10+
end
11+
end
12+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PreCommit::LicenseFinder do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
context 'when license_finder exits successfully' do
9+
before do
10+
result = double('result')
11+
result.stub(:success?).and_return(true)
12+
subject.stub(:execute).and_return(result)
13+
end
14+
15+
it { should pass }
16+
end
17+
18+
context 'when license_finder runs unsucessfully' do
19+
before do
20+
result = double('result')
21+
result.stub(:success?).and_return(false)
22+
result.stub(:stdout).and_return('Some error message')
23+
result.stub(:stderr).and_return('')
24+
subject.stub(:execute).and_return(result)
25+
end
26+
27+
it { should fail_hook 'Some error message' }
28+
end
29+
end

0 commit comments

Comments
 (0)