organization_gem_dependencies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb5e5a02cbf5ed813e8420830752b6f2f1341f61
4
+ data.tar.gz: ee3ad55b7be9f1d8f2db3263e20c8cb37e4768a0
5
+ SHA512:
6
+ metadata.gz: 71ab9c48f521b57b7fa7e2c1c0803126d613b99c641999aeb8951dcef3aa72b369b2a550f216bcfa931088dcd266e97aae98192e5458e49e894806d2d3dfe9a0
7
+ data.tar.gz: b97283bde770583c62b9dec9a306a02c62b9f6baa241b72b152c7e35de95adbc2314ec93486f84c9b020630bffb8511609551944bf53e91fc559d79b833a978b
data/CHANGES.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ ## Unreleased
4
+
5
+ **Added**
6
+
7
+ * Provide initial version of the `organization_gem_dependencies` command line
8
+ tool.
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2018, AppFolio, Inc.
2
+ Copyright (c) 2018, Bryce Boe
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # organization_gem_dependencies
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'organization_gem_dependencies'
5
+ exit OrganizationGemDependencies::Cli.new.run
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'organization_gem_dependencies/cli'
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'io/console'
5
+ require 'json'
6
+ require 'optparse'
7
+
8
+ require 'octokit'
9
+
10
+ module OrganizationGemDependencies
11
+ # Define the command line interface.
12
+ class Cli
13
+ SEARCH_TERM = 'org:appfolio filename:Gemfile.lock'
14
+
15
+ def run
16
+ parse_options
17
+
18
+ access_token = ENV['GITHUB_ACCESS_TOKEN'] || \
19
+ STDIN.getpass('GitHub Personal Access Token: ')
20
+ github = Octokit::Client.new(access_token: access_token)
21
+
22
+ gems = {}
23
+ gemfiles(github) do |gemfile|
24
+ STDERR.puts "Processing #{gemfile.repository.name}/#{gemfile.path}"
25
+ content = nil
26
+ sleep_time = 0
27
+ while content.nil?
28
+ begin
29
+ content = Base64.decode64(github.get(gemfile.url).content)
30
+ rescue StandardError
31
+ sleep_time += 1
32
+ STDERR.puts "Sleeping #{sleep_time} seconds"
33
+ sleep(sleep_time)
34
+ end
35
+ end
36
+ merge!(gems, process_gemfile(
37
+ Bundler::LockfileParser.new(content),
38
+ "#{gemfile.repository.name}/#{gemfile.path}"
39
+ ))
40
+ end
41
+ output gems
42
+
43
+ 0
44
+ end
45
+
46
+ private
47
+
48
+ def gemfiles(github)
49
+ github.search_code(SEARCH_TERM, per_page: 1000)
50
+ last_response = github.last_response
51
+
52
+ matches = last_response.data.items
53
+ until last_response.rels[:next].nil?
54
+ last_response = last_response.rels[:next].get
55
+ matches.concat last_response.data.items
56
+ end
57
+
58
+ matches.sort_by(&:html_url).each do |match|
59
+ yield match
60
+ end
61
+ end
62
+
63
+ def merge!(base, additions)
64
+ additions.each do |gem, versions|
65
+ if base.include? gem
66
+ base_versions = base[gem]
67
+ versions.each do |version, projects|
68
+ if base_versions.include? version
69
+ base_versions[version].concat(projects)
70
+ else
71
+ base_versions[version] = projects
72
+ end
73
+ end
74
+ else
75
+ base[gem] = versions
76
+ end
77
+ end
78
+ end
79
+
80
+ def output(gems)
81
+ sorted_gems = {}
82
+ gems.sort.each do |gem, versions|
83
+ sorted_gems[gem] = {}
84
+ versions.sort.each do |version, projects|
85
+ sorted_gems[gem][version] = projects.sort
86
+ end
87
+ end
88
+ puts JSON.pretty_generate(sorted_gems)
89
+ end
90
+
91
+ def parse_options
92
+ @options = { direct: false }
93
+ OptionParser.new do |config|
94
+ config.banner = <<~USAGE
95
+ Usage: organization_gem_dependencies [options]
96
+ USAGE
97
+ config.on('-d', '--direct',
98
+ 'Consider only direct dependencies.') do |direct|
99
+ @options[:direct] = direct
100
+ end
101
+ config.version = OrganizationGemDependencies::VERSION
102
+ end.parse!
103
+ end
104
+
105
+ def process_gemfile(gemfile, project)
106
+ dependencies = gemfile.dependencies.map { |dependency, _, _| dependency }
107
+ gems = {}
108
+
109
+ gemfile.specs.each do |spec|
110
+ next if @options[:direct] && !dependencies.include?(spec.name)
111
+ gems[spec.name] = {}
112
+ gems[spec.name][spec.version] = [project]
113
+ end
114
+ gems
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrganizationGemDependencies
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: organization_gem_dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryce Boe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ description: |
56
+ organization_gem_dependencies is a command line tool to allow one to
57
+ discover ruby gem dependencies for all ruby projects across a github
58
+ organization..
59
+ email: bryce.boe@appfolio.com
60
+ executables:
61
+ - organization_gem_dependencies
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - CHANGES.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - bin/organization_gem_dependencies
69
+ - lib/organization_gem_dependencies.rb
70
+ - lib/organization_gem_dependencies/cli.rb
71
+ - lib/organization_gem_dependencies/version.rb
72
+ homepage: https://github.com/appfolio/organization_gem_dependencies
73
+ licenses:
74
+ - BSD-2-Clause
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.6.14
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Discover all ruby gem depedencies for a github organization.
96
+ test_files: []