Skip to content

Commit

Permalink
If the user is in org, check out via SSH.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Jun 22, 2012
1 parent 188b226 commit 77bd86c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/commands/commands.rb
Expand Up @@ -161,7 +161,7 @@
end

if repo
if options[:ssh] || current_user?(user)
if options[:ssh] || current_user?(user) || in_org?(user)
git_exec "clone git@github.com:#{user}/#{repo}.git" + (dir ? " #{dir}" : "")
else
git_exec "clone git://github.com/#{user}/#{repo}.git" + (dir ? " #{dir}" : "")
Expand Down Expand Up @@ -307,7 +307,6 @@
data = JSON.parse(open(pull_url).read)
end
head = data['head']
puts data
tip = git "rev-parse HEAD"
if github_token
repo_owner = head['repo']['owner']['login']
Expand Down
10 changes: 9 additions & 1 deletion lib/github/command.rb
Expand Up @@ -97,7 +97,15 @@ def request_github_credentials
git("config --global github.oauth '#{data["token"]}'")
true
end


# is the current user in the given org?
def in_org?(name)
command = "curl -H 'Authorization: token #{github_token}' https://api.github.com/user/orgs"
output_json = sh command
orgs = JSON.parse(output_json)
return orgs.find {|o| o['login']==name }!=nil
end

def highline
@highline ||= HighLine.new
end
Expand Down

0 comments on commit 77bd86c

Please sign in to comment.