Browse files

private repositories support

  • Loading branch information...
1 parent 4c60bf0 commit fed9a6cc177cbc4a7f974b7bea908e656bf8fc5f @grzegorzkazulak grzegorzkazulak committed Jan 27, 2011
Showing with 54 additions and 4 deletions.
  1. +12 −1 README.md
  2. +42 −3 lib/git-pulls.rb
View
13 README.md
@@ -29,6 +29,17 @@ Makes it easy to list and merge GitHub pull requests.
$ git pulls merge 1
> merge pull request #1
+
+Private repositories
+----------------
+
+To manage pull requests for your private repositories you have set up your git config for github
+
+ $ git config --global github.user your_gitubusername
+ $ git config --global github.token your_githubtoken123456789
+
+You can find your API token on the [account](https://github.com/account) page.
+
Installation
===============
@@ -37,4 +48,4 @@ Simply install it via Rubygems:
gem install git-pulls
-(Prefix with `sudo` if necessary)
+(Prefix with `sudo` if necessary)
View
45 lib/git-pulls.rb
@@ -135,10 +135,15 @@ def update
fetch_stale_forks
list
end
+
+ def protocol(is_private)
+ is_private ? "ssh://git@" : "git://"
+ end
def fetch_stale_forks
puts "Checking for forks in need of fetching"
pulls = get_pull_info
+ is_private = get_repo_visibility
repos = {}
pulls.each do |pull|
o = pull['head']['repository']['owner']
@@ -151,7 +156,7 @@ def fetch_stale_forks
end
repos.each do |repo, bool|
puts " fetching #{repo}"
- git("fetch git://github.com/#{repo}.git refs/heads/*:refs/pr/#{repo}/*")
+ git("fetch #{protocol(is_private)}github.com/#{repo}.git refs/heads/*:refs/pr/#{repo}/*")
end
end
@@ -180,15 +185,49 @@ def clean(info)
info.to_s.gsub("\n", ' ')
end
+
+ # PRIVATE REPOSITORIES ACCESS
+
+ def github_username
+ git("config --get-all github.user")
+ end
+
+ def github_token
+ git("config --get-all github.token")
+ end
+
# API/DATA HELPER FUNCTIONS #
+
+ def github_credentials_provided?
+ if github_token.empty? && github_username.empty?
+ return false
+ end
+ true
+ end
+
+ def authentication_options
+ if github_credentials_provided?
+ options = {:basic_auth => {:username => "#{github_username}/token:#{github_token}"}}
+ end
+ options || {}
+ end
def get_pull_info
get_data(PULLS_CACHE_FILE)['pulls']
end
+ def get_repo_visibility
+ # This would fail if the repository was private and user did not provide github token
+ if github_credentials_provided?
+ repo_path = "/repos/show/#{repo_info[0]}/#{repo_info[1]}"
+ repo_response = HTTParty.get('https://github.com/api/v2/json' << repo_path, authentication_options)
+ repo_response['repository']['private'] if repo_response['repository']
+ end
+ end
+
def cache_pull_info
path = "/pulls/#{@user}/#{@repo}/open"
- response = HTTParty.get('https://github.com/api/v2/json' << path)
+ response = HTTParty.get('https://github.com/api/v2/json' << path, authentication_options)
save_data(response, PULLS_CACHE_FILE)
end
@@ -226,4 +265,4 @@ def repo_info
def git(command)
`git #{command}`.chomp
end
-end
+end

0 comments on commit fed9a6c

Please sign in to comment.