Class: IrcMachine::Plugin::GithubNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/irc_machine/plugin/github_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ GithubNotification

Returns a new instance of GithubNotification.



15
16
17
18
# File 'lib/irc_machine/plugin/github_notifier.rb', line 15

def initialize(body)
  json = CGI.parse(body)["payload"][0]
  @data = OpenStruct.new(JSON.parse(json))
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/irc_machine/plugin/github_notifier.rb', line 13

def data
  @data
end

Instance Method Details

#author_usernamesObject



36
37
38
# File 'lib/irc_machine/plugin/github_notifier.rb', line 36

def author_usernames
  authors.map{ |a| a.username }.uniq
end

#authorsObject



32
33
34
# File 'lib/irc_machine/plugin/github_notifier.rb', line 32

def authors
  data.commits.map{ |c| OpenStruct.new c["author"] }
end

#branchObject



28
29
30
# File 'lib/irc_machine/plugin/github_notifier.rb', line 28

def branch
  data.ref.split("/").last
end

#commit_countObject



24
25
26
# File 'lib/irc_machine/plugin/github_notifier.rb', line 24

def commit_count
  data.commits.size
end

#compare_urlObject



40
41
42
# File 'lib/irc_machine/plugin/github_notifier.rb', line 40

def compare_url
  data.compare
end

#messageObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/irc_machine/plugin/github_notifier.rb', line 44

def message
  "%d commit%s by %s pushed to %s/%s: %s" % [
    commit_count,
    commit_count == 1 ? "" : "s",
    author_usernames.join(", "),
    repo_name,
    branch,
    compare_url
  ]
end

#repo_nameObject



20
21
22
# File 'lib/irc_machine/plugin/github_notifier.rb', line 20

def repo_name
  data.repository["name"]
end