gems-license-finder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a01609bf3346c47dc552b9232be5d69c1e90846d
4
- data.tar.gz: 8f8383ad8bca15ed9b8e6110488767c679b5da89
3
+ metadata.gz: 1b21cfc843e5843f328e1ae633c63e6f0d312f9b
4
+ data.tar.gz: bfeb67385f723d004202e29543a2b1cf9dc0b095
5
5
  SHA512:
6
- metadata.gz: 8e23caae8e928bdd1260a94b874a7f1e1f4b943cb30ae1e07d835581e2fb33ad0ca3ea39f3f39c64422ea160fa4bd75ae0c701f1e76833d01a9f5da93aa06973
7
- data.tar.gz: 9643d7c373a601bb5779f046f89d7d320854fa7c639e362b6b0f4668a1bff027b0f4827be96855fe22b0f95b8e166a428b226e47b06e47e28e008205315212bf
6
+ metadata.gz: 30dd68d50f6ab6156f498edf5e3897510c9b3e249edd771d61f9f49bca942358e6fe4dca526dd6fcd129bbe9df25cd9066cf53abfbdcaaad6030f4c18fd0bf59
7
+ data.tar.gz: 648f4fe7e462579d3de271c7db3a21dd58b9f7bdc5622e09ae1edab7a1e847c8d1811397846e97fb02c6720f5c48969e782cfbd976f78b8b0491469c22b491e0
data/README.md CHANGED
@@ -23,7 +23,7 @@ Usage: gems-license-finder gem-name [options]
23
23
  -o, --output FORMAT output format [json, yaml]
24
24
  -t, --token TOKEN github token string ( or by GITHUB_TOEKN environment variable )
25
25
 
26
- More information about how to generate the github token please look at:
26
+ For more information about how to generate the github token please look at:
27
27
  https://help.github.com/articles/git-over-https-using-oauth-token
28
28
  ```
29
29
 
@@ -57,7 +57,7 @@ $ GITHUB_TOEKN=mygithubtoken gems-license-finder rails --output json
57
57
  "github_repo": "rails"
58
58
  }
59
59
  ```
60
- or
60
+ or via the `--token` switch
61
61
  ```
62
62
  $ gems-license-finder redis --output json --token mygithubtoken
63
63
  {
@@ -68,7 +68,7 @@ $ gems-license-finder redis --output json --token mygithubtoken
68
68
  "github_url": "https://github.com/redis/redis-rb",
69
69
  "github_user": "redis",
70
70
  "github_repo": "redis-rb"
71
-
71
+ }
72
72
  ```
73
73
  via code
74
74
 
@@ -80,16 +80,17 @@ client = GemsLicenseFinder.new(oauth_token: "MY-GITHUB-TOKEN")
80
80
  pp client.find("rails")
81
81
 
