pry-github 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ tags
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-github.gemspec
4
+ gemspec
5
+
6
+ # until a new gem is published that works with the latest pry
7
+ group :devlopment do
8
+ gem 'pry-developer_tools', :git => 'http://github.com/pry/pry-developer_tools'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Albert
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
+ # pry-github
2
+
3
+ pry-github teaches Pry about GitHub. It lets you view your methods in GitHub whether. You can also open the GitHub blame view, which I think is quite nice.
4
+
5
+ A bunch of code was taken from [pry-git](https://github.com/pry/pry-git).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'pry-github'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pry-github
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ $ pry
25
+ [1] pry(main)> gh show Foo#bar
26
+ # opens lib/foo.rb on GitHub
27
+
28
+ [2] pry(main)> gh blame Foo#bar
29
+ # opens the blame page for lib/foo.rb on GitHub
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
39
+
40
+ ## License
41
+
42
+ pry-github is licensed under the MIT License. See LICENSE for more info. (c) 2012 David Albert.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/pry-github.rb ADDED
@@ -0,0 +1,125 @@
1
+ require "pry-github/version"
2
+
3
+ require 'pry'
4
+ require 'grit'
5
+ require 'launchy'
6
+
7
+ require 'uri'
8
+ require 'net/http'
9
+
10
+ module PryGithub
11
+ module GithubHelpers
12
+ def get_file_from_commit(path)
13
+ git_root = find_git_root(File.dirname(path))
14
+ repo = Grit::Repo.new(git_root)
15
+ head = repo.commits.first
16
+ tree_names = relative_path(git_root, path).split("/")
17
+ start_tree = head.tree
18
+ blob_name = tree_names.last
19
+ tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |t| t.basename == v } }
20
+ blob = tree.blobs.find { |v| v.basename == blob_name }
21
+ blob.data
22
+ end
23
+
24
+ def method_code_from_head(meth)
25
+ code = get_file_from_commit(meth.source_location.first)
26
+ search_line = meth.source.lines.first.strip
27
+ _, start_line = code.lines.to_a.each_with_index.find { |v, i| v.strip == search_line }
28
+
29
+ raise "Can't find #{args[0]} in the repo. Perhaps it hasn't been committed yet." unless start_line
30
+
31
+ start_line
32
+ [Pry.new(:input => StringIO.new(code.lines.to_a[start_line..-1].join)).r(target), start_line + 1]
33
+ end
34
+
35
+ def relative_path(root, path)
36
+ path =~ /#{root}\/(.*)/
37
+ $1
38
+ end
39
+
40
+ def find_git_root(dir)
41
+ git_root = "."
42
+ Dir.chdir dir do
43
+ git_root = `git rev-parse --show-toplevel`.chomp
44
+ end
45
+
46
+ raise "No associated git repository found!" if git_root =~ /fatal:/
47
+ git_root
48
+ end
49
+
50
+ def find_github_remote(repo)
51
+ remote_urls = repo.remotes.map { |remote| repo.config["remote.#{remote.name.split('/')[0]}.url"] }
52
+ gh_url = remote_urls.find { |url| url =~ /github\.com/ }
53
+
54
+ raise "No GitHub remote found!" unless gh_url
55
+ gh_url
56
+ end
57
+
58
+ def get_github_url(meth, url_type="blob")
59
+ file_name = meth.source_location.first
60
+ code, start_line = method_code_from_head(meth)
61
+
62
+ git_root = find_git_root(File.dirname(file_name))
63
+
64
+ repo = Grit::Repo.new(git_root)
65
+ gh_url = find_github_remote(repo)
66
+
67
+ # ssh urls can't be parsed with URI.parse
68
+ if gh_url[0..3] == "git@"
69
+ gh_url = gh_url.gsub(":", "/")
70
+ gh_url[0..3] = "https://"
71
+ end
72
+
73
+ uri = URI.parse(gh_url)
74
+ https_url = "https://#{uri.host}#{uri.path}".gsub(".git", "")
75
+ https_url += "/#{url_type}/#{repo.commit("HEAD").sha}"
76
+ https_url += file_name.gsub(repo.working_dir, '')
77
+ https_url += "#L#{start_line}-L#{start_line + code.lines.to_a.size}"
78
+
79
+ uri = URI.parse(https_url)
80
+ response = nil
81
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
82
+ response = http.head(uri.path)
83
+ end
84
+
85
+ if response.code == "404"
86
+ https_url = https_url.gsub(repo.commit("HEAD").sha, repo.head.name)
87
+ end
88
+
89
+ https_url
90
+ end
91
+ end
92
+
93
+ Commands = Pry::CommandSet.new do
94
+ create_command "gh show", "Show GitHub page for a method" do
95
+ include GithubHelpers
96
+
97
+ def options(opt)
98
+ method_options(opt)
99
+ end
100
+
101
+ def process
102
+ meth = method_object
103
+ url = get_github_url(meth)
104
+ Launchy.open(url)
105
+ end
106
+ end
107
+
108
+ create_command "gh blame", "Show GitHub blame page for a method" do
109
+ include GithubHelpers
110
+
111
+ def options(opt)
112
+ method_options(opt)
113
+ end
114
+
115
+ def process
116
+ meth = method_object
117
+ url = get_github_url(meth, "blame")
118
+ Launchy.open(url)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+
125
+ Pry.commands.import PryGithub::Commands
@@ -0,0 +1,3 @@
1
+ module PryGithub
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pry-github/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["David Albert"]
6
+ gem.email = ["davidbalbert@gmail.com"]
7
+ gem.description = %q{Make pry play nice with GitHub}
8
+ gem.summary = %q{Make pry play nice with GitHub}
9
+ gem.homepage = "https://github.com/davidbalbert/pry-github"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "pry-github"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = PryGithub::VERSION
17
+
18
+ gem.add_dependency('pry')
19
+ gem.add_dependency('grit', '~> 2.5.0')
20
+ gem.add_dependency('launchy', '~> 2.1.0')
21
+
22
+ gem.add_development_dependency('pry-debundle')
23
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Albert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: grit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: launchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry-debundle
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Make pry play nice with GitHub
79
+ email:
80
+ - davidbalbert@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - lib/pry-github.rb
91
+ - lib/pry-github/version.rb
92
+ - pry-github.gemspec
93
+ homepage: https://github.com/davidbalbert/pry-github
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Make pry play nice with GitHub
117
+ test_files: []
118
+ has_rdoc: