organization_license_audit 1.0.5 → 1.1.0

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: a89c9fdc93f0edd11c07091733e8da1d0ea842fd
4
- data.tar.gz: 569e59dfc0e12564943ce11bb1c62811bc28bdf1
3
+ metadata.gz: 14a8ff97904b324543f7cb11217c164dd0deb7b0
4
+ data.tar.gz: 2b988a0e00bd2ad81febc27665a6762e2a5b952d
5
5
  SHA512:
6
- metadata.gz: 936067f7327b52ecd4c3c138b7799c6a9ec31879a4beec9e8fe24b3a5c8f2f1b58f4779799ec10adbe6190e3ea80f309cfd2b3248646d184f599d252b0b427b7
7
- data.tar.gz: 963a1c534f30508d42b0f85e4115ed488cb3937419a5dcb5e5bea843c8e0dc36d7d6f3ada99a8ec3a4d8760853c2881ee8aad25b1b167787e4a87911bb31f9fa
6
+ metadata.gz: 856767681e8befa89e37d27bb7cd2eaa3a6faf99f25f38b2d369f6c8a7407774fa6bb1b62ae2bb311bdca7ba74ffd39a32dc72730c86e81652e86aed9767ed10
7
+ data.tar.gz: 75602c0aaf489633a374c4631132e8cf3ea48171385bb0cd21762149fd8aa01e61ac6cb1dc15f481f472616284ef536134e4ced6efe7add1d23f2c337199909e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -31,6 +31,7 @@ BANNER
31
31
  options[:csv] = separator
32
32
  end
33
33
  parser.on("--ignore-gems", "Ignore repos that have a %{repo}.gemspec") { options[:ignore_gems] = true }
34
+ parser.on("--debug REPO", String, "Only run on this repo for fast debugging") { |repo| options[:debug] = repo }
34
35
  parser.on("--without TYPES", String, "Do not run for bundler/npm dependencies (comma separated)") { |without| options[:without] = without.split(",") }
35
36
  parser.on("-w", "--whitelist=LICENSES", String, "Comma separated list of licenses") { |whitelist| options[:whitelist] = whitelist.split(",") }
36
37
  parser.on("-h", "--help", "Show this.") { puts parser; exit }
@@ -7,9 +7,11 @@ module OrganizationLicenseAudit
7
7
  BUNDLE_PATH = "vendor/bundle"
8
8
  RESULT_LINE = /(^[a-z_\d\.-]+), ([^,]+), (.+)/i
9
9
  APPROVAL_HEADING = "Dependencies that need approval"
10
- NPM_PACKAGE_FILE = "package.json"
11
- BOWER_PACKAGE_FILE = "bower.json"
12
- BUNDLER_PACKAGE_FILE = "Gemfile"
10
+ PACKAGE_FILES = {
11
+ :bundler => "Gemfile",
12
+ :npm => "package.json",
13
+ :bower => "bower.json"
14
+ }
13
15
 
14
16
  class << self
15
17
  def run(options)
@@ -77,13 +79,16 @@ module OrganizationLicenseAudit
77
79
 
78
80
  def download_file(repo, file)
79
81
  return unless content = repo.content(file)
82
+ FileUtils.mkdir_p(File.dirname(file))
80
83
  File.write(file, content)
81
84
  end
82
85
 
83
86
  def find_bad(options)
84
87
  Dir.mktmpdir do |bundle_cache_dir|
85
- OrganizationAudit.all(options).map do |repo|
86
- next if options[:ignore_gems] and repo.gem?
88
+ repos = OrganizationAudit.all(options)
89
+ repos.select! { |r| r.name == options[:debug] } if options[:debug]
90
+ repos.map do |repo|
91
+ next if options[:ignore_gems] && repo.gem?
87
92
  success, output = audit_repo(repo, bundle_cache_dir, options)
88
93
  $stderr.puts ""
89
94
  [repo, output] unless success
@@ -94,10 +99,14 @@ module OrganizationLicenseAudit
94
99
  def audit_repo(repo, bundle_cache_dir, options)