82
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"}
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
+ }
91
92
  ```
92
93
 
93
94
  ## 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
+ 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
96
 
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  $:.unshift File.expand_path("../../lib",__FILE__)
4
5
 
@@ -23,7 +24,7 @@ OptionParser.new do |opts|
23
24
  end
24
25
 
25
26
  opts.separator ""
26
- opts.separator "More information about how to generate the github token please look at:"
27
+ opts.separator "For more information about how to generate the github token please look at:"
27
28
  opts.separator "https://help.github.com/articles/git-over-https-using-oauth-token"
28
29
  opts.separator ""
29
30
 
@@ -1,3 +1,3 @@
1
1
  module GemsLicenseFinder
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,11 +18,26 @@ module GemsLicenseFinder
18
18
  end
19
19
 
20
20
  class Client
21
+ LICENSE_FILES = %w[LICENSE LICENSE.md LICENSE.markdown MIT-LICENSE
22
+ LICENSE.txt MIT-LICENSE.txt MIT.LICENSE MIT-LICENSE.md
23
+ COPYING COPYING.md]
21
24
 
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
25
  README_FILES = %w[README.md README.rdoc README.markdown README.txt README]
25
26
 
27
+ LICENSES_STRINGS = {
28
+ "mit" => "Permission is hereby granted",
29
+ "affero" => "GNU AFFERO",
30
+ "artistic" => "artistic",
31
+ "apache" => "apache",
32
+ "bsd-3" => "Neither the name of the",
33
+ "bsd" => "Redistribution and use in source and binary forms",
34
+ "gpl-3" => "GNU GENERAL.*?Version 3",
35
+ "gpl" => "GNU GENERAL",
36
+ "lgpl-3" => "GNU LESSER GENERAL.*?Version 3",
37
+ "lgpl" => "GNU LESSER",
38
+ "ruby" => "You may make and give away verbatim copies"
39
+ }
40
+
26
41
  def initialize options = {}
27
42
  @github = Github.new options.clone
28
43
  end
@@ -33,6 +48,11 @@ module GemsLicenseFinder
33
48
 
34
49
  private
35
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
+
36
56
  def rubygems_info name
37
57
  begin
38
58
  content = open("http://rubygems.org/gems/#{name}").read
@@ -54,38 +74,51 @@ module GemsLicenseFinder
54
74
  user, repo = URI(url).path.split("/")[1..2]
55
75
  info = {license: nil, github_url: url, github_user: user, github_repo: repo}
56
76
 
77
+ type, lurl = []
78
+
57
79
  LICENSE_FILES.each do |file|
58
- info[:license] = "#{url}/blob/master/#{file}" if fetch_github_file(user, repo, file)
80
+ content = fetch_github_file(user, repo, file)
81
+ info[:license] = "#{url}/blob/master/#{file}" if content
59
82
 
60
83
  if info[:license]
61
- info[:license_type], info[:license_url] = normalize_licence("mit") if file =~ /mit/i
84
+ type, lurl = (file =~ /mit/i) ?
85
+ normalize_licence("mit") : type_from_license_text(content)
62
86
  break
63
87
  end
64
88
  end
65
89
 
66
- if (!info[:license_type] and gemspec = fetch_github_file(user,repo,"#{name}.gemspec") )
67
- info[:license_type], info[:license_url] = normalize_licence(gemspec)
90
+ if (!type and gemspec = fetch_github_file(user,repo,"#{name}.gemspec") )
91
+ type, lurl = normalize_licence(gemspec)
68
92
  end
69
93
 
70
94
  README_FILES.each do |file|
71
- next if info[:license]
95
+ next if info[:license] and type
72
96
  page_url = "https://github.com/#{user}/#{repo}/blob/master/#{file}"
73
97
  raw_content = fetch_github_file(user, repo, file)
74
98
  content = GitHub::Markup.render(file, raw_content) rescue next
99
+ type, lurl = normalize_licence(content) if content and type.nil?
75
100
 
76
- if content and info[:license_type].nil?
77
- info[:license_type], info[:license_url] = normalize_licence(content)
101
+ info[:license] ||= page_url + "#" +
102
+ utf8_match(content,'<h\d+>.*?(license.*?)<\/h\d+>')[1].to_s.downcase.gsub(/\s/,"-") rescue nil
103
+
104
+ if info[:license] and type.nil?
105
+ type, lurl = type_from_license_text(content)
78
106
  end
79
107
 
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
108
  end
85
109
 
110
+ info[:license_type] = type if type
111
+ info[:license_url] = lurl if lurl
86
112
  info
87
113
  end
88
114
 
115
+ def utf8_match text, regex
116
+ text.force_encoding("utf-8").match Regexp.new(
117
+ regex.force_encoding("utf-8"),
118
+ Regexp::FIXEDENCODING|Regexp::IGNORECASE|Regexp::MULTILINE
119
+ )
120
+ end
121
+
89
122
  def find_github_url name
90
123
  @github.search.repos(q: "#{name} language:ruby").to_a[1][1][0].html_url
91
124
  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.1
4
+ version: 0.0.2
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-23 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest