Class: Jackal::Github::Formatter::CodeFetcher

Inherits:
Formatter
  • Object
show all
Defined in:
lib/jackal-github/formatter/code_fetcher.rb

Constant Summary collapse

SOURCE =

Format payloads from source

'*'
DESTINATION =

Formats for destination

'code_fetcher'

Instance Method Summary collapse

Instance Method Details

#format(payload) ⇒ Smash

Format the payload to provide code fetcher information

Parameters:

  • payload (Smash)

Returns:

  • (Smash)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jackal-github/formatter/code_fetcher.rb', line 18

def format(payload)
  if(payload.get(:data, :github))
    payload.set(:data, :code_fetcher, :info, :source, 'github')
    payload.set(:data, :code_fetcher, :info, :owner,
      payload.get(:data, :github, :repository, :owner, :login))
    payload.set(:data, :code_fetcher, :info, :name,
      payload.get(:data, :github, :repository, :name))
    payload.set(:data, :code_fetcher, :info, :private,
      payload.get(:data, :github, :repository, :private))
    payload.set(:data, :code_fetcher, :info, :url,
      payload.get(:data, :github, :repository, :clone_url))
    set_reference_information(payload.get(:data, :github, :event).to_s, payload)
    payload
  end
end

#set_reference_information(event, payload) ⇒ Smash

Set repository reference information into payload if available

Parameters:

  • event (String)

    github event type

  • payload (Smash)

Returns:

  • (Smash)


40
41
42
43
44
45
46
47
48
# File 'lib/jackal-github/formatter/code_fetcher.rb', line 40

def set_reference_information(event, payload)
  method_name = "#{event}_reference"
  if(self.respond_to?(method_name, true))
    ref, sha = send(method_name, payload)
    payload.set(:data, :code_fetcher, :info, :reference, ref)
    payload.set(:data, :code_fetcher, :info, :commit_sha, sha)
  end
  payload
end