Class: Github
- Inherits:
-
Object
- Object
- Github
- Includes:
- Singleton
- Defined in:
- lib/straight_line/common/github.rb
Overview
Github API wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #create_pull_request(branch, title, body) ⇒ Object
- #ensure_logged_in ⇒ Object
- #github_login ⇒ Object
-
#initialize ⇒ Github
constructor
A new instance of Github.
- #list_repos ⇒ Object
- #login ⇒ Object
- #pull_request_for_feature(feature) ⇒ Object
- #pull_requests ⇒ Object
- #repo_name ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize ⇒ Github
Returns a new instance of Github.
10 11 12 |
# File 'lib/straight_line/common/github.rb', line 10 def initialize @client = nil end |
Class Method Details
.make_class(name) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/straight_line/common/github.rb', line 14 def self.make_class(name) class << self self end.instance_eval do define_method name do |*args| instance.send name, *args end end end |
Instance Method Details
#client ⇒ Object
38 39 40 41 42 |
# File 'lib/straight_line/common/github.rb', line 38 def client return @client if @client @client = Octokit::Client.new netrc: true, auto_paginate: true end |
#create_pull_request(branch, title, body) ⇒ Object
44 45 46 47 48 |
# File 'lib/straight_line/common/github.rb', line 44 def create_pull_request(branch, title, body) repo = repo_name client.create_pull_request repo, 'master', "#{github_login}:#{branch}", title, body end |
#ensure_logged_in ⇒ Object
34 35 36 |
# File 'lib/straight_line/common/github.rb', line 34 def ensure_logged_in raise UserError, 'Must be logged in first' unless @client end |
#github_login ⇒ Object
57 58 59 |
# File 'lib/straight_line/common/github.rb', line 57 def github_login client.user.login end |
#list_repos ⇒ Object
26 27 28 |
# File 'lib/straight_line/common/github.rb', line 26 def list_repos @client.repositories query: { type: 'private' } end |
#login ⇒ Object
24 |
# File 'lib/straight_line/common/github.rb', line 24 def login; end |
#pull_request_for_feature(feature) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/straight_line/common/github.rb', line 67 def pull_request_for_feature(feature) prs = pull_requests prs.find do |p| p.head.ref == feature && p.head.user.login == Github.github_login && p.base.ref == 'master' end end |
#pull_requests ⇒ Object
62 63 64 |
# File 'lib/straight_line/common/github.rb', line 62 def pull_requests client.pull_requests repo_name end |
#repo_name ⇒ Object
51 52 53 54 55 |
# File 'lib/straight_line/common/github.rb', line 51 def repo_name cmd = GitCommands::Config.new('remote.origin.url') remote = cmd.run remote.match(%r{([email protected]:)(.*/.*)\.git})[2] end |
#user ⇒ Object
30 31 32 |
# File 'lib/straight_line/common/github.rb', line 30 def user @client.user end |