95
100
  $stderr.puts repo.name
96
101
  in_temp_dir do
97
- raise "Clone failed" unless sh("git clone #{repo.clone_url} --depth 1 --quiet").first
98
- Dir.chdir repo.name do
99
- audit_project(bundle_cache_dir, options)
102
+ if repo.gem?
103
+ # download everything since gemspecs can require stuff (also gems are mostly small...)
104
+ raise "Clone failed" unless sh("git clone #{repo.clone_url} --depth 1 --quiet .").first
105
+ else
106
+ # download only the files we need to save time on giant projects
107
+ needed_files(repo, options).each { |path| download_file(repo, path) }
100
108
  end
109
+ audit_project(bundle_cache_dir, options)
101
110
  end
102
111
  rescue Exception => e
103
112
  raise if e.is_a?(Interrupt) # user interrupted
@@ -105,6 +114,15 @@ module OrganizationLicenseAudit
105
114
  true
106
115
  end
107
116
 
117
+ def needed_files(repo, options)
118
+ list = repo.file_list
119
+ list += repo.file_list("config") if repo.directory?("config")
120
+ supported = ["config/license_finder.yml"]
121
+ supported << "Gemfile.lock" if wanted?(:bundler, options)
122
+ supported.concat PACKAGE_FILES.map { |t,f| f if wanted?(t, options) }.compact
123
+ supported & list
124
+ end
125
+
108
126
  def audit_project(bundle_cache_dir, options)
109
127
  with_clean_env do
110
128
  bundled = prepare_bundler bundle_cache_dir, options
@@ -125,7 +143,7 @@ module OrganizationLicenseAudit
125
143
  end
126
144
 
127
145
  def prepare_bundler(bundle_cache_dir, options)
128
- with_or_without "bundler", BUNDLER_PACKAGE_FILE, options do
146
+ with_or_without :bundler, options do
129
147
  use_cache_dir_to_bundle(bundle_cache_dir)
130
148
  raise "Failed to bundle" unless sh("bundle --path #{BUNDLE_PATH} --quiet").first
131
149
  true
@@ -133,13 +151,13 @@ module OrganizationLicenseAudit
133
151
  end
134
152
 
135
153
  def prepare_npm(options)
136
- with_or_without "npm", NPM_PACKAGE_FILE, options do
154
+ with_or_without :npm, options do
137
155
  sh "npm install --quiet"
138
156
  end
139
157
  end
140
158
 
141
159
  def prepare_bower(options)
142
- with_or_without "bower", BOWER_PACKAGE_FILE, options
160
+ with_or_without :bower, options
143
161
  end
144
162
 
145
163
  def use_cache_dir_to_bundle(cache_dir)
@@ -189,12 +207,17 @@ module OrganizationLicenseAudit
189
207
  [$?.success?, output]
190
208
  end
191
209
 
192
- def with_or_without(thing, file, options)
210
+ def wanted?(thing, options)
211
+ not (options[:without] || []).include?(thing.to_s)
212
+ end
213
+
214
+ def with_or_without(thing, options)
215
+ file = PACKAGE_FILES.fetch(thing)
193
216
  return unless File.exist?(file)
194
- if (options[:without] || []).include?(thing)
195
- File.unlink(file)
196
- else
217
+ if wanted?(thing, options)
197
218
  yield if block_given?
219
+ else
220
+ File.unlink(file)
198
221
  end
199
222
  end
200
223
  end
@@ -1,3 +1,3 @@
1
1
  module OrganizationLicenseAudit
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organization_license_audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -29,7 +29,7 @@ cert_chain:
29
29
  y0kCSWmK6D+x/SbfS6r7Ke07MRqziJdB9GuE1+0cIRuFh8EQ+LN6HXCKM5pon/GU
30
30
  ycwMXfl0
31
31
  -----END CERTIFICATE-----
32
- date: 2014-01-08 00:00:00.000000000 Z
32
+ date: 2014-01-21 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: organization_audit
metadata.gz.sig CHANGED
Binary file