gems-license-finder 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -24
- data/bin/gems-license-finder +6 -1
- data/lib/gems-license-finder.rb +40 -33
- data/lib/gems-license-finder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f98586f27c7d0fbd33dc870a4ec90e67d7dfcc13
|
4
|
+
data.tar.gz: c2d415e82f4de573a6bf8c253a75f11ef28a0cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ce3bc14c5e56d0f8101a9f67d6207bbec04468ada63ab4bf0363d5f67556ee4d7572d63d91a28bb674032acb91ea216fa919ef5ee170f48b3ca5a264d9b5a8
|
7
|
+
data.tar.gz: 4955d84a89745a597e6ab1073ee0cdf24273aa8fe34251d2380c5c965a610c445c56209af4c24ed53d7f2895f1e66c9e421eb42840dae3af0edcc0a95b7c9321
|
data/README.md
CHANGED
@@ -21,7 +21,8 @@ $ gems-license-finder --help
|
|
21
21
|
Usage: gems-license-finder gem-name [options]
|
22
22
|
|
23
23
|
-o, --output FORMAT output format [json, yaml]
|
24
|
-
-t, --token TOKEN github token string ( or by
|
24
|
+
-t, --token TOKEN github token string ( or by GITHUB_TOKEN environment variable )
|
25
|
+
-v, --version Print version and exit
|
25
26
|
|
26
27
|
For more information about how to generate the github token please look at:
|
27
28
|
https://help.github.com/articles/git-over-https-using-oauth-token
|
@@ -29,15 +30,18 @@ https://help.github.com/articles/git-over-https-using-oauth-token
|
|
29
30
|
|
30
31
|
finding the license of `bundler` gem
|
31
32
|
```
|
32
|
-
$ gems-license-finder bundler
|
33
|
+
$ gems-license-finder bundler
|
33
34
|
{
|
35
|
+
"homepage": "http://bundler.io",
|
36
|
+
"source_code": "http://github.com/carlhuda/bundler/",
|
37
|
+
"documentation": "http://gembundler.com",
|
38
|
+
"mailing_list": "http://groups.google.com/group/ruby-bundler?hl=en",
|
39
|
+
"bug_tracker": "http://github.com/carlhuda/bundler/issues",
|
34
40
|
"license_type": "MIT",
|
35
41
|
"license_url": "http://choosealicense.com/licenses/mit/",
|
36
|
-
"
|
37
|
-
"license": "https://github.com/bundler/bundler
|
38
|
-
"github_url": "https://github.com/bundler/bundler"
|
39
|
-
"github_user": "bundler",
|
40
|
-
"github_repo": "bundler"
|
42
|
+
"description": "Bundler manages an application's dependencies through its entire life, across many machines, systematically and repeatably",
|
43
|
+
"license": "https://github.com/bundler/bundler//blob/master/LICENSE.md",
|
44
|
+
"github_url": "https://github.com/bundler/bundler/"
|
41
45
|
}
|
42
46
|
|
43
47
|
```
|
@@ -46,28 +50,31 @@ Github token is optional, it allows authenticated users to submit more than 20 r
|
|
46
50
|
minute
|
47
51
|
|
48
52
|
```
|
49
|
-
$
|
53
|
+
$ GITHUB_TOKEN=mygithubtoken gems-license-finder rails
|
50
54
|
{
|
55
|
+
"homepage": "http://www.rubyonrails.org",
|
56
|
+
"source_code": "http://github.com/rails/rails",
|
57
|
+
"documentation": "http://api.rubyonrails.org",
|
58
|
+
"wiki": "http://wiki.rubyonrails.org",
|
59
|
+
"mailing_list": "http://groups.google.com/group/rubyonrails-talk",
|
60
|
+
"bug_tracker": "http://github.com/rails/rails/issues",
|
51
61
|
"license_type": "MIT",
|
52
62
|
"license_url": "http://choosealicense.com/licenses/mit/",
|
53
|
-
"
|
63
|
+
"description": "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.",
|
54
64
|
"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"
|
65
|
+
"github_url": "https://github.com/rails/rails"
|
58
66
|
}
|
59
67
|
```
|
60
68
|
or via the `--token` switch
|
61
69
|
```
|
62
|
-
$ gems-license-finder redis --
|
70
|
+
$ gems-license-finder redis --token mygithubtoken
|
63
71
|
{
|
72
|
+
"homepage": "https://github.com/redis/redis-rb",
|
64
73
|
"license_type": "MIT",
|
65
74
|
"license_url": "http://choosealicense.com/licenses/mit/",
|
66
|
-
"
|
75
|
+
"description": "A Ruby client that tries to match Redis' API one-to-one, while still providing an idiomatic interface. It features thread-safety, client-side sharding, pipelining, and an obsession for performance.",
|
67
76
|
"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"
|
77
|
+
"github_url": "https://github.com/redis/redis-rb"
|
71
78
|
}
|
72
79
|
```
|
73
80
|
via code
|
@@ -81,13 +88,16 @@ pp client.find("rails")
|
|
81
88
|
|
82
89
|
# this should be printed to the console
|
83
90
|
{
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
+
"homepage"=>"http://www.rubyonrails.org",
|
92
|
+
"source_code"=>"http://github.com/rails/rails",
|
93
|
+
"documentation"=>"http://api.rubyonrails.org",
|
94
|
+
"wiki"=>"http://wiki.rubyonrails.org",
|
95
|
+
"mailing_list"=>"http://groups.google.com/group/rubyonrails-talk",
|
96
|
+
"bug_tracker"=>"http://github.com/rails/rails/issues",
|
97
|
+
"license_type"=>"MIT",
|
98
|
+
"license_url"=>"http://choosealicense.com/licenses/mit/",
|
99
|
+
"license"=>"https://github.com/rails/rails/blob/master/README.md#license",
|
100
|
+
"github_url"=>"https://github.com/rails/rails"
|
91
101
|
}
|
92
102
|
```
|
93
103
|
|
data/bin/gems-license-finder
CHANGED
@@ -19,10 +19,15 @@ OptionParser.new do |opts|
|
|
19
19
|
options[:output] = ->(hash) { hash.to_yaml } if v =~ /yaml/i
|
20
20
|
end
|
21
21
|
|
22
|
-
opts.on("-t", "--token TOKEN", "github token string ( or by
|
22
|
+
opts.on("-t", "--token TOKEN", "github token string ( or by GITHUB_TOKEN environment variable )") do |v|
|
23
23
|
options[:oauth_token] = v
|
24
24
|
end
|
25
25
|
|
26
|
+
opts.on("-v", "--version","print current version and exit") do
|
27
|
+
puts GemsLicenseFinder.version
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
26
31
|
opts.separator ""
|
27
32
|
opts.separator "For more information about how to generate the github token please look at:"
|
28
33
|
opts.separator "https://help.github.com/articles/git-over-https-using-oauth-token"
|
data/lib/gems-license-finder.rb
CHANGED
@@ -20,7 +20,7 @@ module GemsLicenseFinder
|
|
20
20
|
class Client
|
21
21
|
LICENSE_FILES = %w[LICENSE LICENSE.md LICENSE.markdown MIT-LICENSE
|
22
22
|
LICENSE.txt MIT-LICENSE.txt MIT.LICENSE MIT-LICENSE.md
|
23
|
-
COPYING COPYING.md]
|
23
|
+
COPYING COPYING.md GNU GNU.txt GNU.rdoc GNU.markdown]
|
24
24
|
|
25
25
|
README_FILES = %w[README.md README.rdoc README.markdown README.txt README]
|
26
26
|
|
@@ -43,16 +43,11 @@ module GemsLicenseFinder
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def find name
|
46
|
-
|
46
|
+
normalize(github_info name, rubygems_info( name ))
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def type_from_license_text t
|
52
|
-
LICENSES_STRINGS.each {|n,s| return normalize_licence(n) if utf8_match(t,s)}
|
53
|
-
nil
|
54
|
-
end
|
55
|
-
|
56
51
|
def rubygems_info name
|
57
52
|
begin
|
58
53
|
content = open("http://rubygems.org/gems/#{name}").read
|
@@ -60,29 +55,35 @@ module GemsLicenseFinder
|
|
60
55
|
raise e.io.status.first == "404" ? GemNotFound.new(e) : e
|
61
56
|
end
|
62
57
|
|
63
|
-
|
58
|
+
info = Hash[content.scan(/<a href="(.*?)" rel.*>(.*?)</)].invert
|
64
59
|
type, url = normalize_licence(
|
65
|
-
(content
|
66
|
-
|
67
|
-
|
60
|
+
(utf8_match(content,'<h5>Licenses<\/h5>.*?<p>(.*?)<')[1] rescue ""))
|
61
|
+
description = (utf8_match(content,'<div id="markup">.*?<p>(.*?)<')[1].
|
62
|
+
strip.squeeze(" ").gsub(/\n/,"") rescue nil)
|
68
63
|
|
69
|
-
{ license_type: type, license_url: url,
|
64
|
+
info.merge({ license_type: type, license_url: url, description: description })
|
70
65
|
end
|
71
66
|
|
72
|
-
def github_info name
|
73
|
-
url =
|
74
|
-
|
75
|
-
|
67
|
+
def github_info name, rubygems
|
68
|
+
url = rubygems["Source Code"] || rubygems["Homepage"]
|
69
|
+
if url.to_s =~ /github\.com/
|
70
|
+
# Sometimes the homepage in rubygems.org is old, e.g:
|
71
|
+
# carlhuda/bundler => bundler/bundler
|
72
|
+
open(url.sub("http:","https:")) { |o| url = o.base_uri.to_s } # follow redirects
|
73
|
+
else
|
74
|
+
url = nil
|
75
|
+
end
|
76
76
|
|
77
|
-
|
77
|
+
url ||= find_github_url name
|
78
|
+
user, repo, type, lurl, license = URI(url).path.split("/")[1..2]
|
78
79
|
|
79
80
|
LICENSE_FILES.each do |file|
|
80
81
|
content = fetch_github_file(user, repo, file)
|
81
|
-
|
82
|
+
license = "#{url}/blob/master/#{file}" if content
|
82
83
|
|
83
|
-
if
|
84
|
-
type, lurl = (file =~ /mit/i) ?
|
85
|
-
normalize_licence("
|
84
|
+
if license
|
85
|
+
type, lurl = (file =~ /mit|gnu/i) ?
|
86
|
+
normalize_licence(file.split(".").first) : type_from_license_text(content)
|
86
87
|
break
|
87
88
|
end
|
88
89
|
end
|
@@ -92,24 +93,21 @@ module GemsLicenseFinder
|
|
92
93
|
end
|
93
94
|
|
94
95
|
README_FILES.each do |file|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
content = GitHub::Markup.render(file, raw_content) rescue next
|
99
|
-
type, lurl = normalize_licence(content) if content and type.nil?
|
100
|
-
|
101
|
-
info[:license] ||= page_url + "#" +
|
102
|
-
utf8_match(content,'<h\d+>.*?(license.*?)<\/h\d+>')[1].to_s.downcase.gsub(/\s/,"-") rescue nil
|
96
|
+
break if license and type
|
97
|
+
content = GitHub::Markup.render(file,fetch_github_file(user,repo,file)) rescue next
|
98
|
+
type, lurl = normalize_licence(content) if type.nil?
|
103
99
|
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
license ||= "https://github.com/#{user}/#{repo}/blob/master/#{file}#" +
|
101
|
+
utf8_match(content,'<h\d+>.*?(license.*?)<\/h\d+>')[1].
|
102
|
+
to_s.downcase.gsub(/\s/,"-") rescue nil
|
107
103
|
|
104
|
+
type, lurl = type_from_license_text(content) if license and type.nil?
|
108
105
|
end
|
109
106
|
|
107
|
+
info = {license: license, github_url: url}
|
110
108
|
info[:license_type] = type if type
|
111
109
|
info[:license_url] = lurl if lurl
|
112
|
-
info
|
110
|
+
rubygems.merge info
|
113
111
|
end
|
114
112
|
|
115
113
|
def utf8_match text, regex
|
@@ -130,6 +128,15 @@ module GemsLicenseFinder
|
|
130
128
|
end
|
131
129
|
end
|
132
130
|
|
131
|
+
def type_from_license_text t
|
132
|
+
LICENSES_STRINGS.each {|n,s| return normalize_licence(n) if utf8_match(t,s)}
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
|
136
|
+
def normalize hash
|
137
|
+
Hash[hash.map {|k,v| [k.to_s.downcase.gsub(/\s/,"_"),v]}]
|
138
|
+
end
|
139
|
+
|
133
140
|
def normalize_licence str
|
134
141
|
case str.downcase
|
135
142
|
when /(^|\W)mit(\W|$)/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gems-license-finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eran Barak Levi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|