Class: Toolshed::Github
- Inherits:
-
Object
- Object
- Toolshed::Github
- Includes:
- HTTParty
- Defined in:
- lib/toolshed/github.rb
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 |
# File 'lib/toolshed/github.rb', line 5 def initialize(={}) @auth = { username: Toolshed::Client::github_username, password: Toolshed::Client::github_password } @default_options = { :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 Method Details
#branch_name ⇒ Object
45 46 47 48 |
# File 'lib/toolshed/github.rb', line 45 def branch_name # branch information branch_name = `git rev-parse --abbrev-ref HEAD`.strip end |
#branched_from ⇒ Object
50 51 52 |
# File 'lib/toolshed/github.rb', line 50 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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/toolshed/github.rb', line 15 def create_pull_request(title, body, ={}) .merge!(@default_options) .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
36 37 38 39 40 41 42 43 |
# File 'lib/toolshed/github.rb', line 36 def list_branches(={}) .merge!(@default_options) 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 |