From 8c3b54352db4a81735236a7d3bf14634f0b16a4a Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Thu, 16 Jul 2015 01:55:58 -0400 Subject: [PATCH] Add BowerInstall post-{commit,checkout,merge,rewrite} hooks --- config/default.yml | 36 +++++++++++++++++++ .../hook/post_checkout/bower_install.rb | 11 ++++++ .../hook/post_commit/bower_install.rb | 11 ++++++ .../hook/post_merge/bower_install.rb | 11 ++++++ .../hook/post_rewrite/bower_install.rb | 11 ++++++ lib/overcommit/hook/shared/bower_install.rb | 13 +++++++ .../hook/post_checkout/bower_install_spec.rb | 31 ++++++++++++++++ .../hook/post_commit/bower_install_spec.rb | 31 ++++++++++++++++ .../hook/post_merge/bower_install_spec.rb | 31 ++++++++++++++++ .../hook/post_rewrite/bower_install_spec.rb | 31 ++++++++++++++++ 10 files changed, 217 insertions(+) create mode 100644 lib/overcommit/hook/post_checkout/bower_install.rb create mode 100644 lib/overcommit/hook/post_commit/bower_install.rb create mode 100644 lib/overcommit/hook/post_merge/bower_install.rb create mode 100644 lib/overcommit/hook/post_rewrite/bower_install.rb create mode 100644 lib/overcommit/hook/shared/bower_install.rb create mode 100644 spec/overcommit/hook/post_checkout/bower_install_spec.rb create mode 100644 spec/overcommit/hook/post_commit/bower_install_spec.rb create mode 100644 spec/overcommit/hook/post_merge/bower_install_spec.rb create mode 100644 spec/overcommit/hook/post_rewrite/bower_install_spec.rb diff --git a/config/default.yml b/config/default.yml index ee5efe06..529e49d7 100644 --- a/config/default.yml +++ b/config/default.yml @@ -532,6 +532,15 @@ PostCheckout: required: false quiet: false + BowerInstall: + enabled: false + description: 'Installing bower dependencies' + requires_files: true + required_executable: 'bower' + install_command: 'npm install -g bower' + flags: ['install'] + include: 'bower.json' + IndexTags: enabled: false description: 'Generating tags file from source' @@ -561,6 +570,15 @@ PostCommit: required: false quiet: false + BowerInstall: + enabled: false + description: 'Installing bower dependencies' + requires_files: true + required_executable: 'bower' + install_command: 'npm install -g bower' + flags: ['install'] + include: 'bower.json' + GitGuilt: enabled: false description: 'Calculating changes in blame since last commit' @@ -597,6 +615,15 @@ PostMerge: requires_files: false quiet: false + BowerInstall: + enabled: false + description: 'Installing bower dependencies' + requires_files: true + required_executable: 'bower' + install_command: 'npm install -g bower' + flags: ['install'] + include: 'bower.json' + IndexTags: enabled: false description: 'Generating tags file from source' @@ -625,6 +652,15 @@ PostRewrite: requires_files: false quiet: false + BowerInstall: + enabled: false + description: 'Installing bower dependencies' + requires_files: true + required_executable: 'bower' + install_command: 'npm install -g bower' + flags: ['install'] + include: 'bower.json' + IndexTags: enabled: false description: 'Generating tags file from source' diff --git a/lib/overcommit/hook/post_checkout/bower_install.rb b/lib/overcommit/hook/post_checkout/bower_install.rb new file mode 100644 index 00000000..cc93e074 --- /dev/null +++ b/lib/overcommit/hook/post_checkout/bower_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/bower_install' + +module Overcommit::Hook::PostCheckout + # Runs `bower install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::BowerInstall} + class BowerInstall < Base + include Overcommit::Hook::Shared::BowerInstall + end +end diff --git a/lib/overcommit/hook/post_commit/bower_install.rb b/lib/overcommit/hook/post_commit/bower_install.rb new file mode 100644 index 00000000..72cc1cbc --- /dev/null +++ b/lib/overcommit/hook/post_commit/bower_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/bower_install' + +module Overcommit::Hook::PostCommit + # Runs `bower install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::BowerInstall} + class BowerInstall < Base + include Overcommit::Hook::Shared::BowerInstall + end +end diff --git a/lib/overcommit/hook/post_merge/bower_install.rb b/lib/overcommit/hook/post_merge/bower_install.rb new file mode 100644 index 00000000..07d9b601 --- /dev/null +++ b/lib/overcommit/hook/post_merge/bower_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/bower_install' + +module Overcommit::Hook::PostMerge + # Runs `bower install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::BowerInstall} + class BowerInstall < Base + include Overcommit::Hook::Shared::BowerInstall + end +end diff --git a/lib/overcommit/hook/post_rewrite/bower_install.rb b/lib/overcommit/hook/post_rewrite/bower_install.rb new file mode 100644 index 00000000..c755aae1 --- /dev/null +++ b/lib/overcommit/hook/post_rewrite/bower_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/bower_install' + +module Overcommit::Hook::PostRewrite + # Runs `bower install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::BowerInstall} + class BowerInstall < Base + include Overcommit::Hook::Shared::BowerInstall + end +end diff --git a/lib/overcommit/hook/shared/bower_install.rb b/lib/overcommit/hook/shared/bower_install.rb new file mode 100644 index 00000000..a0ecab63 --- /dev/null +++ b/lib/overcommit/hook/shared/bower_install.rb @@ -0,0 +1,13 @@ +module Overcommit::Hook::Shared + # Shared code used by all BowerInstall hooks. Runs `bower install` when a + # change is detected in the repository's dependencies. + # + # @see http://bower.io/ + module BowerInstall + def run + result = execute(command) + return :fail, result.stderr unless result.success? + :pass + end + end +end diff --git a/spec/overcommit/hook/post_checkout/bower_install_spec.rb b/spec/overcommit/hook/post_checkout/bower_install_spec.rb new file mode 100644 index 00000000..6720a244 --- /dev/null +++ b/spec/overcommit/hook/post_checkout/bower_install_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostCheckout::BowerInstall do + let(:config) { Overcommit::ConfigurationLoader.default_configuration } + let(:context) { double('context') } + subject { described_class.new(config, context) } + + let(:result) { double('result') } + + before do + subject.stub(:execute).and_return(result) + end + + context 'when bower install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when bower install exits unsuccessfully' do + before do + result.stub(success?: false, stderr: normalize_indent(<<-OUT)) + bower EMALFORMED Failed to read bower.json + OUT + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_commit/bower_install_spec.rb b/spec/overcommit/hook/post_commit/bower_install_spec.rb new file mode 100644 index 00000000..7d5417f8 --- /dev/null +++ b/spec/overcommit/hook/post_commit/bower_install_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostCommit::BowerInstall do + let(:config) { Overcommit::ConfigurationLoader.default_configuration } + let(:context) { double('context') } + subject { described_class.new(config, context) } + + let(:result) { double('result') } + + before do + subject.stub(:execute).and_return(result) + end + + context 'when bower install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when bower install exits unsuccessfully' do + before do + result.stub(success?: false, stderr: normalize_indent(<<-OUT)) + bower EMALFORMED Failed to read bower.json + OUT + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_merge/bower_install_spec.rb b/spec/overcommit/hook/post_merge/bower_install_spec.rb new file mode 100644 index 00000000..63f5cbaf --- /dev/null +++ b/spec/overcommit/hook/post_merge/bower_install_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostMerge::BowerInstall do + let(:config) { Overcommit::ConfigurationLoader.default_configuration } + let(:context) { double('context') } + subject { described_class.new(config, context) } + + let(:result) { double('result') } + + before do + subject.stub(:execute).and_return(result) + end + + context 'when bower install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when bower install exits unsuccessfully' do + before do + result.stub(success?: false, stderr: normalize_indent(<<-OUT)) + bower EMALFORMED Failed to read bower.json + OUT + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_rewrite/bower_install_spec.rb b/spec/overcommit/hook/post_rewrite/bower_install_spec.rb new file mode 100644 index 00000000..a3a1a1b1 --- /dev/null +++ b/spec/overcommit/hook/post_rewrite/bower_install_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostRewrite::BowerInstall do + let(:config) { Overcommit::ConfigurationLoader.default_configuration } + let(:context) { double('context') } + subject { described_class.new(config, context) } + + let(:result) { double('result') } + + before do + subject.stub(:execute).and_return(result) + end + + context 'when bower install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when bower install exits unsuccessfully' do + before do + result.stub(success?: false, stderr: normalize_indent(<<-OUT)) + bower EMALFORMED Failed to read bower.json + OUT + end + + it { should fail_hook } + end +end