cerebro 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 300c56ecf7b5ccc38151ec5383dcf467a7f7c260
4
+ data.tar.gz: 2269ee2bb942a2cedcd6bad1d5db275c5fb2eb15
5
+ SHA512:
6
+ metadata.gz: fcb68614992bba5d6c69343878a36bba36bb01ab06a1129fbbc3c0c2f3474f1bb7d566d3f0ea0f6b4f2a0cb23dabc1450be99c6a2a7b1541c09fff258dd8fe95
7
+ data.tar.gz: 273930a5f25475a54dd43de1e219cb3f00579ac4ed700630620fc81e2d882016f88d646df1867cedf70b83817257377574ee3d433f9efd5caf02d6cd109963b5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cerebro.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 cortelyou
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.
@@ -0,0 +1,91 @@
1
+ # Cerebro
2
+
3
+ Search through github forks of a repo for search terms!
4
+ Great for maintainers that want to know what downstream forks are doing.
5
+
6
+ ## Installation
7
+
8
+ Install it with:
9
+
10
+ ```bash
11
+ $ gem install cerebro
12
+ ```
13
+
14
+ ## Details
15
+
16
+ Cerebro currently works by using the Github API to identify all the forks of the
17
+ repo if interest. It then will clone all the repos down into a specifically named
18
+ repo under the `$HOME/.cerebro` directory. It will then use grep searching to
19
+ determine if your search term is present in each/which of the forks.
20
+
21
+ ## Usage
22
+
23
+ - Cloning down of the repos will be shallow by default. If you want deep clones, use `cerebro search --deep`.
24
+
25
+ ####Searching:
26
+
27
+ - To clean up all repos that Cerebro has cloned onto your local file system:
28
+
29
+ ```bash
30
+ $ GITHUB_TOKEN=<github_api_token> cerebro search <repo_owner> <repo_name> <search_term>
31
+ ```
32
+
33
+ For example, if I'm looking to determine how many forks of the [Cloud Foundry python buildpack](https://github.com/cloudfoundry/python-buildpack)
34
+ have been forked to add or use `graphviz`, I might run:
35
+
36
+ ```
37
+ GITHUB_TOKEN=<github_token> cerebro search cloudfoundry python-buildpack graphviz
38
+ Found 85 forks of cloudfoundry/python-buildpack
39
+ All forks will be stored in /Users/user/.cerebro/python-buildpack-forks
40
+ Cloning or updating all local fork repos...
41
+ <...>
42
+ Searching through these forks now...
43
+
44
+ ----------------Search Results---------------------
45
+ Found graphviz in kdunn-pivotal-python-buildpack
46
+ Found graphviz in ssssam-python-buildpack
47
+
48
+ Found "graphviz" in 2 forks out of total 85 forks of cloudfoundry/python-buildpack
49
+
50
+ Clones of forked repos are located in /Users/user/.cerebro/python-buildpack-forks
51
+ ```
52
+
53
+ ####Cleaning Up:
54
+
55
+ - To clean up all repos that Cerebro has cloned onto your local file system:
56
+
57
+ ```bash
58
+ $ cerebro clean --all
59
+ ```
60
+
61
+ - To clean up only the repos that are forks for a specific repo:
62
+
63
+ ```bash
64
+ $ cerebro clean <repo-name>
65
+ ```
66
+
67
+ ## Dependencies
68
+
69
+ - This gem relies on `git` for cloning down forks of repos.
70
+ - This gem currently relies on $HOME being set on your machine for figuring out where to store cloned repos.
71
+ - This gem's searching for forks relies on the user providing a valid Github API token via
72
+ `GITHUB_TOKEN` env vars. This token is not persisted or stored at all.
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RochesterinNYC/cerebro or in https://cloudfoundry.slack.com/messages/buildpacks/.
77
+
78
+ ## Later Work
79
+
80
+ - Make dirnames specific to owner and repo name instead of just repo name
81
+ - Command for cleaning up stored repos
82
+ - Specify where to store cloned repos
83
+ - Option for auto-clean up afterwards
84
+ - Better UX for specifying github auth
85
+ - Remove dependency on octokit
86
+ - Threading for parallel cloning
87
+ - Search caching?
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cerebro"
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cerebro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cerebro"
8
+ spec.version = Cerebro::VERSION
9
+ spec.authors = ["James Wen"]
10
+ spec.email = ["jrw2175@columbia.edu"]
11
+
12
+ spec.summary = "A tool for searching through forks of github repos for information."
13
+ spec.description = "Description"
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = ["cerebro"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'claide', '>= 1.0.0', '< 2.0'
23
+ spec.add_runtime_dependency 'octokit', '>= 4.0.0', '< 5.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'cerebro'
6
+
7
+ Cerebro::Command.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require "cerebro/version"
2
+
3
+ module Cerebro
4
+ autoload :Command, 'cerebro/command'
5
+ autoload :Searcher, 'cerebro/searcher'
6
+
7
+ def self.storage_directory
8
+ home_dir = ENV.fetch('HOME', nil)
9
+ home_dir.empty? ? nil : File.join(home_dir, ".cerebro")
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require 'claide'
2
+
3
+ module Cerebro
4
+ class Command < CLAide::Command
5
+ require 'cerebro/command/search'
6
+ require 'cerebro/command/clean'
7
+
8
+ def self.run(argv)
9
+ super(argv)
10
+ end
11
+
12
+ def validate!
13
+ super
14
+
15
+ if !Cerebro.storage_directory
16
+ puts <<-HELP
17
+ You don't have $HOME set.
18
+ Cerebro currently relies on storing cloned fork repos in your home directory.
19
+ HELP
20
+ exit 1
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,48 @@
1
+ require 'fileutils'
2
+
3
+ module Cerebro
4
+ class Command
5
+ class Clean < Command
6
+ self.summary = 'Clean locally stored github repo forks'
7
+ self.description = <<-DESC
8
+ Clean up the repos that you've cloned down via searches
9
+ DESC
10
+
11
+ def initialize(argv)
12
+ @clean_specs = argv.arguments
13
+ @repo = argv.shift_argument
14
+ @clean_all = argv.flag?('all')
15
+ super
16
+ end
17
+
18
+ def self.options
19
+ [
20
+ ['--all', 'Clean all locally cloned repos used by Cerebro'],
21
+ ].concat(super).reject { |(name, _)| name == '--no-all' }
22
+ end
23
+
24
+ def validate!
25
+ super
26
+
27
+ if !@clean_all && @clean_specs.length != 1
28
+ help = <<-HELP
29
+ Usage: cerebro clean <repo_name>
30
+ HELP
31
+ help! help
32
+ end
33
+ end
34
+
35
+ def run
36
+ if @clean_all
37
+ FileUtils.rm_rf("#{Cerebro.storage_directory}/.")
38
+ puts "Cleaned up all local clones created by Cerebro"
39
+ else
40
+ Dir.chdir(Cerebro.storage_directory) do
41
+ FileUtils.rm_rf("#{@repo}-forks")
42
+ end
43
+ puts "Cleaned up all local clones of #{@repo} forks created by Cerebro"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,94 @@
1
+ require 'octokit'
2
+ require 'fileutils'
3
+ require 'cerebro/searcher'
4
+
5
+ module Cerebro
6
+ class Command
7
+ class Search < Command
8
+ self.summary = 'Search through github repo forks'
9
+ self.description = <<-DESC
10
+ Search through forks of the specified repo for a search term
11
+ DESC
12
+
13
+ def initialize(argv)
14
+ @search_specs = argv.arguments
15
+ @owner = argv.shift_argument
16
+ @repo = argv.shift_argument
17
+ @search_term = argv.shift_argument
18
+ @deep_clone = argv.flag?('deep')
19
+ @github_token = ENV.fetch('GITHUB_TOKEN', nil)
20
+ super
21
+ end
22
+
23
+ def self.options
24
+ [
25
+ ['--deep', 'Use full git cloning instead of shallow clones'],
26
+ ].concat(super).reject { |(name, _)| name == '--no-deep' }
27
+ end
28
+
29
+ def validate!
30
+ super
31
+
32
+ if @search_specs.length != 3
33
+ help = <<-HELP
34
+ Usage: GITHUB_TOKEN=<github_token> cerebro search <repo_owner> <repo_name> <search_term>
35
+ HELP
36
+ help! help
37
+ end
38
+ if !@github_token
39
+ puts <<-HELP
40
+ Please specify or pass in GITHUB_TOKEN as an environment variable.
41
+ Usage: GITHUB_TOKEN=<github_token> cerebro search <repo_owner> <repo_name> <search_term>
42
+ HELP
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ def run
48
+ # Setup Github API
49
+ Octokit.auto_paginate = true
50
+ Octokit.configure do |c|
51
+ c.access_token = @github_token
52
+ end
53
+
54
+ full_repo_name = "#{@owner}/#{@repo}"
55
+ forks_with_term = []
56
+
57
+ # Get all forks
58
+ forks = Octokit.forks(full_repo_name)
59
+ forks_directory = File.join(Cerebro.storage_directory, "#{@repo}-forks")
60
+ FileUtils.mkdir_p forks_directory
61
+
62
+ Dir.chdir(forks_directory) do
63
+ puts "Found #{forks.count} forks of #{full_repo_name}"
64
+ puts "All forks will be stored in #{forks_directory}"
65
+ puts "Cloning or updating all local fork repos..."
66
+ forks.each do |git_fork|
67
+ forked_dir = File.join(forks_directory, "#{git_fork.owner.login}-#{git_fork.name}")
68
+ if Dir.exists?(forked_dir)
69
+ Dir.chdir(forked_dir) do
70
+ `git pull -r`
71
+ end
72
+ else
73
+ shallow = @deep_clone ? "" : "--depth 1"
74
+ `git clone #{shallow} #{git_fork.ssh_url} #{forked_dir}`
75
+ end
76
+ end
77
+ puts "Searching through these forks now..."
78
+ forks_with_term = Searcher.find(forks_directory, @search_term)
79
+ end
80
+ puts <<-RESULTS
81
+
82
+ ----------------Search Results---------------------
83
+ RESULTS
84
+ forks_with_term.each do |repo_identifier|
85
+ puts "Found #{@search_term} in #{repo_identifier}"
86
+ end
87
+ puts
88
+ puts "Found \"#{@search_term}\" in #{forks_with_term.count} forks out of total #{forks.count} forks of #{full_repo_name}"
89
+ puts
90
+ puts "Clones of forked repos are located in #{forks_directory}"
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,30 @@
1
+ module Cerebro
2
+ class Searcher
3
+ attr_accessor :forks_dir
4
+ attr_accessor :search_term
5
+
6
+ def self.find(forks_dir, search_term)
7
+ new(forks_dir, search_term).matched_forks
8
+ end
9
+
10
+ def initialize(forks_dir, search_term)
11
+ @forks_dir = forks_dir
12
+ @search_term = search_term
13
+ end
14
+
15
+ def matched_forks
16
+ forks_with_term = []
17
+ Dir.chdir(@forks_dir) do
18
+ Dir["*"].each do |fork_dir|
19
+ forks_with_term << fork_dir if search_in_fork(fork_dir)
20
+ end
21
+ end
22
+ forks_with_term
23
+ end
24
+
25
+ def search_in_fork(fork_dir)
26
+ `grep -IR '#{@search_term}' #{fork_dir}`
27
+ $?.success?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Cerebro
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cerebro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Wen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: claide
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: octokit
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 4.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 4.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.12'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.12'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ description: Description
96
+ email:
97
+ - jrw2175@columbia.edu
98
+ executables:
99
+ - cerebro
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - cerebro.gemspec
113
+ - exe/cerebro
114
+ - lib/cerebro.rb
115
+ - lib/cerebro/command.rb
116
+ - lib/cerebro/command/clean.rb
117
+ - lib/cerebro/command/search.rb
118
+ - lib/cerebro/searcher.rb
119
+ - lib/cerebro/version.rb
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A tool for searching through forks of github repos for information.
144
+ test_files: []