sourceninja 0.0.8 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,15 @@ require 'json'
4
4
  module Sourceninja
5
5
  include HTTParty
6
6
 
7
- @@base_uri = "https://app.sourceninja.com"
7
+ @@BASE_URI = "https://app.sourceninja.com/rubygems/1_0"
8
+
9
+ def self.log(msg)
10
+ if defined? Rails
11
+ Rails.logger.info msg
12
+ else
13
+ $stderr.puts msg
14
+ end
15
+ end
8
16
 
9
17
  def self.process_bundle_info
10
18
  # all we need in the dep list is the name of the module. the version number here won't be important because
@@ -12,13 +20,9 @@ module Sourceninja
12
20
  dep_list = {}
13
21
  Bundler.environment.dependencies.to_a.map{|b| b.to_s}.each do |dep|
14
22
  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
-
23
+ log("Sourceninja: Could not find the package name for #{dep.to_s}")
19
24
  next
20
25
  end
21
-
22
26
  dep_list[$1] = true
23
27
  end
24
28
 
@@ -26,68 +30,51 @@ module Sourceninja
26
30
  spec_hash = Bundler.environment.specs.to_hash
27
31
  spec_hash.keys.each do |key|
28
32
  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
33
+ log("Sourceninja: Could not parse information for gem #{key}: #{spec_hash[key]}")
34
34
  next
35
35
  end
36
36
  package_data << { :package_name => key, :package_version => $1, :direct_requirement => (dep_list[key] || false) }
37
37
  end
38
38
 
39
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
-
40
+ log("Sourceninja: Did not successfully parse any packages, will not attempt to upload information")
44
41
  return
45
42
  end
46
43
 
47
44
  package_data
48
45
  end
49
46
 
50
- def self.send_package_info(package_data_hash)
51
- if defined? Rails
52
- Rails.logger.debug "Sourceninja: Attempting to send package information to SourceNinja"
53
- end
54
-
55
- base_uri = @@base_uri
56
-
57
- if not ENV['SOURCENINJA_UPLOAD_URL'].nil? and ENV['SOURCENINJA_UPLOAD_URL'] != ""
58
- if defined? Rails
59
- Rails.logger.debug "Sourceninja: using #{ENV['SOURCENINJA_UPLOAD_URL']} for the upload URI"
60
- end
61
-
62
- base_uri = ENV['SOURCENINJA_UPLOAD_URL']
47
+ def self.send_package_info(package_data_hash, options={})
48
+ defaults = {
49
+ :url => ENV['SOURCENINJA_UPLOAD_URL'] ? ENV['SOURCENINJA_UPLOAD_URL'] : @@BASE_URI,
50
+ :token => ENV['SOURCENINJA_TOKEN'],
51
+ :product_id => ENV['SOURCENINJA_PRODUCT_ID']
52
+ }
53
+ options = defaults.merge(options)
54
+
55
+ if options[:token].nil? or options[:token] == ""
56
+ log("Sourceninja: No token set, not uploading information to SourceNinja")
57
+ return false
63
58
  end
64
59
 
65
- if ENV['SOURCENINJA_TOKEN'].nil? or ENV['SOURCENINJA_TOKEN'] == ""
66
- if defined? Rails
67
- Rails.logger.debug "Sourceninja: No SOURCENINJA_TOKEN set, not uploading information to SourceNinja"
68
- end
69
-
70
- return
60
+ if options[:product_id].nil? or options[:product_id] == ""
61
+ log("Sourceninja: No product ID set, not uploading information to SourceNinja")
62
+ return false
71
63
  end
72
64
 
73
- if ENV['SOURCENINJA_PRODUCT_ID'].nil? or ENV['SOURCENINJA_PRODUCT_ID'] == ""
74
- if defined? Rails
75
- Rails.logger.debug "Sourceninja: No SOURCENINJA_PRODUCT_ID set, not uploading information to SourceNinja"
76
- end
65
+ params = { :id => options[:product_id], :token => options[:token], :package_info => { :package_details => package_data_hash }.to_json }
66
+ # log("Sourceninja: Attempting to send package_info of #{params.to_s} to #{[options[:url],'rubygems/1_0'].join('/')}")
77
67
 
78
- return
68
+ response = nil
69
+ begin
70
+ log("Sourceninja: Sending package information to SourceNinja")
71
+ response = HTTParty.post(options[:url], :body => params)
72
+ rescue Exception => e
73
+ log("Sourceninja: Error submitting data: #{e.message}")
74
+ return false
79
75
  end
80
76
 
81
- params = { :id => ENV['SOURCENINJA_PRODUCT_ID'], :token => ENV['SOURCENINJA_TOKEN'], :package_info => { :package_details => package_data_hash }.to_json }
82
-
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
86
-
87
- response = HTTParty.post([base_uri,'rubygems/1_0'].join('/'), :body => params )
88
-
89
- if defined? Rails
90
- Rails.logger.debug "Sourceninja: Got back status #{response.code}"
91
- end
77
+ log("Sourceninja: Received status #{response.code}")
78
+ return response.code == 200
92
79
  end
