gems-license-finder 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b21cfc843e5843f328e1ae633c63e6f0d312f9b
4
- data.tar.gz: bfeb67385f723d004202e29543a2b1cf9dc0b095
3
+ metadata.gz: f98586f27c7d0fbd33dc870a4ec90e67d7dfcc13
4
+ data.tar.gz: c2d415e82f4de573a6bf8c253a75f11ef28a0cc3
5
5
  SHA512:
6
- metadata.gz: 30dd68d50f6ab6156f498edf5e3897510c9b3e249edd771d61f9f49bca942358e6fe4dca526dd6fcd129bbe9df25cd9066cf53abfbdcaaad6030f4c18fd0bf59
7
- data.tar.gz: 648f4fe7e462579d3de271c7db3a21dd58b9f7bdc5622e09ae1edab7a1e847c8d1811397846e97fb02c6720f5c48969e782cfbd976f78b8b0491469c22b491e0
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 GITHUB_TOEKN environment variable )
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 --output json
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
- "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"
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
- $ GITHUB_TOEKN=mygithubtoken gems-license-finder rails --output json
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
- "homepage": "http://github.com/rails/rails",
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 --output json --token mygithubtoken
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
- "homepage": "https://github.com/redis/redis-rb",
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
- :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
+ "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
 
@@ -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 GITHUB_TOEKN environment variable )") do |v|
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"
@@ -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
- rubygems_info( name ).merge( github_info name )
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
- homepage = nil
58
+ info = Hash[content.scan(/<a href="(.*?)" rel.*>(.*?)</)].invert
64
59
  type, url = normalize_licence(
65
- (content.match(/<h5>Licenses<\/h5>.*?<p>(.*?)</msi)[1] rescue ""))
66
- homepage = (content.match(/<a href="(.*?)".*?>Source/)[1] rescue nil)
67
- homepage ||= (content.match(/<a href="(.*?)".*?>Home/)[1] rescue nil)
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, homepage: homepage }
64
+ info.merge({ license_type: type, license_url: url, description: description })
70
65
  end
71
66
 
72
- def github_info name
73
- url = find_github_url name
74
- user, repo = URI(url).path.split("/")[1..2]
75
- info = {license: nil, github_url: url, github_user: user, github_repo: repo}
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
- type, lurl = []
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
- info[:license] = "#{url}/blob/master/#{file}" if content
82
+ license = "#{url}/blob/master/#{file}" if content
82
83
 
83
- if info[:license]
84
- type, lurl = (file =~ /mit/i) ?
85
- normalize_licence("mit") : type_from_license_text(content)
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
- next if info[:license] and type
96
- page_url = "https://github.com/#{user}/#{repo}/blob/master/#{file}"
97
- raw_content = fetch_github_file(user, repo, file)
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
- if info[:license] and type.nil?
105
- type, lurl = type_from_license_text(content)
106
- end
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|$)/
@@ -1,3 +1,3 @@
1
1
  module GemsLicenseFinder
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-25 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest