gempendencies 0.1.0 → 0.1.5

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
  SHA256:
3
- metadata.gz: 174a5a541ad86cef48f122d348dfdb0725cecc3ebc2e182a9511026defc987f2
4
- data.tar.gz: d7c0f0e717c1946faa828a4e84fdf1bec528d083429615c7978e68f0aaed6452
3
+ metadata.gz: 66c6b02ac30e6061bb9b805320a68ae37d19ca1af5c15f3df6eb0bc406478c45
4
+ data.tar.gz: 5b3feb8a468ea87fa5b825e31dfd13a5e6ea026104cfdf7f51280d17ebd0ed8c
5
5
  SHA512:
6
- metadata.gz: dabde61dcec1d84b1d8a52f8a73cab1de161dcaf3058da51e9a75a9b392fc717210a092b0af956dac6b7cc20b8022f4136a85425f409ed975d670bad76f569ac
7
- data.tar.gz: 6518bad7caf4df392585a53fd6e35bf5d34b9c9ae4e2cf72344bd5c4bd7d9547eb8adcefcdb343ca8f7ffe6486031a7772ab308bdc109ca9f41f220cff9ec26a
6
+ metadata.gz: a5961d06fdf4fe1ef430fa0ce1cb4801cff54ece9ecacdddb6f0ecb73c47167217dea7a2599ee5b8a7ded9a0f8f2b1ae9eb77ebddc1a64b56d09517c567f3fc7
7
+ data.tar.gz: 67059fbc266bfd2d3a357c7c9154dd6206167781cc3e27734c1ffdb49d8c5a001c2bd16ed74300e51aba8abf7044bf296b7aaddc5fe9453cf499e433e3c327fe
data/bin/gempendencies CHANGED
@@ -1,21 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
4
- abort 'Please run gempendencies from the root of the project.'
5
- end
3
+ # unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
4
+ # abort 'Please run gempendencies from the root of the project.'
5
+ # end
6
6
 
7
7
  require 'rubygems'
8
+ require 'gempendencies'
9
+ require 'gempendencies/gem_info'
10
+
11
+ here = File.expand_path(File.dirname __FILE__)
12
+ $LOAD_PATH << "#{here}/../lib"
13
+
8
14
  begin
9
15
  require 'bundler'
10
16
  Bundler.setup
17
+ # If we're in a Bundler-managed project, then build the information for it
18
+ Gempendencies::GemInfo.new.build
11
19
  rescue StandardError => e
12
- puts "ERROR: #{e.message}"
20
+ # Otherwise, look for nested projects that have .gempendencies info and aggregate it
21
+ Gempendencies::GemInfo.new.aggregate
13
22
  end
14
-
15
- here = File.expand_path(File.dirname __FILE__)
16
- $LOAD_PATH << "#{here}/../lib"
17
-
18
- require 'gempendencies'
19
- require 'gempendencies/gem_info'
20
-
21
- Gempendencies::GemInfo.new.build
@@ -4,6 +4,7 @@ require 'nokogiri'
4
4
  require 'open-uri'
5
5
  require 'set'
6
6
  require 'securerandom'
7
+ require 'yaml'
7
8
 
8
9
  module Gempendencies
9
10
 
@@ -34,23 +35,60 @@ module Gempendencies
34
35
  class GemInfo
35
36
  def initialize
36
37
  @domain_badge_labels = {}
37
- # note - be sure to double backslash all the CLI backslashes
38
- if File.exist?(".gempendencies/gem_info.txt")
39
- github_urls
40
- else
41
- "You need to generate gem_info.txt - GemInfo.new.build_gem_info_txt"
42
- end
38
+ # # note - be sure to double backslash all the CLI backslashes
39
+ # if File.exist?(".gempendencies/gem_info.txt")
40
+ # github_urls
41
+ # else
42
+ # build_gem_info_txt
43
+ # end
43
44
  end
44
45
 
45
46
  # uses bundler to build the gem_info.txt summarization of all gems used...
46
47
  def build_gem_info_txt
47
48
  # https://gist.github.com/deevis/3211023e2b14e85df6ca908dbc642a2d
48
49
  # https://gist.githubusercontent.com/deevis/3211023e2b14e85df6ca908dbc642a2d/raw/9fe1c9dfedc15b328cbe2e3f64f8198d56bb9795/generate_gem_info.sh
49
- `bin/generate_gem_info.sh`
50
+ `mkdir -p .gempendencies`
51
+ gem_names = `bundle list`.split("\n").select{|s| s.index("*") && s.index("(")}.map{|s| s.split("*").last.split("(").first.gsub(" ","")}
52
+ count = gem_names.length
53
+ puts "Fetching 'gem info' for #{count} dependencies..."
54
+ gem_info = {}
55
+ license_counts = Hash.new(0)
56
+ author_counts = Hash.new(0)
57
+ gem_names.each_with_index do |gem_name,i|
58
+ cmd = "gem info #{gem_name}"
59
+ puts "\n#{i+1}/#{count} #{cmd}"
60
+ info = `#{cmd}`
61
+ data = {}
62
+ info.split("\n").each do |line|
63
+ next unless line.index(":")
64
+ next if line.index("Installed at")
65
+ key, value = line.split(": ")
66
+ key = key.gsub('"', "").gsub(" ", "")
67
+ case key
68
+ when "Author", "Authors"
69
+ key = "Author"
70
+ value = value.split(", ")
71
+ value.each{|v| author_counts[v] += 1}
72
+ when "License", "Licenses"
73
+ key = "License"
74
+ value = value.split(", ")
75
+ value.each{|v| license_counts[v] += 1}
76
+ end
77
+ data[key] = value
78
+ end
79
+ gem_info[gem_name] = data
80
+ end
81
+ File.open(".gempendencies/gem_info.yaml", "w") do |f|
82
+ f.puts gem_info.to_yaml
83
+ end
84
+ author_counts = Hash[author_counts.sort{|a,b| b[1] <=> a[1]}]
85
+ File.open(".gempendencies/author_info.yaml", "w"){|f| f.puts author_counts.to_yaml}
86
+ license_counts = Hash[license_counts.sort{|a,b| b[1] <=> a[1]}]
87
+ File.open(".gempendencies/license_info.yaml", "w"){|f| f.puts license_counts.to_yaml}
50
88
  end
51
89
 
52
90
  def github_urls
53
- @github_urls = `grep "Homepage:" .gempendencies/gem_info.txt | grep "github" | sed 's/.*page: \\(.*\\)/\\1/g'`.split("\n").uniq
91
+ @github_urls = `grep "Homepage:" .gempendencies/gem_info.yaml | grep "github" | sed 's/.*page: \\(.*\\)/\\1/g'`.split("\n").uniq
54
92
  #puts @github_urls
55
93
  puts "Got #{@github_urls.length} github urls to process"
56
94
  @github_urls
@@ -121,35 +159,72 @@ module Gempendencies
121
159
  contents
122
160
  end
123
161
 
124
- def build
125
- if !File.exist?("gem_info.txt")
162
+ def aggregate
163
+ data = {}
164
+ total_counts = Hash.new(0)
165
+ puts "Searching recursively for nested .gempendencies to aggregate"
166
+ paths = `find . -iname "license_info.yaml"`
167
+ paths.split("\n").each do |path|
168
+ "./business_rules/.gempendencies/license_info.yaml"
169
+ puts path
170
+ project_name = path.match(/.\/(.*)\/\.gem.*/)[1]
171
+ licenses = YAML.load_file(path)
172
+ data[project_name] = licenses
173
+ licenses.each do |name, count|
174
+ total_counts[name] += count
175
+ end
176
+ end
177
+ data['TOTALS'] = total_counts
178
+ # order output columns by most common license
179
+ puts "-" * 60
180
+ puts " Start CSV output"
181
+ puts "-" * 60
182
+ columns = Hash[total_counts.sort{|a,b| b[1] <=> a[1]}].keys
183
+ puts (['project'] + columns).join(',')
184
+ data.each do |project_name, counts|
185
+ print project_name
186
+ columns.each do |col|
187
+ print ','
188
+ print counts[col]
189
+ end
190
+ puts
191
+ end
192
+ puts "-" * 60
193
+ puts " End CSV output"
194
+ puts "-" * 60
195
+ end
196
+
197
+ def build(load_github_metadata = false)
198
+ if !File.exist?(".gempendencies/gem_info.yaml")
126
199
  build_gem_info_txt
127
200
  end
128
- @github_urls.each do |url|
129
- cleansed = url.gsub(/http[s]*:../, '').gsub('github.com','').gsub('github.io','').gsub("/", " ").gsub(".", "").strip
130
- owner, repo = cleansed.split(" ")
131
- if owner && repo
132
- url = "https://api.github.com/repos/#{owner}/#{repo}"
133
- # puts "#{owner} - #{repo} : #{url}"
134
- directory = ".gempendencies/#{owner}/#{repo}"
135
- `mkdir -p #{directory}`
136
- file = "#{directory}/curl_result.json"
137
-
138
- if File.exist?(file)
139
- if (contents = File.read(file)).index("Moved Permanently")
140
- json = JSON.parse(contents)
141
- url = json['url']
142
- elsif !contents.index("rate limit exceeded")
143
- puts "skipping #{file}..."
144
- json = JSON.parse(contents)
145
- get_badges(json['html_url'], directory)
146
- next
201
+ if load_github_metadata
202
+ @github_urls.each do |url|
203
+ cleansed = url.gsub(/http[s]*:../, '').gsub('github.com','').gsub('github.io','').gsub("/", " ").gsub(".", "").strip
204
+ owner, repo = cleansed.split(" ")
205
+ if owner && repo
206
+ url = "https://api.github.com/repos/#{owner}/#{repo}"
207
+ # puts "#{owner} - #{repo} : #{url}"
208
+ directory = ".gempendencies/#{owner}/#{repo}"
209
+ `mkdir -p #{directory}`
210
+ file = "#{directory}/curl_result.json"
211
+
212
+ if File.exist?(file)
213
+ if (contents = File.read(file)).index("Moved Permanently")
214
+ json = JSON.parse(contents)
215
+ url = json['url']
216
+ elsif !contents.index("rate limit exceeded")
217
+ puts "skipping #{file}..."
218
+ json = JSON.parse(contents)
219
+ get_badges(json['html_url'], directory)
220
+ next
221
+ end
147
222
  end
148
- end
149
223
 
150
- contents = get_repo_json(url, file)
151
- json = JSON.parse(contents)
152
- get_badges(json['html_url'], directory)
224
+ contents = get_repo_json(url, file)
225
+ json = JSON.parse(contents)
226
+ get_badges(json['html_url'], directory)
227
+ end
153
228
  end
154
229
  end
155
230
  end # def build
@@ -1,3 +1,3 @@
1
1
  module Gempendencies
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gempendencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Hicks
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,26 +66,17 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: Builds a comprehensive list of gems used by your project
69
+ description: Builds a comprehensive list of gems used by your project and summarizes
70
+ the OSS Licenses being used
70
71
  email:
71
72
  - darren.hicks@gmail.com
72
- executables: []
73
+ executables:
74
+ - gempendencies
73
75
  extensions: []
74
76
  extra_rdoc_files: []
75
77
  files:
76
- - ".gitignore"
77
- - ".rspec"
78
- - ".travis.yml"
79
- - Gemfile
80
- - Gemfile.lock
81
- - LICENSE.txt
82
78
  - README.md
83
- - Rakefile
84
- - bin/console
85
79
  - bin/gempendencies
86
- - bin/generate_gem_info.sh
87
- - bin/setup
88
- - gempendencies.gemspec
89
80
  - lib/gempendencies.rb
90
81
  - lib/gempendencies/gem_info.rb
91
82
  - lib/gempendencies/version.rb
@@ -110,8 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
101
  - !ruby/object:Gem::Version
111
102
  version: '0'
112
103
  requirements: []
