sourceninja 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/COPYRIGHT ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2012 SourceNinja
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2012 SourceNinja
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,20 +1,18 @@
1
- Note
2
- ----
3
- * This gem is currently alpha. __You need to be invited to [SourceNinja Alpha](http://www.sourceninja.com/sign-up.html) in order to use this gem__.
4
-
5
- What is SourceNinja
1
+ What is SourceNinja?
6
2
  -------------------
7
3
  SourceNinja is an awesome service that allows you to stay informed of updates to the open source packages that your application uses. When a newer version of a package is released, SourceNinja alerts you and gives you actionable information to help you determine whether you should upgrade to the newer package.
8
4
 
9
5
  Visit [SourceNinja](http://sourceninja.com) to learn more.
10
6
 
11
- What is the sourceninja gem
7
+ What is the sourceninja gem?
12
8
  ---------------------------
13
- The sourceninja gem is a gem that can be included in your rails application to allow seamless integration with SourceNinja. The sourceninja gem will send all of your gem files and versions to SourceNinja to begin managing your open source libraries.
9
+ The sourceninja gem is a gem that can be included in your Rails application to allow seamless integration with SourceNinja. The sourceninja gem will send SourceNinja the list of the gem names and gem versions that you are using to begin managing your open source libraries.
10
+
11
+ In a non-Rails environment, a script is included for processing a Gemfile.lock and uploading it to SourceNinja.
14
12
 
15
13
  Getting Started
16
14
  ---------------
17
- 1. Create a [SourceNinja](http://sourceninja.com) account. Currently, you need to be part of our [alpha](http://www.sourceninja.com/sign-up.html).
15
+ 1. Create a [SourceNinja](https://app.sourceninja.com/plans) account.
18
16
 
19
17
  2. Log into SourceNinja and create a product. The product you create will be paired with your application.
20
18
 
@@ -33,26 +31,44 @@ Getting Started
33
31
 
34
32
  6. Run `bundle install`.
35
33
 
36
- 7. Set the environment variables ```SOURCENINJA_TOKEN``` and ```SOURCENINJA_PRODUCT_ID``` using the values from step 4.
37
-
38
- Updated Magically in Production
39
- -----------------
40
- Now each time you push to production the sourceninja gem will be run and data will be populated back to SourceNinja. If you visit your SourceNinja page you will be given a list of outdated gems.
34
+ Rails environment - Testing
35
+ ----------------------------
36
+ 1. In order to automate the process of uploading module information from your Rails environment, you can create
37
+ an initializer script to configure how your Rails application will send information to SourceNinja.
41
38
 
42
- The sourceninja data is populated whenever the app is initialized.
39
+ ### Contents of `config/initializers/sourceninja.rb`
40
+ ENV["SOURCENINJA_TOKEN"] ||= "50a336d92da8ddea1ae0a6c0d06a172"
41
+ ENV["SOURCENINJA_PRODUCT_ID"] ||= "477fcfa7-765a-4b91-b6a5-2ebe4c4f9d58"
43
42
 
44
- Testing Locally
45
- ---------------
46
- If you would like to test sourceninja gem locally, you will want to create an initializer script to set the variables.
43
+ The values that you set in this initializer script should be the ones presented to you in step 4, above.
47
44
 
48
- ### Contents of `config/initializers/sourceninja.rb`
49
- ENV["SOURCENINJA_TOKEN"] ||= "1cea0be98caf02e830ac2aadbe44e4ee"
50
- ENV["SOURCENINJA_PRODUCT_ID"] ||= "fb89e064-b48c-d0c3-81x4-a34a5b60a654"
45
+ Now each time your Rails application is started, the sourceninja gem will be run and data will be populated back to SourceNinja. If you visit your SourceNinja page you will be given a list of outdated gems.
51
46
 
52
- Upon doing this, each time you start the rails server locally the data will be pushed. You could also use these steps if you want to manage a production instance and a development instance.
47
+ You could also use these steps if you want to manage a production instance and a development instance.
53
48
 
54
49
  __Note: DO NOT DO THIS FOR PRODUCTION: No configuration files with sensitive information should ever be required within the application source and required config values should be read in from the ENV by supported libraries.__
55
50
 
51
+ Rails environment - Production
52
+ -------------------------------
53
+ 1. Configure environment variables for ```SOURCENINJA_TOKEN``` and ```SOURCENINJA_PRODUCT_ID``` using the values from step 4, above.
54
+
55
+ Non-Rails environment
56
+ ----------------------
57
+ 1. Included in the gem is a script, ```sourceninja```, that you may run to have it upload information to SourceNinja directly from your Gemfile.lock.
58
+ 2. You will need the ```SOURCENINJA_TOKEN``` and ```SOURCENINJA_PRODUCT_ID``` values from step 4, above.
59
+ 3. Run the script with ```-h``` to see this output:
60
+ ```
61
+ Usage: sourceninja -t <sourceninja_account_token> -p <sourceninja_product_id> [-f Gemfile.lock]
62
+ -f, --filename FILE Gemfile.lock file to process
63
+ -h, --help Display this screen
64
+ -p, --product_id PRODUCT_ID SourceNinja Product ID
65
+ -t, --token TOKEN SourceNinja API Key Token
66
+ -v, --verbose Output more information
67
+ ```
68
+ 4. Run the script using ```-p```, ```-f```, and ```-t``` to pass along the correct configuration information to SourceNinja.
69
+
70
+ 5. Now you can login to your SourceNinja account and review your project's information.
71
+
56
72
  Support
57
73
  -------
58
74
  Feel free to email us at support at sourceninja dot com if you have any questions or issues.
data/bin/sourceninja ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sourceninja'
4
+ require 'bundler'
5
+ require 'optparse'
6
+
7
+ DEFAULT_FILE_TO_PROCESS = './Gemfile.lock'
8
+
9
+ # This hash will hold all of the options
10
+ # parsed from the command-line by
11
+ # OptionParser.
12
+ options = { 'file_to_process' => DEFAULT_FILE_TO_PROCESS }
13
+
14
+ optparse = OptionParser.new do|opts|
15
+ # Set a banner, displayed at the top
16
+ # of the help screen.
17
+ opts.banner = "Usage: sourceninja -t <sourceninja_account_token> -p <sourceninja_product_id> [-f Gemfile.lock]"
18
+
19
+ # Define the options, and what they do
20
+ opts.on( '-f', '--filename FILE', 'Gemfile.lock file to process') do |filename|
21
+ options['file_to_process'] = filename
22
+ end
23
+
24
+ # This displays the help screen
25
+ opts.on( '-h', '--help', 'Display this screen' ) do
26
+ puts opts
27
+ exit
28
+ end
29
+
30
+ opts.on( '-p', '--product_id PRODUCT_ID', 'SourceNinja Product ID' ) do |product_id|
31
+ ENV["SOURCENINJA_PRODUCT_ID"] = product_id
32
+ end
33
+
34
+ opts.on( '-t', '--token TOKEN', 'SourceNinja API Key Token' ) do |token|
35
+ ENV["SOURCENINJA_TOKEN"] = token
36
+ end
37
+
38
+ options[:verbose] = false
39
+ opts.on( '-v', '--verbose', 'Output more information' ) do
40
+ options[:verbose] = true
41
+ end
42
+ end
43
+
44
+ # Actually parse the command line
45
+ optparse.parse!
46
+
47
+ unless ENV["SOURCENINJA_PRODUCT_ID"] and ENV["SOURCENINJA_TOKEN"]
48
+ $stderr.puts "You must supply a token and product ID! Exiting."
49
+ puts optparse.help
50
+ exit
51
+ end
52
+
53
+ unless File::exists? options['file_to_process']
54
+ $stderr.puts "Filename #{options['file_to_process']} not found! Exiting."
55
+ puts optparse.help
56
+ exit
57
+ end
58
+
59
+ lockfile = Bundler::LockfileParser.new(Bundler.read_file(options['file_to_process']))
60
+
61
+ # all we need in the dep list is the name of the module. the version number here won't be important because
62
+ # Bundler will resolve that into the spec list below
63
+ dep_list = {}
64
+ lockfile.dependencies.to_a.map{|b| b.to_s}.each do |dep|
65
+ puts "Sourceninja: processing dependency #{dep}" if options[:verbose]
66
+ unless dep =~ %r{^\s*(\S+)}
67
+ $stderr.puts "Sourceninja: Could not find the package name for #{dep.to_s}"
68
+ next
69
+ end
70
+
71
+ dep_list[$1] = true
72
+ end
73
+
74
+ package_data = []
75
+ lockfile.specs.each do |spec|
76
+ # Data looks like 'sourceninja (0.0.8)'
77
+ unless spec.to_s =~ %r{^(\S+)\s*\((\S+)\)$}
78
+ $stderr.puts "Sourceninja: Could not parse information for gem '#{spec}' (class #{spec.class.to_s})"
79
+ next
80
+ end
81
+
82
+ puts "Sourceninja: found gem #{$1} with a version of #{$2}" if options[:verbose]
83
+
84
+ package_data << { :package_name => $1, :package_version => $2, :direct_requirement => (dep_list[$1] || false) }
85
+ end
86
+
87
+ if package_data.empty?
88
+ $stderr.puts "Sourceninja: Did not successfully parse any packages, will not attempt to upload information"
89
+ elsif options[:verbose]
90
+ puts "Package data: #{package_data.to_s}"
91
+ end
92
+
93
+ puts "Sending package information to SourceNinja..." if options[:verbose]
94
+ Sourceninja.send_package_info package_data
95
+ puts "Done." if options[:verbose]
data/lib/sourceninja.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require "sourceninja/version"
2
2
 
3
- # only allow this to be run under rails for the time being.
4
- require "sourceninja/sourceninja.rb" if defined? Rails
3
+ require "sourceninja/sourceninja"
4
+ require "sourceninja/railtie" if defined? Rails
@@ -0,0 +1,8 @@
1
+ module SourceNinja
2
+ class RailTie < Rails::Railtie
3
+ ActiveSupport.on_load(:after_initialize) do
4
+ package_data = Sourceninja.process_bundle_info
5
+ Sourceninja.send_package_info(package_data)
6
+ end
7
+ end
8
+ end
@@ -2,68 +2,92 @@ require 'httparty'
2
2
  require 'json'
3
3
 
4
4
  module Sourceninja
5
- class Sourceninja
6
- include HTTParty
5
+ include HTTParty
7
6
 
8
- @@base_uri = "https://app.sourceninja.com"
7
+ @@base_uri = "https://app.sourceninja.com"
9
8
 
10
- def self.send_package_info
9
+ def self.process_bundle_info
10
+ # all we need in the dep list is the name of the module. the version number here won't be important because
11
+ # Bundler will resolve that into the spec list below
12
+ dep_list = {}
13
+ Bundler.environment.dependencies.to_a.map{|b| b.to_s}.each do |dep|
14
+ unless dep =~ %r{^\s*(\S+)}
15
+ if defined? Rails
16
+ Rails.logger.info "Sourceninja: Could not find the package name for #{dep.to_s}"
17
+ end
18
+
19
+ next
20
+ end
21
+
22
+ dep_list[$1] = true
23
+ end
24
+
25
+ package_data = []
26
+ spec_hash = Bundler.environment.specs.to_hash
27
+ spec_hash.keys.each do |key|
28
+ unless %r{Gem::Specification name=#{key} version=([\d.]+)} =~ spec_hash[key][0].to_s
29
+ if defined? Rails
30
+ Rails.logger.info "Sourceninja: Could not parse information for gem #{key}: #{spec_hash[key]}"
31
+ else
32
+ $stderr.puts "Sourceninja: Could not parse information for gem #{key}: #{spec_hash[key]}"
33
+ end
34
+ next
35
+ end
36
+ package_data << { :package_name => key, :package_version => $1, :direct_requirement => (dep_list[key] || false) }
37
+ end
38
+
39
+ if package_data.empty?
40
+ if defined? Rails
41
+ Rails.logger.info "Sourceninja: Did not successfully parse any packages, will not attempt to upload information"
42
+ end
43
+
44
+ return
45
+ end
46
+
47
+ package_data
48
+ end
49
+
50
+ def self.send_package_info(package_data_hash)
51
+ if defined? Rails
11
52
  Rails.logger.debug "Sourceninja: Attempting to send package information to SourceNinja"
53
+ end
12
54
 
13
- base_uri = @@base_uri
55
+ base_uri = @@base_uri
14
56
 
15
- if not ENV['SOURCENINJA_UPLOAD_URL'].nil? and ENV['SOURCENINJA_UPLOAD_URL'] != ""
57
+ if not ENV['SOURCENINJA_UPLOAD_URL'].nil? and ENV['SOURCENINJA_UPLOAD_URL'] != ""
58
+ if defined? Rails
16
59
  Rails.logger.debug "Sourceninja: using #{ENV['SOURCENINJA_UPLOAD_URL']} for the upload URI"
17
- base_uri = ENV['SOURCENINJA_UPLOAD_URL']
18
60
  end
19
61
 
20
- if ENV['SOURCENINJA_TOKEN'].nil? or ENV['SOURCENINJA_TOKEN'] == ""
62
+ base_uri = ENV['SOURCENINJA_UPLOAD_URL']
63
+ end
64
+
65
+ if ENV['SOURCENINJA_TOKEN'].nil? or ENV['SOURCENINJA_TOKEN'] == ""
66
+ if defined? Rails
21
67
  Rails.logger.debug "Sourceninja: No SOURCENINJA_TOKEN set, not uploading information to SourceNinja"
22
- return
23
68
  end
24
69
 
25
- if ENV['SOURCENINJA_PRODUCT_ID'].nil? or ENV['SOURCENINJA_PRODUCT_ID'] == ""
70
+ return
71
+ end
72
+
73
+ if ENV['SOURCENINJA_PRODUCT_ID'].nil? or ENV['SOURCENINJA_PRODUCT_ID'] == ""
74
+ if defined? Rails
26
75
  Rails.logger.debug "Sourceninja: No SOURCENINJA_PRODUCT_ID set, not uploading information to SourceNinja"
27
- return
28
76
  end
29
77
 
30
- # all we need in the dep list is the name of the module. the version number here won't be important because
31
- # Bundler will resolve that into the spec list below
32
- dep_list = {}
33
- Bundler.environment.dependencies.to_a.map{|b| b.to_s}.each do |dep|
34
- unless %r{^\s*(\S+)} =~ dep
35
- Rails.logger.info "Sourceninja: Could not find the package name for #{dep.to_s}"
36
- next
37
- end
78
+ return
79
+ end
38
80
 
39
- dep_list[$1] = true
40
- end
81
+ params = { :id => ENV['SOURCENINJA_PRODUCT_ID'], :token => ENV['SOURCENINJA_TOKEN'], :package_info => { :package_details => package_data_hash }.to_json }
41
82
 
42
- package_data = []
43
- spec_hash = Bundler.environment.specs.to_hash
44
- spec_hash.keys.each do |key|
45
- unless %r{Gem::Specification name=#{key} version=([\d.]+)} =~ spec_hash[key][0].to_s
46
- Rails.logger.info "Sourceninja: Could not parse information for gem #{key}: #{spec_hash[key]}"
47
- next
48
- end
49
- package_data << { :package_name => key, :package_version => $1, :direct_requirement => (dep_list[key] || false) }
50
- end
83
+ if defined? Rails
84
+ Rails.logger.debug "Sourceninja: Attempting to send package_info of #{params.to_s} to #{[base_uri,'rubygems/1_0'].join('/')}"
85
+ end
51
86
 
52
- if package_data.empty?
53
- Rails.logger.info "Sourceninja: Did not successfully parse any packages, will not attempt to upload information"
54
- return
55
- end
87
+ response = HTTParty.post([base_uri,'rubygems/1_0'].join('/'), :body => params )
56
88
 
57
- params = { :id => ENV['SOURCENINJA_PRODUCT_ID'], :token => ENV['SOURCENINJA_TOKEN'], :package_info => { :package_details => package_data}.to_json }
58
- Rails.logger.debug "Sourceninja: Attempting to send package_info of #{params.to_s} to #{[base_uri,'rubygems/1_0'].join('/')}"
59
- response = HTTParty.post([base_uri,'rubygems/1_0'].join('/'), :body => params )
89
+ if defined? Rails
60
90
  Rails.logger.debug "Sourceninja: Got back status #{response.code}"
61
- end
62
- end
63
-
64
- class RailTie < Rails::Railtie
65
- ActiveSupport.on_load(:after_initialize) do
66
- Sourceninja.send_package_info
67
91
  end
68
92
  end
69
93
  end
@@ -1,3 +1,3 @@
1
1
  module Sourceninja
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/sourceninja.gemspec CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_runtime_dependency "json"
20
- s.add_runtime_dependency "httparty"
19
+ s.add_dependency "json"
20
+ s.add_dependency "httparty"
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sourceninja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-19 00:00:00.000000000 Z
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -48,15 +48,20 @@ description: Integration with SourceNinja software tracking. Will allow a user t
48
48
  SourceNinja system.
49
49
  email:
50
50
  - support@sourceninja.com
51
- executables: []
51
+ executables:
52
+ - sourceninja
52
53
  extensions: []
53
54
  extra_rdoc_files: []
54
55
  files:
55
56
  - .gitignore
57
+ - COPYRIGHT
56
58
  - Gemfile
59
+ - LICENSE
57
60
  - README.md
58
61
  - Rakefile
62
+ - bin/sourceninja
59
63
  - lib/sourceninja.rb
64
+ - lib/sourceninja/railtie.rb
60
65
  - lib/sourceninja/sourceninja.rb
61
66
  - lib/sourceninja/version.rb
62
67
  - sourceninja.gemspec