GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: The official `github` command line helper for simplifying your GitHub experience.
Homepage: http://github.com
Clone URL: git://github.com/defunkt/github-gem.git
defunkt (author)
Sun May 11 19:32:43 -0700 2008
commit  af8cfb367df0a76aec274c16af26936bcb9de1da
tree    c03f6c824e3961f8bf81f30a1da45cfe85a965b1
parent  a4452cb0f150a63e6c417dbabbc56fff8f59094c parent  bf1aaf6cca044b58bf74c2d7eaddb04764cb90dd
github-gem / commands / helpers.rb
100644 94 lines (78 sloc) 1.938 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
GitHub.helper :user_and_repo_from do |url|
  case url
  when %r|^git://github\.com/([^/]+/[^/]+)$|: $1.split('/')
  when %r|^(?:ssh://)?(?:git@)?github\.com:([^/]+/[^/]+)$|: $1.split('/')
  else ['', '']
  end
end
 
GitHub.helper :user_and_repo_for do |remote|
  user_and_repo_from(url_for(remote))
end
 
GitHub.helper :user_for do |remote|
  user_and_repo_for(remote).first
end
 
GitHub.helper :repo_for do |remote|
  user_and_repo_for(remote).last
end
 
GitHub.helper :project do
  repo = repo_for(:origin)
  if repo == ""
    if url_for(:origin) == ""
      STDERR.puts "Error: missing remote 'origin'"
    else
      STDERR.puts "Error: remote 'origin' is not a github URL"
    end
    exit 1
  end
  repo.chomp('.git')
end
 
GitHub.helper :url_for do |remote|
  `git config --get remote.#{remote}.url`.chomp
end
 
GitHub.helper :remotes do
  regexp = '^remote\.(.+)\.url$'
  `git config --get-regexp '#{regexp}'`.split(/\n/).map do |line|
    name_string, url = line.split(/ /, 2)
    m, name = *name_string.match(/#{regexp}/)
    [name, url]
  end
end
 
GitHub.helper :tracking do
  remotes.map do |(name, url)|
    if ur = user_and_repo_from(url)
      [name, ur.first]
    else
      [name, url]
    end
  end
end
 
GitHub.helper :tracking? do |user|
  tracking.include?(user)
end
 
GitHub.helper :owner do
  user_for(:origin)
end
 
GitHub.helper :user_and_branch do
  raw_branch = `git rev-parse --symbolic-full-name HEAD`.chomp.sub(/^refs\/heads\//, '')
  user, branch = raw_branch.split(/\//, 2)
  if branch
    [user, branch]
  else
    [owner, user]
  end
end
 
GitHub.helper :branch_user do
  user_and_branch.first
end
 
GitHub.helper :branch_name do
  user_and_branch.last
end
 
GitHub.helper :public_url_for do |user|
  "git://github.com/#{user}/#{project}.git"
end
 
GitHub.helper :homepage_for do |user, branch|
  "https://github.com/#{user}/#{project}/tree/#{branch}"
end
 
GitHub.helper :open do
  Windoze ? 'start' : 'open'
end