Class: OpenSourceStats::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/open_source_stats/event.rb

Constant Summary collapse

TYPES =

Hash of event types to count as an event

The top-level key should be the event type The top-level value should be a hash used to filter acceptable key/value pairs

For the sub-hash, keys are keys to look for in the event, and the value is an array of acceptable values

Events that don’t match an event type and key/value pair with fail the in_scope? check

{
  "CreateEvent" => { :ref_type => ["repository"] },
  "IssueCommentEvent" => {:action => ["created"] },
  "IssuesEvent" => { :action => ["opened", "closed"] },
  "PublicEvent" => {},
  "PullRequestEvent" => { :action => ["opened", "closed"]},
  "PullRequestReviewCommentEvent" => { :action => ["created"] },
  "PushEvent" => {},
  "ReleaseEvent" => { :action => "published" },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Event

Takes the raw event object from Octokit



27
28
29
30
31
32
33
34
# File 'lib/open_source_stats/event.rb', line 27

def initialize(event)
  @type = event[:type]
  @repo = event[:repo][:name]
  @actor = User.new(event[:actor][:login])
  @time = event[:created_at]
  @payload = event[:payload]
  @id = event[:id]
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def actor
  @actor
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def payload
  @payload
end

#repoObject (readonly)

Returns the value of attribute repo.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def repo
  @repo
end

#timeObject (readonly)

Returns the value of attribute time.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def time
  @time
end

#typeObject (readonly)

Returns the value of attribute type.



24
25
26
# File 'lib/open_source_stats/event.rb', line 24

def type
  @type
end

Instance Method Details

#==(other_event) ⇒ Object Also known as: eql?

Use event IDs to compare uniquness via Array#uniq



47
48
49
# File 'lib/open_source_stats/event.rb', line 47

def ==(other_event)
  id == other_event.id
end

#commitsObject

How many commmits does this event involve?

For push events, this is the number of commits pushed For pull request events, this is the number of commits contained in the PR



56
57
58
59
60
61
62
63
64
65
# File 'lib/open_source_stats/event.rb', line 56

def commits
  case type
  when "PushEvent"
    payload[:commits].count
  when "PullRequestEvent"
    payload[:pull_request][:commits]
  else
    0
  end
end

#in_scope?Boolean

Is this event type within our timeframe AND an acceptable event type?

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/open_source_stats/event.rb', line 37

def in_scope?
  return false unless time >= OpenSourceStats.start_time
  return false unless TYPES.keys.include?(type)
  TYPES[type].each do |key, values|
    return false unless values.include? payload[key]
  end
  true
end