gems-license-finder 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a01609bf3346c47dc552b9232be5d69c1e90846d
4
+ data.tar.gz: 8f8383ad8bca15ed9b8e6110488767c679b5da89
5
+ SHA512:
6
+ metadata.gz: 8e23caae8e928bdd1260a94b874a7f1e1f4b943cb30ae1e07d835581e2fb33ad0ca3ea39f3f39c64422ea160fa4bd75ae0c701f1e76833d01a9f5da93aa06973
7
+ data.tar.gz: 9643d7c373a601bb5779f046f89d7d320854fa7c639e362b6b0f4668a1bff027b0f4827be96855fe22b0f95b8e166a428b226e47b06e47e28e008205315212bf
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gems-license-finder (0.0.1)
5
+ bluecloth
6
+ faraday (< 0.9)
7
+ github-markup
8
+ github_api
9
+ kramdown
10
+ maruku
11
+ posix-spawn
12
+ rdiscount
13
+ redcarpet
14
+
15
+ GEM
16
+ remote: http://rubygems.org/
17
+ specs:
18
+ addressable (2.3.5)
19
+ bluecloth (2.2.0)
20
+ descendants_tracker (0.0.3)
21
+ faraday (0.8.9)
22
+ multipart-post (~> 1.2.0)
23
+ github-markup (1.1.0)
24
+ github_api (0.11.3)
25
+ addressable (~> 2.3)
26
+ descendants_tracker (~> 0.0.1)
27
+ faraday (~> 0.8, < 0.10)
28
+ hashie (>= 1.2)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ nokogiri (~> 1.6.0)
31
+ oauth2
32
+ hashie (2.0.5)
33
+ jwt (0.1.11)
34
+ multi_json (>= 1.5)
35
+ kramdown (1.3.3)
36
+ maruku (0.7.1)
37
+ metaclass (0.0.4)
38
+ mini_portile (0.5.2)
39
+ minitest (5.3.1)
40
+ mocha (1.0.0)
41
+ metaclass (~> 0.0.1)
42
+ multi_json (1.9.2)
43
+ multi_xml (0.5.5)
44
+ multipart-post (1.2.0)
45
+ nokogiri (1.6.1)
46
+ mini_portile (~> 0.5.0)
47
+ oauth2 (0.9.3)
48
+ faraday (>= 0.8, < 0.10)
49
+ jwt (~> 0.1.8)
50
+ multi_json (~> 1.3)
51
+ multi_xml (~> 0.5)
52
+ rack (~> 1.2)
53
+ posix-spawn (0.3.8)
54
+ rack (1.5.2)
55
+ rdiscount (2.1.7)
56
+ redcarpet (3.1.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ gems-license-finder!
63
+ minitest
64
+ mocha
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Kontera Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # Gems License Finder
2
+
3
+ Poor man's implementation of a license finder for rubygems.
4
+ <br/>It uses `rubygems.org` && `Github` under the hood and **works 90% of the time** :)
5
+
6
+ ## WARNING
7
+ Please be aware that it may give you the WRONG license for some of the gems,
8
+ so use it at your own risk
9
+
10
+ ## Installtion
11
+ `gem install gems-license-finder`
12
+
13
+ or add this to your `Gemfile` and bundle
14
+
15
+ `gem 'gems-license-finder'`
16
+
17
+ ## Usage
18
+ via command line
19
+ ```
20
+ $ gems-license-finder --help
21
+ Usage: gems-license-finder gem-name [options]
22
+
23
+ -o, --output FORMAT output format [json, yaml]
24
+ -t, --token TOKEN github token string ( or by GITHUB_TOEKN environment variable )
25
+
26
+ More information about how to generate the github token please look at:
27
+ https://help.github.com/articles/git-over-https-using-oauth-token
28
+ ```
29
+
30
+ finding the license of `bundler` gem
31
+ ```
32
+ $ gems-license-finder bundler --output json
33
+ {
34
+ "license_type": "MIT",
35
+ "license_url": "http://choosealicense.com/licenses/mit/",
36
+ "homepage": "http://github.com/carlhuda/bundler/",
37
+ "license": "https://github.com/bundler/bundler/blob/master/LICENSE.md",
38
+ "github_url": "https://github.com/bundler/bundler",
39
+ "github_user": "bundler",
40
+ "github_repo": "bundler"
41
+ }
42
+
43
+ ```
44
+
45
+ Github token is optional, it allows authenticated users to submit more than 20 requests per
46
+ minute
47
+
48
+ ```
49
+ $ GITHUB_TOEKN=mygithubtoken gems-license-finder rails --output json
50
+ {
51
+ "license_type": "MIT",
52
+ "license_url": "http://choosealicense.com/licenses/mit/",
53
+ "homepage": "http://github.com/rails/rails",
54
+ "license": "https://github.com/rails/rails/blob/master/README.md#license",
55
+ "github_url": "https://github.com/rails/rails",
56
+ "github_user": "rails",
57
+ "github_repo": "rails"
58
+ }
59
+ ```
60
+ or
61
+ ```
62
+ $ gems-license-finder redis --output json --token mygithubtoken
63
+ {
64
+ "license_type": "MIT",
65
+ "license_url": "http://choosealicense.com/licenses/mit/",
66
+ "homepage": "https://github.com/redis/redis-rb",
67
+ "license": "https://github.com/redis/redis-rb/blob/master/LICENSE",
68
+ "github_url": "https://github.com/redis/redis-rb",
69
+ "github_user": "redis",
70
+ "github_repo": "redis-rb"
71
+
72
+ ```
73
+ via code
74
+
75
+ ```ruby
76
+ require 'gems-license-finder'
77
+ require 'pp'
78
+
79
+ client = GemsLicenseFinder.new(oauth_token: "MY-GITHUB-TOKEN")
80
+ pp client.find("rails")
81
+
82
+ # this should be printed to the console
83
+
84
+ {:license_type=>"MIT",
85
+ :license_url=>"http://choosealicense.com/licenses/mit/",
86
+ :homepage=>"http://github.com/rails/rails",
87
+ :license=>"https://github.com/rails/rails/blob/master/README.md#license",
88
+ :github_url=>"https://github.com/rails/rails",
89
+ :github_user=>"rails",
90
+ :github_repo=>"rails"}
91
+ ```
92
+
93
+ ## Warranty
94
+ This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
95
+
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path '../lib', __FILE__
2
+ require 'gems-license-finder'
3
+ require 'rubygems/package_task'
4
+ require 'rake/testtask'
5
+
6
+ GemsLicenseFinder::GemSpec = eval File.read 'gems-license-finder.gemspec'
7
+
8
+ Gem::PackageTask.new GemsLicenseFinder::GemSpec do |p|
9
+ p.gem_spec = GemsLicenseFinder::GemSpec
10
+ end
11
+
12
+ ## Tests stuff
13
+ task :default => :test
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs.push 'tests'
17
+ t.pattern = 'tests/**/*_test.rb'
18
+ end
@@ -0,0 +1,33 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib",__FILE__)
4
+
5
+ require 'gems-license-finder'
6
+ require 'yaml'
7
+ require 'json'
8
+ require 'optparse'
9
+
10
+ options = { output: ->(hash) { JSON.pretty_generate hash } }
11
+ options[:oauth_token] = ENV["GITHUB_TOKEN"] if ENV["GITHUB_TOKEN"]
12
+
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Usage: gems-license-finder gem-name [options]"
15
+ opts.separator ""
16
+
17
+ opts.on("-o", "--output FORMAT", "output format [json, yaml]") do |v|
18
+ options[:output] = ->(hash) { hash.to_yaml } if v =~ /yaml/i
19
+ end
20
+
21
+ opts.on("-t", "--token TOKEN", "github token string ( or by GITHUB_TOEKN environment variable )") do |v|
22
+ options[:oauth_token] = v
23
+ end
24
+
25
+ opts.separator ""
26
+ opts.separator "More information about how to generate the github token please look at:"
27
+ opts.separator "https://help.github.com/articles/git-over-https-using-oauth-token"
28
+ opts.separator ""
29
+
30
+ end.parse!
31
+
32
+ ARGV.first or abort "No gem was specified..."
33
+ puts options[:output].(GemsLicenseFinder.new(options).find ARGV.first)
@@ -0,0 +1,132 @@
1
+ # encoding: utf-8
2
+
3
+ require 'github_api'
4
+ require 'open-uri'
5
+ require 'uri'
6
+ require 'github/markup'
7
+ require 'gems-license-finder/version'
8
+
9
+ module GemsLicenseFinder
10
+ GemNotFound = Class.new(StandardError)
11
+
12
+ def self.new(*args)
13
+ Client.new(*args)
14
+ end
15
+
16
+ def self.version
17
+ GemsLicenseFinder::VERSION
18
+ end
19
+
20
+ class Client
21
+
22
+ LICENSE_FILES = %w[LICENSE LICENSE.md LICENSE.markdown MIT-LICENSE LICENSE.txt
23
+ MIT-LICENSE.txt MIT.LICENSE MIT-LICENSE.md COPYING COPYING.md]
24
+ README_FILES = %w[README.md README.rdoc README.markdown README.txt README]
25
+
26
+ def initialize options = {}
27
+ @github = Github.new options.clone
28
+ end
29
+
30
+ def find name
31
+ rubygems_info( name ).merge( github_info name )
32
+ end
33
+
34
+ private
35
+
36
+ def rubygems_info name
37
+ begin
38
+ content = open("http://rubygems.org/gems/#{name}").read
39
+ rescue Exception => e
40
+ raise e.io.status.first == "404" ? GemNotFound.new(e) : e
41
+ end
42
+
43
+ homepage = nil
44
+ type, url = normalize_licence(
45
+ (content.match(/<h5>Licenses<\/h5>.*?<p>(.*?)</msi)[1] rescue ""))
46
+ homepage = (content.match(/<a href="(.*?)".*?>Source/)[1] rescue nil)
47
+ homepage ||= (content.match(/<a href="(.*?)".*?>Home/)[1] rescue nil)
48
+
49
+ { license_type: type, license_url: url, homepage: homepage }
50
+ end
51
+
52
+ def github_info name
53
+ url = find_github_url name
54
+ user, repo = URI(url).path.split("/")[1..2]
55
+ info = {license: nil, github_url: url, github_user: user, github_repo: repo}
56
+
57
+ LICENSE_FILES.each do |file|
58
+ info[:license] = "#{url}/blob/master/#{file}" if fetch_github_file(user, repo, file)
59
+
60
+ if info[:license]
61
+ info[:license_type], info[:license_url] = normalize_licence("mit") if file =~ /mit/i
62
+ break
63
+ end
64
+ end
65
+
66
+ if (!info[:license_type] and gemspec = fetch_github_file(user,repo,"#{name}.gemspec") )
67
+ info[:license_type], info[:license_url] = normalize_licence(gemspec)
68
+ end
69
+
70
+ README_FILES.each do |file|
71
+ next if info[:license]
72
+ page_url = "https://github.com/#{user}/#{repo}/blob/master/#{file}"
73
+ raw_content = fetch_github_file(user, repo, file)
74
+ content = GitHub::Markup.render(file, raw_content) rescue next
75
+
76
+ if content and info[:license_type].nil?
77
+ info[:license_type], info[:license_url] = normalize_licence(content)
78
+ end
79
+
80
+ msi = Regexp::FIXEDENCODING | Regexp::IGNORECASE | Regexp::MULTILINE
81
+ regex = Regexp.new('<h\d+>.*?(license.*?)<\/h\d+>'.force_encoding("UTF-8"),msi)
82
+ info[:license] = page_url + "#" +
83
+ content.match(regex)[1].to_s.downcase.gsub(/\s/,"-") rescue nil
84
+ end
85
+
86
+ info
87
+ end
88
+
89
+ def find_github_url name
90
+ @github.search.repos(q: "#{name} language:ruby").to_a[1][1][0].html_url
91
+ end
92
+
93
+ def fetch_github_file user, repo, file
94
+ begin
95
+ Base64.decode64(@github.repos.contents.get(user, repo, file).content)
96
+ rescue Github::Error::NotFound
97
+ end
98
+ end
99
+
100
+ def normalize_licence str
101
+ case str.downcase
102
+ when /(^|\W)mit(\W|$)/
103
+ ["MIT","http://choosealicense.com/licenses/mit/"]
104
+ when /(^|\W)bsd\W.*?3/
105
+ ["BSD-3","http://choosealicense.com/licenses/bsd-3-clause/"]
106
+ when /(^|\W)bsd(\W|$)/
107
+ ["BSD","http://choosealicense.com/licenses/bsd/"]
108
+ when /(^|\W)apache(\W|$)/
109
+ ["Apache","http://choosealicense.com/licenses/apache/"]
110
+ when /(^|\W)lgpl\W.*?3/
111
+ ["LGPL-3","http://choosealicense.com/licenses/lgpl-v3/"]
112
+ when /(^|\W)lgpl(\W|$)/
113
+ ["LGPL","http://choosealicense.com/licenses/lgpl-v2.1/"]
114
+ when /(affero)|(agpl)/
115
+ ["Affero-GPL","http://choosealicense.com/licenses/agpl/"]
116
+ when /(^|\W)gpl\W.*?3/
117
+ ["GPL-3","http://choosealicense.com/licenses/gpl-v3/"]
118
+ when /(^|\W)gpl(\W|$)/
119
+ ["GPL-2","http://choosealicense.com/licenses/gpl-v2/"]
120
+ when /(^|\W)artistic(\W|$)/
121
+ ["Artistic","http://choosealicense.com/licenses/artistic/"]
122
+ when /(license.*?ruby)|(ruby.*?license)/
123
+ ["Ruby","https://www.ruby-lang.org/en/about/license.txt"]
124
+ when "ruby"
125
+ ["Ruby","https://www.ruby-lang.org/en/about/license.txt"]
126
+ else
127
+ nil
128
+ end
129
+ end
130
+
131
+ end
132
+ end
@@ -0,0 +1,3 @@
1
+ module GemsLicenseFinder
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gems-license-finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eran Barak Levi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github_api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: github-markup
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: posix-spawn
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redcarpet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdiscount
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: maruku
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: kramdown
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: bluecloth
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: faraday
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - <
158
+ - !ruby/object:Gem::Version
159
+ version: '0.9'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - <
165
+ - !ruby/object:Gem::Version
166
+ version: '0.9'
167
+ description: Poor man's license finder for rubygems, that might work
168
+ email: eran@kontera.com
169
+ executables:
170
+ - gems-license-finder
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - Gemfile
175
+ - Gemfile.lock
176
+ - LICENSE
177
+ - README.md
178
+ - Rakefile
179
+ - bin/gems-license-finder
180
+ - lib/gems-license-finder.rb
181
+ - lib/gems-license-finder/version.rb
182
+ homepage: http://www.kontera.com
183
+ licenses: []
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: 1.9.1
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.2.2
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Poor man's license finder for rubygems
205
+ test_files: []