113
- rubygems_version: 3.1.2
104
+ rubygems_version: 3.2.16
114
105
  signing_key:
115
106
  specification_version: 4
116
- summary: Builds a comprehensive list of gems used by your project
107
+ summary: Builds a comprehensive list of gems used by your project and summarizes the
108
+ OSS Licenses being used
117
109
  test_files: []
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- .gempendencies
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 2.0.2
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in gempendencies.gemspec
4
- gemspec
data/Gemfile.lock DELETED
@@ -1,41 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- gempendencies (0.1.0)
5
- nokogiri
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- diff-lcs (1.4.4)
11
- mini_portile2 (2.5.0)
12
- nokogiri (1.11.2)
13
- mini_portile2 (~> 2.5.0)
14
- racc (~> 1.4)
15
- racc (1.5.2)
16
- rake (10.5.0)
17
- rspec (3.10.0)
18
- rspec-core (~> 3.10.0)
19
- rspec-expectations (~> 3.10.0)
20
- rspec-mocks (~> 3.10.0)
21
- rspec-core (3.10.1)
22
- rspec-support (~> 3.10.0)
23
- rspec-expectations (3.10.1)
24
- diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.10.0)
26
- rspec-mocks (3.10.2)
27
- diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.10.0)
29
- rspec-support (3.10.2)
30
-
31
- PLATFORMS
32
- ruby
33
-
34
- DEPENDENCIES
35
- bundler (~> 2.0)
36
- gempendencies!
37
- rake (~> 10.0)
38
- rspec (~> 3.0)
39
-
40
- BUNDLED WITH
41
- 2.0.2
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2021 dhicks@verisys.com
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
13
- all 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
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "gempendencies"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
@@ -1,27 +0,0 @@
1
- # Build an informative list of all Gems used by the project - this will take a minute to run
2
- mkdir -p .gempendencies
3
-
4
- echo "Calling 'gem info' for every gem in the project...patience is a virtue..."
5
- for gem in `bundle list | sed 's/ \* \(.*\) (.*/\1/g' | grep -v " "`
6
- do echo "------------------------ $gem -----------------------------------"
7
- gem info $gem | grep -v "Installed at"
8
- done | tee .gempendencies/gem_info.txt
9
-
10
- echo "Building License Counts"
11
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
12
- echo " Licenses " | tee -a .gempendencies/gem_info.txt
13
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
14
- grep "License[s]*" .gempendencies/gem_info.txt | sed 's/.*License[s]*: \(.*\)/\1/g' | sort | uniq -c | sort -n -r | tee -a .gempendencies/gem_info.txt
15
-
16
- echo "Building Prolific Author Counts"
17
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
18
- echo " Top Gem Authors " | tee -a .gempendencies/gem_info.txt
19
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
20
- grep "Author[s]*:" .gempendencies/gem_info.txt | sed 's/.*Author[s]*: \(.*\)/\1/g' | sort | uniq -c | sort -n -r | head -n 15 | tee -a .gempendencies/gem_info.txt
21
-
22
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
23
- echo " Total Gem Count " | tee -a .gempendencies/gem_info.txt
24
- echo "#---#---#---#---#---#---#---#---#---#---#---#---#---#---#" | tee -a .gempendencies/gem_info.txt
25
- grep "Author[s]*:" .gempendencies/gem_info.txt | wc -l | tee -a .gempendencies/gem_info.txt
26
-
27
- echo "We done - check out gem_info.txt for results"
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,35 +0,0 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "gempendencies/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "gempendencies"
7
- spec.version = Gempendencies::VERSION
8
- spec.authors = ["Darren Hicks"]
9
- spec.email = ["darren.hicks@gmail.com"]
10
-
11
- spec.summary = %q{Builds a comprehensive list of gems used by your project}
12
- spec.description = %q{Builds a comprehensive list of gems used by your project}
13
- spec.homepage = "https://github.com/deevis/gempendencies"
14
- spec.license = "MIT"
15
-
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/deevis/gempendencies"
19
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_dependency "nokogiri"
31
-
32
- spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- end