class Octocat::API
Constants
- API_ROOT_URL
Public Instance Methods
compare_branch(project, current_branch)
click to toggle source
# File lib/octocat/api.rb, line 26 def compare_branch(project, current_branch) `open #{compare_url_for_branch(project, current_branch)}` end
new_pr(project, current_branch)
click to toggle source
# File lib/octocat/api.rb, line 14 def new_pr(project, current_branch) `open #{pr_url_for(project, current_branch)}` end
open_branch(project, current_branch)
click to toggle source
# File lib/octocat/api.rb, line 22 def open_branch(project, current_branch) `open #{branch_url_for(project, current_branch)}` end
open_pr(project, current_branch)
click to toggle source
# File lib/octocat/api.rb, line 18 def open_pr(project, current_branch) `open #{pull_request_url_for_branch(project, current_branch)}` end
pull_requests(project)
click to toggle source
# File lib/octocat/api.rb, line 8 def pull_requests(project) password = `/usr/bin/security find-internet-password -g -a halogenandtoast -s github.com -w`.chomp connection = open("#{API_ROOT_URL}repos/#{project}/pulls", http_basic_authentication: ["halogenandtoast", password]) JSON.parse(connection.read) end
Private Instance Methods
base_url()
click to toggle source
# File lib/octocat/api.rb, line 46 def base_url "https://github.com" end
branch_url_for(project, branch)
click to toggle source
# File lib/octocat/api.rb, line 54 def branch_url_for(project, branch) "#{base_url}/#{project}/tree/#{branch}" end
compare_url_for_branch(project, branch)
click to toggle source
# File lib/octocat/api.rb, line 59 def compare_url_for_branch(project, branch) "#{base_url}/#{project}/compare/master...#{branch}" end
pr_url_for(project, branch)
click to toggle source
# File lib/octocat/api.rb, line 50 def pr_url_for(project, branch) "#{base_url}/#{project}/pull/new/#{branch}" end
pull_request_url_for_branch(project, branch)
click to toggle source
# File lib/octocat/api.rb, line 32 def pull_request_url_for_branch(project, branch) current_pull_requests = pull_requests(project) pull_request = current_pull_requests.detect { |pr| pr["head"]["ref"] == branch } if pull_request pull_request["html_url"] else print "No pull request for #{branch}. Create one now? [Y/n]" response = $stdin.gets.chomp unless response.downcase == "n" new_pr(project, branch) end end end