Class: Toolshed::Git::Github
Constant Summary
Constants included from Toolshed::Git
DEFAULT_BRANCH_FROM, DEFAULT_GIT_TOOL
Instance Attribute Summary collapse
-
#default_options ⇒ Object
Returns the value of attribute default_options.
Attributes inherited from Base
#from_remote_branch_name, #from_remote_name, #to_remote_branch_name, #to_remote_name, #validator
Class Method Summary collapse
Instance Method Summary collapse
- #create_pull_request(title, body, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Github
constructor
A new instance of Github.
- #list_branches(options = {}) ⇒ Object
Methods included from Toolshed::Git
branch_name, branch_name_from_id, branched_from, checkout, clean_branch_name, delete, git_submodule_command, push
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Github
Returns a new instance of Github.
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 |
# File 'lib/toolshed/git/github.rb', line 9 def initialize(={}) super() username = Toolshed::Client::github_username password = Toolshed::Client::github_password token = Toolshed::Client::github_token unless ([:username].nil?) username = [:username] end unless ([:password].nil?) password = [:password] end unless (token.nil?) username = token password = nil end unless ([:token].nil?) username = [:token] password = nil end @auth = { username: username, password: password } self. = { :headers => { "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17", }, basic_auth: @auth, } end |
Instance Attribute Details
#default_options ⇒ Object
Returns the value of attribute default_options.
7 8 9 |
# File 'lib/toolshed/git/github.rb', line 7 def @default_options end |
Class Method Details
.create_instance ⇒ Object
94 95 96 |
# File 'lib/toolshed/git/github.rb', line 94 def self.create_instance Toolshed::Git::Github.new({ username: Toolshed::Git::Github.username, password: Toolshed::Git::Github.password }) end |
.password ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/toolshed/git/github.rb', line 81 def self.password password = Toolshed::Client::github_password if (password.nil?) # prompt to ask for password system "stty -echo" puts "Github password? " password = $stdin.gets.chomp.strip system "stty echo" end return password end |
.username ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/toolshed/git/github.rb', line 70 def self.username username = Toolshed::Client::github_username if (username.nil?) # prompt to ask for username puts "Github username? " username = $stdin.gets.chomp.strip end return username end |
Instance Method Details
#create_pull_request(title, body, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/toolshed/git/github.rb', line 43 def create_pull_request(title, body, ={}) .merge!(self.) .merge!({ body: { title: title, body: body, head: "#{Toolshed::Client.github_username}:#{Toolshed::Git::Base.branch_name}", base: Toolshed::Git::Base.branched_from }.to_json }) response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.pull_from_repository_user}/#{Toolshed::Client.pull_from_repository_name}/pulls", ).response response = JSON.parse(response.body) if (response["errors"].nil?) response else raise "validation errors #{response.inspect}" end end |
#list_branches(options = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/toolshed/git/github.rb', line 63 def list_branches(={}) .merge!(self.) response = HTTParty.get("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/#{Toolshed::Client.pull_from_repository_name}/branches", ).response response = JSON.parse(response.body) end |