github 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,17 @@
1
+ bin/github
2
+ commands/commands.rb
3
+ commands/helpers.rb
4
+ lib/github/command.rb
5
+ lib/github/helper.rb
6
+ lib/github.rb
7
+ LICENSE
8
+ README
9
+ spec/command_spec.rb
10
+ spec/helpers/owner_spec.rb
11
+ spec/helpers/project_spec.rb
12
+ spec/helpers/public_url_for_spec.rb
13
+ spec/helpers/repo_for_spec.rb
14
+ spec/helpers/user_and_repo_from_spec.rb
15
+ spec/helpers/user_for_spec.rb
16
+ spec/spec_helper.rb
17
+ Manifest
data/README ADDED
@@ -0,0 +1,24 @@
1
+ The GitHub Gem
2
+ =============
3
+
4
+ This gem'll work hand-in-hand with GitHub's API to help you out.
5
+
6
+ Catch us in the #github room on freenode if you want to get involved. Or just fork and send a pull request.
7
+
8
+ ===========
9
+ Getting started
10
+ ===========
11
+
12
+ $ gem install github
13
+
14
+ Run it:
15
+ $ github <command> <args>
16
+
17
+
18
+ ===========
19
+ Contributors
20
+ ===========
21
+
22
+ - defunkt
23
+ - maddox
24
+ - halorgium
data/bin/github ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/github'
4
+
5
+ GitHub.activate ARGV
@@ -0,0 +1,47 @@
1
+ GitHub.register :helper do |name, comma_args|
2
+ comma_args ||= ''
3
+ puts helper.send(name, comma_args.split(/,/))
4
+ end
5
+
6
+ GitHub.describe :home => "Open this repo's master branch in a web browser."
7
+ GitHub.register :home do
8
+ if helper.project
9
+ exec "open #{helper.homepage_for(helper.owner, 'master')}"
10
+ end
11
+ end
12
+
13
+ GitHub.describe :browse => "Open this repo in a web browser."
14
+ GitHub.register :browse do
15
+ if helper.project
16
+ exec "open #{helper.homepage_for(helper.branch_user, helper.branch_name)}"
17
+ end
18
+ end
19
+
20
+ GitHub.describe :info => "Info about this project."
21
+ GitHub.register :info do
22
+ puts "== Info for #{helper.project}"
23
+ puts "You are #{helper.owner}"
24
+ puts "Currently tracking: "
25
+ helper.tracking.each do |(name,user_or_url)|
26
+ puts " - #{user_or_url} (as #{name})"
27
+ end
28
+ end
29
+
30
+ GitHub.describe :track => "Track another user's repository."
31
+ GitHub.register :track do |user|
32
+ die "Specify a user to track" if user.nil?
33
+ die "Already tracking #{user}" if helper.tracking?(user)
34
+
35
+ git "remote add #{user} #{helper.public_url_for(user)}"
36
+ end
37
+
38
+ GitHub.describe :pull => 'Pull from a remote.'
39
+ GitHub.register :pull do |user, branch|
40
+ die "Specify a user to pull from" if user.nil?
41
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
42
+ branch ||= 'master'
43
+
44
+ puts "Switching to #{user}/#{branch}"
45
+ git "checkout #{user}/#{branch}" if git("checkout -b #{user}/#{branch}").error?
46
+ git_exec "pull #{user} #{branch}"
47
+ end
@@ -0,0 +1,79 @@
1
+ GitHub.helper :user_and_repo_from do |url|
2
+ case url
3
+ when %r|^git://github\.com/(.*)$|: $1.split('/')
4
+ when %r|^git@github\.com:(.*)$|: $1.split('/')
5
+ end
6
+ end
7
+
8
+ GitHub.helper :user_and_repo_for do |remote|
9
+ user_and_repo_from(url_for(remote))
10
+ end
11
+
12
+ GitHub.helper :user_for do |remote|
13
+ user_and_repo_for(remote).first
14
+ end
15
+
16
+ GitHub.helper :repo_for do |remote|
17
+ user_and_repo_for(remote).last
18
+ end
19
+
20
+ GitHub.helper :project do
21
+ repo_for(:origin).chomp('.git')
22
+ end
23
+
24
+ GitHub.helper :url_for do |remote|
25
+ `git config --get remote.#{remote}.url`.chomp
26
+ end
27
+
28
+ GitHub.helper :remotes do
29
+ regexp = '^remote\.(.+)\.url$'
30
+ `git config --get-regexp '#{regexp}'`.split(/\n/).map do |line|
31
+ name_string, url = line.split(/ /, 2)
32
+ m, name = *name_string.match(/#{regexp}/)
33
+ [name, url]
34
+ end
35
+ end
36
+
37
+ GitHub.helper :tracking do
38
+ remotes.map do |(name, url)|
39
+ if ur = user_and_repo_from(url)
40
+ [name, ur.first]
41
+ else
42
+ [name, url]
43
+ end
44
+ end
45
+ end
46
+
47
+ GitHub.helper :tracking? do |user|
48
+ tracking.include?(user)
49
+ end
50
+
51
+ GitHub.helper :owner do
52
+ user_for(:origin)
53
+ end
54
+
55
+ GitHub.helper :user_and_branch do
56
+ raw_branch = `git rev-parse --symbolic-full-name HEAD`.chomp.sub(/^refs\/heads\//, '')
57
+ user, branch = raw_branch.split(/\//, 2)
58
+ if branch
59
+ [user, branch]
60
+ else
61
+ [owner, user]
62
+ end
63
+ end
64
+
65
+ GitHub.helper :branch_user do
66
+ user_and_branch.first
67
+ end
68
+
69
+ GitHub.helper :branch_name do
70
+ user_and_branch.last
71
+ end
72
+
73
+ GitHub.helper :public_url_for do |user|
74
+ "git://github.com/#{user}/#{project}.git"
75
+ end
76
+
77
+ GitHub.helper :homepage_for do |user, branch|
78
+ "https://github.com/#{user}/#{project}/tree/#{branch}"
79
+ end
data/github.gemspec ADDED
@@ -0,0 +1,42 @@
1
+
2
+ # Gem::Specification for Github-0.1.0
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{github}
7
+ s.version = "0.1.0"
8
+ s.date = %q{2008-03-03}
9
+ s.summary = %q{The official `github` command line helper for simplifying your GitHub experience.}
10
+ s.email = %q{chris@ozmm.org}
11
+ s.homepage = %q{http://github.com/}
12
+ s.rubyforge_project = %q{github}
13
+ s.description = %q{The official `github` command line helper for simplifying your GitHub experience.}
14
+ s.default_executable = %q{github}
15
+ s.has_rdoc = true
16
+ s.authors = ["Chris Wanstrath"]
17
+ s.files = ["bin/github", "commands/commands.rb", "commands/helpers.rb", "lib/github/command.rb", "lib/github/helper.rb", "lib/github.rb", "LICENSE", "README", "spec/command_spec.rb", "spec/helpers/owner_spec.rb", "spec/helpers/project_spec.rb", "spec/helpers/public_url_for_spec.rb", "spec/helpers/repo_for_spec.rb", "spec/helpers/user_and_repo_from_spec.rb", "spec/helpers/user_for_spec.rb", "spec/spec_helper.rb", "Manifest", "github.gemspec"]
18
+ s.executables = ["github"]
19
+ end
20
+
21
+
22
+ # # Original Rakefile source (requires the Echoe gem):
23
+ #
24
+ # require 'rubygems'
25
+ # require 'rake'
26
+ #
27
+ # begin
28
+ # require 'echoe'
29
+ #
30
+ # Echoe.new('github', '0.1.0') do |p|
31
+ # p.rubyforge_name = 'github'
32
+ # p.summary = "The official `github` command line helper for simplifying your GitHub experience."
33
+ # p.description = "The official `github` command line helper for simplifying your GitHub experience."
34
+ # p.url = "http://github.com/"
35
+ # p.author = 'Chris Wanstrath'
36
+ # p.email = "chris@ozmm.org"
37
+ # end
38
+ #
39
+ # rescue LoadError => boom
40
+ # puts "You are missing a dependency required for meta-operations on this gem."
41
+ # puts "#{boom.to_s.capitalize}."
42
+ # end
data/lib/github.rb ADDED
@@ -0,0 +1,78 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'github/command'
3
+ require 'github/helper'
4
+
5
+ ##
6
+ # Starting simple.
7
+ #
8
+ # $ github <command> <args>
9
+ #
10
+ # GitHub.register <command> do |*args|
11
+ # whatever
12
+ # end
13
+ #
14
+ # We'll probably want to use the `choice` gem for concise, tasty DSL
15
+ # arg parsing action.
16
+ #
17
+
18
+ module GitHub
19
+ extend self
20
+
21
+ BasePath = File.expand_path(File.dirname(__FILE__) + '/..')
22
+
23
+ def register(command, &block)
24
+ debug "Registered `#{command}`"
25
+ commands[command.to_s] = Command.new(block)
26
+ end
27
+
28
+ def describe(hash)
29
+ descriptions.update hash
30
+ end
31
+
32
+ def helper(command, &block)
33
+ debug "Helper'd `#{command}`"
34
+ Helper.send :define_method, command, &block
35
+ end
36
+
37
+ def activate(args)
38
+ @debug = args.delete('--debug')
39
+ load 'helpers.rb'
40
+ load 'commands.rb'
41
+ invoke(args.shift, *args)
42
+ end
43
+
44
+ def invoke(command, *args)
45
+ block = commands[command.to_s] || commands['default']
46
+ debug "Invoking `#{command}`"
47
+ block.call(*args)
48
+ end
49
+
50
+ def commands
51
+ @commands ||= {}
52
+ end
53
+
54
+ def descriptions
55
+ @descriptions ||= {}
56
+ end
57
+
58
+ def load(file)
59
+ file[0] == ?/ ? super : super(BasePath + "/commands/#{file}")
60
+ end
61
+
62
+ def debug(*messages)
63
+ puts *messages.map { |m| "== #{m}" } if debug?
64
+ end
65
+
66
+ def debug?
67
+ !!@debug
68
+ end
69
+ end
70
+
71
+ GitHub.register :default do
72
+ puts "Usage: github command <space separated arguments>", ''
73
+ puts "Available commands:", ''
74
+ GitHub.descriptions.each do |command, desc|
75
+ puts " #{command} => #{desc}"
76
+ end
77
+ puts
78
+ end
@@ -0,0 +1,72 @@
1
+ require 'open3'
2
+
3
+ module GitHub
4
+ class Command
5
+ def initialize(block)
6
+ (class << self;self end).send :define_method, :command, &block
7
+ end
8
+
9
+ def call(*args)
10
+ arity = method(:command).arity
11
+ args << nil while args.size < arity
12
+ send :command, *args
13
+ end
14
+
15
+ def helper
16
+ @helper ||= Helper.new
17
+ end
18
+
19
+ def pgit(*command)
20
+ puts git(*command)
21
+ end
22
+
23
+ def git(*command)
24
+ sh ['git', command].flatten.join(' ')
25
+ end
26
+
27
+ def git_exec(*command)
28
+ exec ['git', command].flatten.join(' ')
29
+ end
30
+
31
+ def sh(*command)
32
+ Shell.new(*command).run
33
+ end
34
+
35
+ def die(message)
36
+ puts "=> #{message}"
37
+ exit!
38
+ end
39
+
40
+ class Shell < String
41
+ def initialize(*command)
42
+ @command = command
43
+ end
44
+
45
+ def run
46
+ GitHub.debug "sh: #{command}"
47
+ _, out, err = Open3.popen3(*@command)
48
+
49
+ out = out.read.strip
50
+ err = err.read.strip
51
+
52
+ if out.any?
53
+ replace @out = out
54
+ elsif err.any?
55
+ replace @error = err
56
+ end
57
+ end
58
+
59
+ def command
60
+ @command.join(' ')
61
+ end
62
+
63
+ def error?
64
+ !!@error
65
+ end
66
+
67
+ def out?
68
+ !!@out
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,4 @@
1
+ module GitHub
2
+ class Helper
3
+ end
4
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The owner helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should return hacker" do
9
+ @helper.should_receive(:url_for).with(:origin).and_return("git://github.com/hacker/project.git")
10
+ @helper.owner.should == "hacker"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The project helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should return project-awesome" do
9
+ @helper.should_receive(:url_for).with(:origin).and_return("git://github.com/user/project-awesome.git")
10
+ @helper.project.should == "project-awesome"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The public_url_for helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should return git://github.com/wycats/merb-core.git" do
9
+ @helper.should_receive(:url_for).with(:origin).and_return("git://github.com/user/merb-core.git")
10
+ @helper.public_url_for("wycats").should == "git://github.com/wycats/merb-core.git"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The repo_for helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should return mephisto.git" do
9
+ @helper.should_receive(:url_for).with("mojombo").and_return("git@github.com:mojombo/mephisto.git")
10
+ @helper.repo_for("mojombo").should == "mephisto.git"
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The user_and_repo_from helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should parse a git:// url" do
9
+ @helper.user_and_repo_from("git://github.com/defunkt/github.git").should == ["defunkt", "github.git"]
10
+ end
11
+
12
+ it "should parse a ssh-based url" do
13
+ @helper.user_and_repo_from("git@github.com:mojombo/god.git").should == ["mojombo", "god.git"]
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The user_for helper" do
4
+ before(:each) do
5
+ @helper = GitHub::Helper.new
6
+ end
7
+
8
+ it "should return defunkt" do
9
+ @helper.should_receive(:url_for).with("origin").and_return("git@github.com:defunkt/project.git")
10
+ @helper.user_for("origin").should == "defunkt"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.dirname(__FILE__) + '/../lib/github'
5
+
6
+ module GitHub
7
+ load 'helpers.rb'
8
+ load 'commands.rb'
9
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: github
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2008-03-03 00:00:00 -08:00
8
+ summary: The official `github` command line helper for simplifying your GitHub experience.
9
+ require_paths:
10
+ - lib
11
+ email: chris@ozmm.org
12
+ homepage: http://github.com/
13
+ rubyforge_project: github
14
+ description: The official `github` command line helper for simplifying your GitHub experience.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Chris Wanstrath
31
+ files:
32
+ - bin/github
33
+ - commands/commands.rb
34
+ - commands/helpers.rb
35
+ - lib/github/command.rb
36
+ - lib/github/helper.rb
37
+ - lib/github.rb
38
+ - LICENSE
39
+ - README
40
+ - spec/command_spec.rb
41
+ - spec/helpers/owner_spec.rb
42
+ - spec/helpers/project_spec.rb
43
+ - spec/helpers/public_url_for_spec.rb
44
+ - spec/helpers/repo_for_spec.rb
45
+ - spec/helpers/user_and_repo_from_spec.rb
46
+ - spec/helpers/user_for_spec.rb
47
+ - spec/spec_helper.rb
48
+ - Manifest
49
+ - github.gemspec
50
+ test_files: []
51
+
52
+ rdoc_options: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ executables:
57
+ - github
58
+ extensions: []
59
+
60
+ requirements: []
61
+
62
+ dependencies: []
63
+