gripst 0.0.1

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: 9917e6f56f54f29e862a085c51633ebe25deaeb8
4
+ data.tar.gz: e5f2c3a7520a9a29bddbdf1b0eabd912d65cf90c
5
+ SHA512:
6
+ metadata.gz: 6e2a4e5a21139341944c901cbe0cc638b046f1d2584efe9509f4df5d07d3cfa1fab769ab618cb77f04a15802a7c72b83fb30c60f885ddd7fd090385c32d36f11
7
+ data.tar.gz: 961b335ca0171da8c53fdcaf6220d9155c4382fc92b21eec87098ac8aea5add3c134592115bb78c1b6c36c95deb67eef4499f93f578a0679f6f78bbbcfbe068e
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ .ruby-version
2
+ .ruby-gemset
3
+ .rpsec
4
+ *.gem
5
+ *.rbc
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Max Beizer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ gripst
2
+ ======
3
+ Is GitHub's Gist search not enough? Brute-force grep all your gists.
4
+
5
+ ## Installation
6
+
7
+ [Create an access token for GitHub](https://help.github.com/articles/creating-an-access-token-for-command-line-use/)
8
+ ```
9
+ $ gem install gripst
10
+ $ export GITHUB_USER_ACCESS_TOKEN=your_access_token_from_above
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ gripst "(stuff|things)"
17
+ ```
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
26
+
27
+
28
+ ## Tests
29
+
30
+ ```
31
+ git clone git@github.com:maxbeizer/gripst.git
32
+ rake install
33
+ rake spec
34
+ ```
35
+
36
+ ## Credits
37
+
38
+ This Ruby script was originally written by [James White](https://github.com/jameswhite/).
39
+
40
+ ## License
41
+
42
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'bundler/version'
4
+
5
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
6
+
7
+ task :build do
8
+ system 'gem build gripst.gemspec'
9
+ end
10
+
11
+ task :release => :build do
12
+ system "gem push gripst-#{Gripst::VERSION}"
13
+ end
data/bin/gripst ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'gripst'
8
+
9
+ begin
10
+ gripst = Gripst::Gripst.new
11
+ $stderr.puts "please set GITHUB_USER_ACCESS_TOKEN in env" unless gripst.initialized?
12
+ puts 'gripsting'
13
+ gripst.all_gist_ids.each { |id| gripst.run(ARGV[0], id) }
14
+ rescue SystemExit, Interrupt
15
+ $stderr.puts 'Bye Bye'
16
+ end
data/gripst.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gripst/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gripst'
8
+ spec.version = Gripst::VERSION
9
+ spec.authors = ['Max Beizer']
10
+ spec.email = ['max.beizer@gmail.com']
11
+ spec.description = %q{Brute-force grep your gists}
12
+ spec.summary = %q{Brute-force grep your gists for when the search tool is not enough}
13
+ spec.homepage = 'https://github.com/maxbeizer/gripst'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.0'
22
+
23
+ spec.add_runtime_dependency 'octokit', '~> 3.3', '>= 3.3.1'
24
+ spec.add_runtime_dependency 'git', '~> 1.2', '>= 1.2.8'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rspec', '~> 0'
28
+ spec.add_development_dependency 'rake', '~> 0'
29
+ spec.add_development_dependency 'pry', '~> 0'
30
+ end
@@ -0,0 +1,82 @@
1
+ require 'find'
2
+ require 'tmpdir'
3
+ require 'octokit'
4
+ require 'git'
5
+ require_relative 'string'
6
+ require_relative 'version'
7
+
8
+ module Gripst
9
+ class Gripst
10
+ attr_reader :tmpdir, :auth_token
11
+ ParamObj = Struct.new(:id, :path)
12
+
13
+ def initialize
14
+ @auth_token = ENV['GITHUB_USER_ACCESS_TOKEN']
15
+ @tmpdir = Dir.mktmpdir
16
+ end
17
+
18
+ def initialized?
19
+ !!auth_token
20
+ end
21
+
22
+ def all_gist_ids
23
+ client.gists.map(&:id)
24
+ end
25
+
26
+ def client
27
+ @client ||= create_client
28
+ end
29
+
30
+ def clone(id)
31
+ Git.clone "https://#{auth_token}@gist.github.com/#{id}.git", id, :path => "#{tmpdir}"
32
+ true
33
+ rescue => e # TODO figure out what error this is could be and not rescue bare exception
34
+ $stderr.puts "ERROR: git fell down on #{id}"
35
+ $stderr.puts "ERROR: #{e}"
36
+ false
37
+ end
38
+
39
+ def run(regex, id)
40
+ Find.find("#{tmpdir}/#{id}") do |path|
41
+ param_obj = ParamObj.new(id, path)
42
+ return Find.prune if git_dir? param_obj
43
+ loop_through_lines_of_a_gist(regex, param_obj) if File.file? path
44
+ end if clone id
45
+ end
46
+
47
+ private
48
+
49
+ def create_client
50
+ client = Octokit::Client.new :access_token => "#{auth_token}"
51
+ client.user.login
52
+ client
53
+ end
54
+
55
+ def loop_through_lines_of_a_gist(regex, param_obj)
56
+ File.new(param_obj.path).each do |line|
57
+ begin
58
+ display_match(param_obj, line) if /#{regex}/.match line
59
+ rescue ArgumentError
60
+ $stderr.puts "Skipping... #{output_info_string(param_obj)} #{$!}"
61
+ sleep 300
62
+ end
63
+ end
64
+ end
65
+
66
+ def display_match(param_obj, line)
67
+ puts "#{output_info_string(param_obj)} #{line}"
68
+ end
69
+
70
+ def git_dir?(obj)
71
+ obj.path == "#{tmpdir}/#{obj.id}/.git"
72
+ end
73
+
74
+ def output_info_string(param_obj)
75
+ "#{param_obj.id.pink} (#{extract_gistfile_name(param_obj.path)})"
76
+ end
77
+
78
+ def extract_gistfile_name(path)
79
+ path.split('/')[-1].yellow
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,21 @@
1
+ class String
2
+ def colorize(color_code)
3
+ "\e[#{color_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def red
7
+ colorize(31)
8
+ end
9
+
10
+ def green
11
+ colorize(32)
12
+ end
13
+
14
+ def yellow
15
+ colorize(33)
16
+ end
17
+
18
+ def pink
19
+ colorize(35)
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Gripst
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gripst.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'gripst/gripst'
2
+ require 'gripst/string'
3
+ require 'gripst/version'
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/gripst'
3
+ require 'pry'
4
+
5
+ RSpec.describe Gripst do
6
+ context 'without a user_access_token' do
7
+ it '#initialized? returns false' do
8
+ stub_const('ENV', { 'GITHUB_USER_ACCESS_TOKEN' => nil })
9
+ gripst_without_token = Gripst::Gripst.new
10
+ expect(gripst_without_token.initialized?).to be false
11
+ end
12
+ end
13
+
14
+ context 'with a user_access_token' do
15
+ let(:gripst_with_token) { Gripst::Gripst.new }
16
+
17
+ before :each do
18
+ stub_const('ENV', { 'GITHUB_USER_ACCESS_TOKEN' => 'asdf' })
19
+ end
20
+
21
+ it '#initialized? returns true' do
22
+ expect(gripst_with_token.initialized?).to be true
23
+ end
24
+
25
+ describe "#all_gist_ids" do
26
+ it "returns an array of ids of all gists for a given user" do
27
+ Gist = Struct.new(:id)
28
+ allow(gripst_with_token).to receive(:client).and_return(double('client'))
29
+ allow(gripst_with_token.client).to receive(:gists).and_return([Gist.new(123), Gist.new(234), Gist.new(345)])
30
+ expect(gripst_with_token.all_gist_ids).to include 123, 234, 345
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#clone' do
36
+ let(:gripst) { Gripst::Gripst.new }
37
+
38
+ before :each do
39
+ stub_const('ENV', { 'GITHUB_USER_ACCESS_TOKEN' => 'asdf' })
40
+ end
41
+
42
+ context 'with no error' do
43
+ it 'returns true' do
44
+ allow(Git).to receive(:clone).and_return true
45
+ expect(gripst.clone('123')).to eq true
46
+ end
47
+ end
48
+
49
+ context 'with error' do
50
+ it 'returns false' do
51
+ allow(Git).to receive(:clone).and_raise StandardError
52
+ expect(gripst.clone('123')).to eq false
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#run' do
58
+ let(:gripst) { Gripst::Gripst.new }
59
+
60
+ before :each do
61
+ stub_const('ENV', { 'GITHUB_USER_ACCESS_TOKEN' => 'asdf' })
62
+ end
63
+
64
+ context 'when clone fails' do
65
+ it 'returns silently' do
66
+ allow(gripst).to receive(:clone).and_return false
67
+ expect(gripst).to receive(:loop_through_lines_of_a_gist).exactly(0).times
68
+ gripst.run('asdf', 'asdf')
69
+ end
70
+ end
71
+
72
+ context 'when clone succeeds' do
73
+ it 'returns with Find.prune if the path is a git dir' do
74
+ allow(gripst).to receive(:clone).and_return true
75
+ path = '.git'
76
+ allow(Find).to receive(:find).and_yield path
77
+ allow(gripst).to receive(:git_dir?).and_return true
78
+ expect(Find).to receive(:prune)
79
+ gripst.run('asdf', 'asdf')
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.configure do |config|
2
+ config.mock_with :rspec do |mocks|
3
+ mocks.verify_partial_doubles = true
4
+ end
5
+
6
+ config.filter_run :focus
7
+ config.run_all_when_everything_filtered = true
8
+
9
+ config.warnings = true
10
+
11
+ if config.files_to_run.one?
12
+ config.default_formatter = 'doc'
13
+ end
14
+
15
+ config.order = :random
16
+
17
+ Kernel.srand config.seed
18
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gripst
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Beizer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.3'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: git
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 1.2.8
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '1.2'
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.2.8
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.3'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '1.3'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ description: Brute-force grep your gists
110
+ email:
111
+ - max.beizer@gmail.com
112
+ executables:
113
+ - gripst
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/gripst
124
+ - gripst.gemspec
125
+ - lib/gripst.rb
126
+ - lib/gripst/gripst.rb
127
+ - lib/gripst/string.rb
128
+ - lib/gripst/version.rb
129
+ - spec/gripst_spec.rb
130
+ - spec/spec_helper.rb
131
+ - tasks/rspec.rake
132
+ homepage: https://github.com/maxbeizer/gripst
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Brute-force grep your gists for when the search tool is not enough
156
+ test_files:
157
+ - spec/gripst_spec.rb
158
+ - spec/spec_helper.rb