Class: GotFixed::Adapters::Github

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/got_fixed/adapters/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Github



11
12
13
# File 'lib/got_fixed/adapters/github.rb', line 11

def initialize(options = {})
  ensure_mandatory_parameters options, true
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/got_fixed/adapters/github.rb', line 9

def access_token
  @access_token
end

#ownerObject

Returns the value of attribute owner.



9
10
11
# File 'lib/got_fixed/adapters/github.rb', line 9

def owner
  @owner
end

#repoObject

Returns the value of attribute repo.



9
10
11
# File 'lib/got_fixed/adapters/github.rb', line 9

def repo
  @repo
end

Instance Method Details

#create_hook(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/got_fixed/adapters/github.rb', line 33

def create_hook(options = {})
  ensure_mandatory_parameters options
  url = options[:url] || "http://requestb.in/xy043uxy"
  secret = options[:secret]  # TODO(ssaunier): Raise error if secret not set.

  body = {
    :name => "web",
    :config => {
      :url => url,
      :content_type => "json",
      :secret => secret
    },
    :events => [ 'issues' ]
  }
  self.class.post "/repos/#{@owner}/#{@repo}/hooks", :body => body.to_json, :headers => headers
end

#hooks(options = {}) ⇒ Object



28
29
30
31
# File 'lib/got_fixed/adapters/github.rb', line 28

def hooks(options = {})
  ensure_mandatory_parameters options
  self.class.get "/repos/#{@owner}/#{@repo}/hooks", :headers => headers
end

#issues(options = {}) ⇒ Object

Retrieve all issues of a given GitHub repository matching given labels Labels must be comma separated, e.g. “public,foo,bar”

Doc: developer.github.com/v3/issues/#list-issues-for-a-repository



19
20
21
22
23
24
25
26
# File 'lib/got_fixed/adapters/github.rb', line 19

def issues(options = {})
  ensure_mandatory_parameters options
  labels = options[:labels]

  opened = issues_with_state(labels, :open)
  closed = issues_with_state(labels, :closed)
  opened + closed
end