Class: Policial::PullRequestEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/policial/pull_request_event.rb

Overview

Public: Parses a pull request event payload.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ PullRequestEvent

Returns a new instance of PullRequestEvent.



10
11
12
# File 'lib/policial/pull_request_event.rb', line 10

def initialize(payload)
  @payload = payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



8
9
10
# File 'lib/policial/pull_request_event.rb', line 8

def payload
  @payload
end

Instance Method Details

#pull_request_attributesObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/policial/pull_request_event.rb', line 14

def pull_request_attributes
  {
    repo: @payload['repository']['full_name'],
    number: @payload['number'],
    head_sha: @payload['pull_request']['head']['sha'],
    user: @payload['pull_request']['user']['login']
  }
rescue NoMethodError
  nil
end

#should_investigate?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/policial/pull_request_event.rb', line 25

def should_investigate?
  !pull_request_attributes.nil? && (
    @payload['action'] == 'opened' || @payload['action'] == 'synchronize'
  )
end