Skip to content

Commit

Permalink
Add silence-branch option
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Jun 16, 2014
1 parent 1742d22 commit 78efbdc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
8 changes: 5 additions & 3 deletions lib/gemnasium.rb
Expand Up @@ -15,11 +15,13 @@ def push options
ensure_config_is_up_to_date!

unless current_branch == @config.project_branch
message = "Dependency files updated but not on tracked branch (#{@config.project_branch}), ignoring...\n"
if options[:ignore_branch]
notify message, :blue
notify "Not on tracked branch (#{@config.project_branch}), but ignore-branch option set to true. Continuing.\n", :blue
elsif options[:silence_branch]
notify "Not on tracked branch (#{@config.project_branch}). Exiting silently.\n", :blue
return
else
quit_because_of(message)
quit_because_of("Not on tracked branch (#{@config.project_branch})")
end
end

Expand Down
4 changes: 4 additions & 0 deletions lib/gemnasium/options.rb
Expand Up @@ -64,6 +64,10 @@ def self.parse args
options[:ignore_branch] = true
end

opts.on '-s', '--silence-branch', 'Silently ignore untracked branches' do
options[:silence_branch] = true
end

opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
Expand Down
9 changes: 8 additions & 1 deletion spec/gemnasium/options_spec.rb
Expand Up @@ -97,13 +97,20 @@
expect(options).to eql({ command: 'push' })
end
end

context 'with ignore branch options' do
it 'correctly set the options' do
options, parser = Gemnasium::Options.parse ['push', '--ignore-branch']
expect(options).to eql({ command: 'push', ignore_branch: true })
end
end

context 'with silence branch failure options' do
it 'correctly set the options' do
options, parser = Gemnasium::Options.parse ['push', '--silence-branch']
expect(options).to eql({ command: 'push', silence_branch: true })
end
end
end

context '`migrate`' do
Expand Down
36 changes: 27 additions & 9 deletions spec/gemnasium_spec.rb
Expand Up @@ -45,13 +45,6 @@
context 'on a non tracked branch' do
before { allow(Gemnasium).to receive(:current_branch).and_return('non_project_branch') }

it 'quit the program' do
expect{ Gemnasium.push({ project_path: project_path }) }.to raise_error { |e|
expect(e).to be_kind_of SystemExit
expect(error_output).to include "Dependency files updated but not on tracked branch (master), ignoring...\n"
}
end

context 'with supported dependency files for gemnasium project not up-to-date' do
let(:sha1_hash) {{ 'new_gemspec.gemspec' => 'gemspec_sha1_hash', 'modified_lockfile.lock' => 'lockfile_sha1_hash', 'Gemfile_unchanged.lock' => 'gemfile_sha1_hash' }}
let(:hash_to_upload) {[{ filename: 'new_gemspec.gemspec', sha: 'gemspec_sha1_hash', content: 'stubbed gemspec content' },
Expand All @@ -62,8 +55,33 @@
allow(Gemnasium::DependencyFiles).to receive(:get_content_to_upload).and_return(hash_to_upload)
end

it 'should not quit the program when :ignore_branch is true' do
expect{ Gemnasium.push({ project_path: project_path, ignore_branch: true }) }.to_not raise_error
it 'quit the program with an error' do
expect{ Gemnasium.push({ project_path: project_path }) }.to raise_error { |e|
expect(e).to be_kind_of SystemExit
expect(error_output).to include 'Not on tracked branch (master)'
}
end

context "when :silence_branch is true" do
it "should not raise an error" do
expect{ Gemnasium.push({ project_path: project_path, silence_branch: true }) }.to_not raise_error
end

it 'should not contact Gemnasium' do
Gemnasium.push({ project_path: project_path, silence_branch: true })
expect(WebMock).to_not have_requested(:post, api_url('/api/v3/projects/existing-slug/dependency_files/compare'))
end
end

context "when :ignore_branch is true" do
it "should not raise an error" do
expect{ Gemnasium.push({ project_path: project_path, ignore_branch: true }) }.to_not raise_error
end

it 'should still contact Gemnasium' do
Gemnasium.push({ project_path: project_path, ignore_branch: true })
expect(WebMock).to have_requested(:post, api_url('/api/v3/projects/existing-slug/dependency_files/compare'))
end
end
end
end
Expand Down

0 comments on commit 78efbdc

Please sign in to comment.