Class: Toolshed::Github
- Inherits:
-
Object
- Object
- Toolshed::Github
- Includes:
- HTTParty
- Defined in:
- lib/toolshed/github.rb
Class Method Summary collapse
Instance Method Summary collapse
- #branch_name ⇒ Object
- #branched_from ⇒ Object
- #create_pull_request(title, body, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Github
constructor
A new instance of Github.
- #list_branches(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Github
Returns a new instance of Github.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/toolshed/github.rb', line 5 def initialize(={}) username = Toolshed::Client::github_username password = Toolshed::Client::github_password unless ([:username].nil?) username = [:username] end unless ([:password].nil?) password = [:password] end @auth = { username: username, password: password } = { :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 |
Class Method Details
.password ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/toolshed/github.rb', line 76 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
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/toolshed/github.rb', line 65 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
#branch_name ⇒ Object
56 57 58 59 |
# File 'lib/toolshed/github.rb', line 56 def branch_name # branch information branch_name = `git rev-parse --abbrev-ref HEAD`.strip end |
#branched_from ⇒ Object
61 62 63 |
# File 'lib/toolshed/github.rb', line 61 def branched_from branched_from = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.split('/')[-1].strip end |
#create_pull_request(title, body, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/toolshed/github.rb', line 26 def create_pull_request(title, body, ={}) .merge!() .merge!({ body: { title: title, body: body, head: "#{Toolshed::Client.github_username}:#{self.branch_name}", base: self.branched_from }.to_json }) response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.branched_from_user}/#{Toolshed::Client.branched_from_repo_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
47 48 49 50 51 52 53 54 |
# File 'lib/toolshed/github.rb', line 47 def list_branches(={}) .merge!() response = HTTParty.get("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/toolshed/branches", ).response JSON.parse(response.body).each do |branch| puts branch.inspect end end |