Class: Vx::ServiceConnector::Github::Hooks

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/github/hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repoObject

Returns the value of attribute repo

Returns:

  • (Object)

    the current value of repo



4
5
6
# File 'lib/vx/service_connector/github/hooks.rb', line 4

def repo
  @repo
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



4
5
6
# File 'lib/vx/service_connector/github/hooks.rb', line 4

def session
  @session
end

Instance Method Details

#allObject



6
7
8
# File 'lib/vx/service_connector/github/hooks.rb', line 6

def all
  session.hooks(repo.full_name)
end

#create(url, token) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/vx/service_connector/github/hooks.rb', line 10

def create(url, token)
  config = {
    url:           url,
    secret:        token,
    content_type: "json"
  }
  options = { events: %w{ push pull_request } }
  session.create_hook(repo.full_name, "web", config, options)
end

#destroy(url_mask) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/vx/service_connector/github/hooks.rb', line 20

def destroy(url_mask)
  all.select do |hook|
    if url = hook.config.rels[:self]
      url.href =~ /#{Regexp.escape url_mask}/
    end
  end.map do |hook|
    session.remove_hook(repo.full_name, hook.id)
  end
end