Class: Vx::ServiceConnector::Bitbucket::Hooks

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/bitbucket/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/bitbucket/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/bitbucket/hooks.rb', line 4

def session
  @session
end

Instance Method Details

#allObject



6
7
8
9
10
11
12
# File 'lib/vx/service_connector/bitbucket/hooks.rb', line 6

def all
  begin
    session.get hooks_url
  rescue RequestError
    []
  end
end

#create(url, token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vx/service_connector/bitbucket/hooks.rb', line 14

def create(url, token)
  session.post(
    hooks_url,
    'type' => 'POST',
    'URL'  => url
  )
  session.post(
    hooks_url,
    'type' => 'Pull Request POST',
    'URL'  => url,
    'create/edit/merge/decline' => 'on',
    'comments'                  => 'off',
    'approve/unapprove'         => 'off'
  )
end

#destroy(url_mask) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/vx/service_connector/bitbucket/hooks.rb', line 30

def destroy(url_mask)
  all.select do |hook|
    url = extract_url(hook)
    url && url =~ /#{Regexp.escape url_mask}/
  end.map do |hook|
    session.delete hook_url(hook['id'])
  end
end