Class: Janky::GitHub::PayloadParser

Inherits:
Object
  • Object
show all
Defined in:
lib/janky/github/payload_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ PayloadParser

Returns a new instance of PayloadParser.



4
5
6
# File 'lib/janky/github/payload_parser.rb', line 4

def initialize(json)
  @payload = Yajl.load(json)
end

Instance Method Details

#branchObject



56
57
58
# File 'lib/janky/github/payload_parser.rb', line 56

def branch
  @payload["ref"].split("refs/heads/").last
end

#commitsObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/janky/github/payload_parser.rb', line 20

def commits
  @payload["commits"].map do |commit|
    GitHub::Commit.new(
      commit["id"],
      commit["url"],
      commit["message"],
      normalize_author(commit["author"]),
      commit["timestamp"]
    )
  end
end

#compareObject



16
17
18
# File 'lib/janky/github/payload_parser.rb', line 16

def compare
  @payload["compare"]
end

#headObject



12
13
14
# File 'lib/janky/github/payload_parser.rb', line 12

def head
  @payload["after"]
end

#normalize_author(author) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/janky/github/payload_parser.rb', line 32

def normalize_author(author)
  if email = author["email"]
    "#{author["name"]} <#{email}>"
  else
    author
  end
end

#pusherObject



8
9
10
# File 'lib/janky/github/payload_parser.rb', line 8

def pusher
  @payload["pusher"]["name"]
end

#uriObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/janky/github/payload_parser.rb', line 40

def uri
  if uri = @payload["uri"]
    return uri
  end

  repository = @payload["repository"]

  if repository["private"]
    "git@#{GitHub.git_host}:#{URI(repository["url"]).path[1..-1]}"
  else
    uri = URI(repository["url"])
    uri.scheme = "git"
    uri.to_s
  end
end