Class: GitHubWebHooksReceiver::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/github-web-hooks-receiver/payload.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, metadata = {}) ⇒ Payload

Returns a new instance of Payload.



19
20
21
22
# File 'lib/github-web-hooks-receiver/payload.rb', line 19

def initialize(data, ={})
  @data = data
   = 
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/github-web-hooks-receiver/payload.rb', line 24

def [](key)
  key.split(".").inject(@data) do |current_data, current_key|
    if current_data
      current_data[current_key]
    else
      nil
    end
  end
end

#event_nameObject



58
59
60
61
62
63
64
# File 'lib/github-web-hooks-receiver/payload.rb', line 58

def event_name
  if gitlab?
    self["object_kind"]
  else
    ["x-github-event"]
  end
end

#github_gollum?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/github-web-hooks-receiver/payload.rb', line 54

def github_gollum?
  event_name == "gollum"
end

#gitlab?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/github-web-hooks-receiver/payload.rb', line 46

def gitlab?
  not self["object_kind"].nil?
end

#gitlab_wiki?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/github-web-hooks-receiver/payload.rb', line 50

def gitlab_wiki?
  event_name == "wiki_page"
end

#repository_urlObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/github-web-hooks-receiver/payload.rb', line 34

def repository_url
  if gitlab_wiki?
    self["wiki.git_ssh_url"]
  elsif gitlab?
    self["repository.url"]
  elsif github_gollum?
    self["repository.clone_url"].gsub(/(\.git)\z/, ".wiki\\1")
  else
    self["repository.clone_url"] || "#{self['repository.url']}.git"
  end
end