diff --git a/config/default.yml b/config/default.yml index 9d95fd4e..fadcb1c7 100644 --- a/config/default.yml +++ b/config/default.yml @@ -784,6 +784,15 @@ PostCheckout: - 'Gemfile.lock' - '*.gemspec' + ComposerInstall: + enabled: false + description: 'Install composer dependencies' + requires_files: true + required_executable: 'composer' + install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer' + flags: ['install'] + include: 'composer.json' + IndexTags: enabled: false description: 'Generate tags file from source' @@ -851,6 +860,15 @@ PostCommit: install_command: 'npm install --save-dev commitplease' flags: ['-1'] + ComposerInstall: + enabled: false + description: 'Install composer dependencies' + requires_files: true + required_executable: 'composer' + install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer' + flags: ['install'] + include: 'composer.json' + GitGuilt: enabled: false description: 'Calculate changes in blame since last commit' @@ -918,6 +936,15 @@ PostMerge: - 'Gemfile.lock' - '*.gemspec' + ComposerInstall: + enabled: false + description: 'Install composer dependencies' + requires_files: true + required_executable: 'composer' + install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer' + flags: ['install'] + include: 'composer.json' + IndexTags: enabled: false description: 'Generate tags file from source' @@ -977,6 +1004,15 @@ PostRewrite: - 'Gemfile.lock' - '*.gemspec' + ComposerInstall: + enabled: false + description: 'Install composer dependencies' + requires_files: true + required_executable: 'composer' + install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer' + flags: ['install'] + include: 'composer.json' + IndexTags: enabled: false description: 'Generate tags file from source' diff --git a/lib/overcommit/hook/post_checkout/composer_install.rb b/lib/overcommit/hook/post_checkout/composer_install.rb new file mode 100644 index 00000000..28573343 --- /dev/null +++ b/lib/overcommit/hook/post_checkout/composer_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/composer_install' + +module Overcommit::Hook::PostCheckout + # Runs `composer install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::ComposerInstall} + class ComposerInstall < Base + include Overcommit::Hook::Shared::ComposerInstall + end +end diff --git a/lib/overcommit/hook/post_commit/composer_install.rb b/lib/overcommit/hook/post_commit/composer_install.rb new file mode 100644 index 00000000..218c8140 --- /dev/null +++ b/lib/overcommit/hook/post_commit/composer_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/composer_install' + +module Overcommit::Hook::PostCommit + # Runs `composer install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::ComposerInstall} + class ComposerInstall < Base + include Overcommit::Hook::Shared::ComposerInstall + end +end diff --git a/lib/overcommit/hook/post_merge/composer_install.rb b/lib/overcommit/hook/post_merge/composer_install.rb new file mode 100644 index 00000000..ec17a5a8 --- /dev/null +++ b/lib/overcommit/hook/post_merge/composer_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/composer_install' + +module Overcommit::Hook::PostMerge + # Runs `composer install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::ComposerInstall} + class ComposerInstall < Base + include Overcommit::Hook::Shared::ComposerInstall + end +end diff --git a/lib/overcommit/hook/post_rewrite/composer_install.rb b/lib/overcommit/hook/post_rewrite/composer_install.rb new file mode 100644 index 00000000..354d6e50 --- /dev/null +++ b/lib/overcommit/hook/post_rewrite/composer_install.rb @@ -0,0 +1,11 @@ +require 'overcommit/hook/shared/composer_install' + +module Overcommit::Hook::PostRewrite + # Runs `composer install` when a change is detected in the repository's + # dependencies. + # + # @see {Overcommit::Hook::Shared::ComposerInstall} + class ComposerInstall < Base + include Overcommit::Hook::Shared::ComposerInstall + end +end diff --git a/lib/overcommit/hook/shared/composer_install.rb b/lib/overcommit/hook/shared/composer_install.rb new file mode 100644 index 00000000..828484e6 --- /dev/null +++ b/lib/overcommit/hook/shared/composer_install.rb @@ -0,0 +1,13 @@ +module Overcommit::Hook::Shared + # Shared code used by all ComposerInstall hooks. Runs `composer install` when + # a change is detected in the repository's dependencies. + # + # @see https://getcomposer.org/ + module ComposerInstall + def run + result = execute(command) + return :fail, result.stdout unless result.success? + :pass + end + end +end diff --git a/spec/overcommit/hook/post_checkout/composer_install_spec.rb b/spec/overcommit/hook/post_checkout/composer_install_spec.rb new file mode 100644 index 00000000..bf041e6f --- /dev/null +++ b/spec/overcommit/hook/post_checkout/composer_install_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostCheckout::ComposerInstall 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 composer install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when composer install exits unsuccessfully' do + before do + result.stub(success?: false, stdout: 'Composer could not find a composer.json file') + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_commit/composer_install_spec.rb b/spec/overcommit/hook/post_commit/composer_install_spec.rb new file mode 100644 index 00000000..499ec8ea --- /dev/null +++ b/spec/overcommit/hook/post_commit/composer_install_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostCommit::ComposerInstall 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 composer install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when composer install exits unsuccessfully' do + before do + result.stub(success?: false, stdout: 'Composer could not find a composer.json file') + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_merge/composer_install_spec.rb b/spec/overcommit/hook/post_merge/composer_install_spec.rb new file mode 100644 index 00000000..fb092bc2 --- /dev/null +++ b/spec/overcommit/hook/post_merge/composer_install_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostMerge::ComposerInstall 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 composer install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when composer install exits unsuccessfully' do + before do + result.stub(success?: false, stdout: 'Composer could not find a composer.json file') + end + + it { should fail_hook } + end +end diff --git a/spec/overcommit/hook/post_rewrite/composer_install_spec.rb b/spec/overcommit/hook/post_rewrite/composer_install_spec.rb new file mode 100644 index 00000000..fd44d43c --- /dev/null +++ b/spec/overcommit/hook/post_rewrite/composer_install_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Overcommit::Hook::PostRewrite::ComposerInstall 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 composer install exits successfully' do + before do + result.stub(:success?).and_return(true) + end + + it { should pass } + end + + context 'when composer install exits unsuccessfully' do + before do + result.stub(success?: false, stdout: 'Composer could not find a composer.json file') + end + + it { should fail_hook } + end +end