Class: Github

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/straight_line/common/github.rb

Overview

Github API wrapper

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGithub

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

#clientObject



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', "#{}:#{branch}", title, body
end

#ensure_logged_inObject

Raises:



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_loginObject



57
58
59
# File 'lib/straight_line/common/github.rb', line 57

def 
  client.user.
end

#list_reposObject



26
27
28
# File 'lib/straight_line/common/github.rb', line 26

def list_repos
  @client.repositories query: { type: 'private' }
end

#loginObject



24
# File 'lib/straight_line/common/github.rb', line 24

def ; 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. == Github. &&
      p.base.ref == 'master'
  end
end

#pull_requestsObject



62
63
64
# File 'lib/straight_line/common/github.rb', line 62

def pull_requests
  client.pull_requests repo_name
end

#repo_nameObject



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

#userObject



30
31
32
# File 'lib/straight_line/common/github.rb', line 30

def user
  @client.user
end