93
80
  end
@@ -1,3 +1,3 @@
1
1
  module Sourceninja
2
- VERSION = "0.0.8"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["SourceNinja"]
9
9
  s.email = ["support@sourceninja.com"]
10
10
  s.homepage = "http://www.sourceninja.com"
11
- s.summary = %q{Integration with SourceNinja software tracking.}
12
- s.description = %q{Integration with SourceNinja software tracking. Will allow a user to scan their installed gemlist and automatically populate their product within the SourceNinja system.}
11
+ s.summary = "Integration with SourceNinja software tracking."
12
+ s.description = "Integration with SourceNinja software tracking. Will allow a user to scan their installed gemlist and automatically populate their product within the SourceNinja system."
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_dependency "json"
20
20
  s.add_dependency "httparty"
21
+ s.add_development_dependency "rspec"
21
22
  end
@@ -0,0 +1,67 @@
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+
4
+
5
+ describe Sourceninja do
6
+
7
+ describe "process_bundle_info" do
8
+
9
+ it "should return an array of hashes" do
10
+ Sourceninja.process_bundle_info.class.should == Array
11
+ Sourceninja.process_bundle_info.all?(&Hash.method(:===)).should == true
12
+ Sourceninja.process_bundle_info.each { |e|
13
+ e.include?(:package_name).should == true
14
+ e.include?(:package_version).should == true
15
+ e.include?(:direct_requirement).should == true
16
+ }
17
+ end
18
+
19
+ it "check for direct and our named indirect deps" do
20
+ direct_gems = ["rspec", "sourceninja"]
21
+ indirect_gems = ["httparty", "json"]
22
+
23
+ direct_gems.each do |d|
24
+ bundle_info = Sourceninja.process_bundle_info
25
+ rcov_result = bundle_info.select { |e| e[:package_name] == d }
26
+ rcov_result.count.should == 1
27
+ rcov_result.first[:package_name].should == d
28
+ rcov_result.first[:direct_requirement].should == true
29
+ end
30
+
31
+ indirect_gems.each do |d|
32
+ bundle_info = Sourceninja.process_bundle_info
33
+ rcov_result = bundle_info.select { |e| e[:package_name] == d }
34
+ rcov_result.count.should == 1
35
+ rcov_result.first[:package_name].should == d
36
+ rcov_result.first[:direct_requirement].should == false
37
+ end
38
+ end
39
+ end
40
+
41
+ it "make sure the list of hashes is being submitted to SN" do
42
+ data = [{:package_name => "bundler", :package_version => "1.1.3", :direct_requirement => false},
43
+ {:package_name => "sourceninja", :package_version => "0.0.8", :direct_requirement => true}]
44
+
45
+ response = mock(HTTParty::Response)
46
+ response.stub!(:code).and_return(200)
47
+ HTTParty.stub(:post).with("https://app.sourceninja.com/rubygems/1_0",
48
+ {:body => { :id => "product_id",
49
+ :token => "token",
50
+ :package_info => { :package_details => data }.to_json }}).and_return(response)
51
+
52
+ Sourceninja.send_package_info(data,
53
+ :token => "token",
54
+ :product_id => "product_id").should == true
55
+ end
56
+
57
+ it "make sure invalid URLs don't crash the app" do
58
+ data = [{:package_name => "bundler", :package_version => "1.1.3", :direct_requirement => false},
59
+ {:package_name => "sourceninja", :package_version => "0.0.8", :direct_requirement => true}]
60
+
61
+ Sourceninja.send_package_info(data,
62
+ :url => "blargl",
63
+ :token => "token",
64
+ :product_id => "product_id").should == false
65
+ end
66
+
67
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ require 'sourceninja'
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.8
4
+ version: 0.9.0
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-04-25 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: Integration with SourceNinja software tracking. Will allow a user to
47
63
  scan their installed gemlist and automatically populate their product within the
48
64
  SourceNinja system.
@@ -65,6 +81,8 @@ files:
65
81
  - lib/sourceninja/sourceninja.rb
66
82
  - lib/sourceninja/version.rb
67
83
  - sourceninja.gemspec
84
+ - spec/lib/sourceninja/sourceninja_spec.rb
85
+ - spec/spec_helper.rb
68
86
  homepage: http://www.sourceninja.com
69
87
  licenses: []
70
88
  post_install_message:
@@ -85,8 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
103
  version: '0'
86
104
  requirements: []
87
105
  rubyforge_project:
88
- rubygems_version: 1.8.18
106
+ rubygems_version: 1.8.24
89
107
  signing_key:
90
108
  specification_version: 3
91
109
  summary: Integration with SourceNinja software tracking.
92
- test_files: []
110
+ test_files:
111
+ - spec/lib/sourceninja/sourceninja_spec.rb
112
+ - spec/spec_helper.rb