Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add ignored_paths option #3

Merged
merged 2 commits into from

1 participant

@gonzoyumo
Owner

No description provided.

@gonzoyumo gonzoyumo merged commit d03ae3d into master
@gonzoyumo gonzoyumo deleted the add_ignored_paths_option branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 30, 2013
  1. @gonzoyumo

    Add ignored_paths option

    gonzoyumo authored
  2. @gonzoyumo
This page is out of date. Refresh to see the latest.
View
10 README.md
@@ -118,13 +118,19 @@ Here is a sample config file:
```yaml
api_key: "some_secret_api_key"
profile_name: "tech-angels"
-project_name: "vandamme"
+project_name: "vandamme"
project_branch: "master"
+ignored_paths:
+ - spec/
+ - tmp/
```
+This will handle the dependencies of the _vandamme_ project for the _tech-angels_ profile on _master_ branch.
+Gemnasium gem will also ignore the project dependency files found in _spec/_ and _tmp/_.
+
## Troubleshooting
-Gemnasium will try to display the most accurate error message when something goes wrong.
+Gemnasium will try to display the most accurate error message when something goes wrong.
Though, if you're stil stuck with something, feel free to contact [Gemnasium support](https://gemnasium.freshdesk.com).
View
28 lib/gemnasium/configuration.rb
@@ -2,10 +2,11 @@
module Gemnasium
class Configuration
- attr_accessor :site, :api_key, :use_ssl, :profile_name, :project_name, :api_version, :project_branch
- DEFAULT_CONFIG = { site: 'gemnasium.com',
- use_ssl: true,
- api_version: 'v2' }
+ attr_accessor :site, :api_key, :use_ssl, :profile_name, :project_name, :api_version, :project_branch, :ignored_paths
+ DEFAULT_CONFIG = { 'site' => 'gemnasium.com',
+ 'use_ssl' => true,
+ 'api_version' => 'v2',
+ 'ignored_paths' => [] }
# Initialize the configuration object from a YAML file
#
@@ -16,7 +17,10 @@ def initialize config_file
config_hash = DEFAULT_CONFIG.merge!(YAML.load_file(config_file))
config_hash.each do |k, v|
writer_method = "#{k}="
- send(writer_method, v) if respond_to?(writer_method)
+ if respond_to?(writer_method)
+ v = convert_ignored_paths_to_regexp(v) if k.to_s == 'ignored_paths'
+ send(writer_method, v)
+ end
end
raise 'Your configuration file does not contain all mandatory parameters or contain invalid values. Please check the documentation.' unless is_valid?
@@ -34,9 +38,21 @@ def is_valid?
api_version_option_valid = !api_version.nil? && !api_version.empty?
profile_name_option_valid = !profile_name.nil? && !profile_name.empty?
project_name_option_valid = !project_name.nil? && !project_name.empty?
+ ignored_paths_option_valid = ignored_paths.kind_of?(Array)
site_option_valid && api_key_option_valid && use_ssl_option_valid && api_version_option_valid &&
- profile_name_option_valid && project_name_option_valid
+ profile_name_option_valid && project_name_option_valid && ignored_paths_option_valid
+ end
+
+ def convert_ignored_paths_to_regexp(paths)
+ return [] unless paths.kind_of? Array
+
+ paths.inject([]) do |regexp_array, path|
+ path = path.insert(0,'^') # All path start from app root
+ .gsub('*','[^/]+') # Replace `*` to whatever char except slash
+ .gsub('.','\.') # Escape dots
+ regexp_array << Regexp.new(path)
+ end
end
end
end
View
15 lib/gemnasium/dependency_files.rb
@@ -12,7 +12,7 @@ class DependencyFiles
def self.get_sha1s_hash(project_path)
Dir.chdir(project_path)
Dir.glob("**/**").grep(SUPPORTED_DEPENDENCY_FILES).inject({}) do |h, file_path|
- h[file_path] = calculate_sha1("#{project_path}/#{file_path}")
+ h[file_path] = calculate_sha1("#{project_path}/#{file_path}") unless is_ignored?(file_path)
h
end
end
@@ -31,7 +31,7 @@ def self.get_content_to_upload(project_path, files_path)
# Calculate hash of a file in the same way git does
#
- # @param file_path [String] path of the file
+ # @param file_path [String] path of the file
# @return [String] SHA1 of the file
def self.calculate_sha1(file_path)
mem_buf = File.open(file_path) {|io| io.read}
@@ -40,5 +40,16 @@ def self.calculate_sha1(file_path)
Digest::SHA1.hexdigest(header + mem_buf)
end
+
+ # Test if the file is ignored by the configuration file
+ #
+ # @param file_path [String] path of the file to test
+ # @return [Boolean] true if the file is ignored
+ def self.is_ignored?(file_path)
+ Gemnasium.config.ignored_paths.each do |ignored_path|
+ return true if file_path =~ ignored_path
+ end
+ false
+ end
end
end
View
13 lib/templates/gemnasium.yml
@@ -1,4 +1,9 @@
-api_key: "api_key_goes_here" # You personal (secret) API key. Get it at https://gemnasium.com/settings/api_access
-profile_name: "profile_name" # One of https://gemnasium.com/settings/github_setup
-project_name: "project_name" # Will be available at https://gemnasium.com/profile_name/project_name
-project_branch: "master" # /!\ If you don't use git, remove this line
+api_key: api_key_goes_here # You personal (secret) API key. Get it at https://gemnasium.com/settings/api_access
+profile_name: profile_name # One of https://gemnasium.com/settings/github_setup
+project_name: project_name # Will be available at https://gemnasium.com/profile_name/project_name
+project_branch: master # /!\ If you don't use git, remove this line
+ignored_paths: # Paths you want to ignore when searching for dependency files (from app root)
+ - features/
+ - spec/
+ - test/
+ - tmp/
View
20 spec/gemnasium/configuration_spec.rb
@@ -3,9 +3,10 @@
describe Gemnasium::Configuration do
describe 'default config' do
- it { expect(Gemnasium::Configuration::DEFAULT_CONFIG[:site]).to eql 'gemnasium.com' }
- it { expect(Gemnasium::Configuration::DEFAULT_CONFIG[:use_ssl]).to eql true }
- it { expect(Gemnasium::Configuration::DEFAULT_CONFIG[:api_version]).to eql 'v2' }
+ it { expect(Gemnasium::Configuration::DEFAULT_CONFIG['site']).to eql 'gemnasium.com' }
+ it { expect(Gemnasium::Configuration::DEFAULT_CONFIG['use_ssl']).to eql true }
+ it { expect(Gemnasium::Configuration::DEFAULT_CONFIG['api_version']).to eql 'v2' }
+ it { expect(Gemnasium::Configuration::DEFAULT_CONFIG['ignored_paths']).to eql [] }
end
describe 'initialize' do
@@ -29,7 +30,7 @@
end
context 'with all mandatory values' do
- let(:config_options) {{ api_key: 'api_key', profile_name: 'tech-angels', project_name: 'gemnasium-gem', project_branch: 'master' }}
+ let(:config_options) {{ api_key: 'api_key', profile_name: 'tech-angels', project_name: 'gemnasium-gem', project_branch: 'master', ignored_paths: ['spec/','tmp/*.lock', '*.gemspec'] }}
before do
File.open(config_file_path, 'w+') { |f| f.write(config_options.to_yaml) }
end
@@ -39,10 +40,13 @@
it { expect(config.profile_name).to eql config_options[:profile_name] }
it { expect(config.project_name).to eql config_options[:project_name] }
it { expect(config.project_branch).to eql config_options[:project_branch] }
- it { expect(config.site).to eql Gemnasium::Configuration::DEFAULT_CONFIG[:site] }
- it { expect(config.use_ssl).to eql Gemnasium::Configuration::DEFAULT_CONFIG[:use_ssl] }
- it { expect(config.api_version).to eql Gemnasium::Configuration::DEFAULT_CONFIG[:api_version] }
+ it { expect(config.site).to eql Gemnasium::Configuration::DEFAULT_CONFIG['site'] }
+ it { expect(config.use_ssl).to eql Gemnasium::Configuration::DEFAULT_CONFIG['use_ssl'] }
+ it { expect(config.api_version).to eql Gemnasium::Configuration::DEFAULT_CONFIG['api_version'] }
+ it { expect(config.ignored_paths).to include Regexp.new("^spec/") }
+ it { expect(config.ignored_paths).to include Regexp.new("^tmp/[^/]+\\.lock") }
+ it { expect(config.ignored_paths).to include Regexp.new("^[^\/]+\\.gemspec") }
end
end
end
-end
+end
View
17 spec/gemnasium/dependency_files_spec.rb
@@ -14,12 +14,29 @@
end
context 'with a mathing regexp' do
+ before { Gemnasium.stub_chain(:config, :ignored_paths).and_return([]) }
it 'returns a Hash of matching files and their git calculated hash' do
sha1s_hash = Gemnasium::DependencyFiles.get_sha1s_hash(project_path)
expect(sha1s_hash).to include({ 'gemnasium.gemspec' => git_hash('gemnasium.gemspec') })
end
end
+
+ context 'with some ignored paths' do
+ let(:ignored_file_path) { 'tmp/ignored.gemspec' }
+ before do
+ FileUtils.touch(ignored_file_path)
+ Gemnasium.stub_chain(:config, :ignored_paths).and_return([/^tmp/, /[^\/]+\.lock/])
+ end
+ after { File.delete(ignored_file_path) }
+
+ it 'returns a Hash of matching files without ignored ones' do
+ sha1s_hash = Gemnasium::DependencyFiles.get_sha1s_hash(project_path)
+
+ expect(sha1s_hash).to_not have_key(ignored_file_path)
+ expect(sha1s_hash).to_not have_key('Gemfile.lock')
+ end
+ end
end
describe 'get_content_to_upload' do
Something went wrong with that request. Please try again.