14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/gitall/parsers/github.rb', line 14
def self.parse(json, event)
j = RecursiveOpenStruct.new(json)
response = []
case event
when 'ping'
zen = j.zen
id = j.hook_id
response << "Hook #{id} [PING] '#{zen}'"
when 'issue_comment'
when 'member'
when 'membership'
when 'milestone'
when 'label'
action = j.action
l = j.label
repo = j.repository.full_name
user = j.sender.login
lurl = l.url
lname = l.name
case action
when 'created', 'deleted'
response << "[#{repo}] #{user} #{action} label #{lname} <#{lurl}>"
when 'edited'
old = l.changes.name.from
new = lname
if old != new
response << "[#{repo}] #{user} #{action} Old: #{old} New: #{new}"
end
end
when 'team'
when 'team_add'
when 'fork'
f = RecursiveOpenStruct.new(j.forkee)
user = j.sender.login
fork = f.full_name
repo = j.repository.full_name
response << "[#{repo}] #{user} forked the repository to #{fork}"
when 'pull_request'
p = RecursiveOpenStruct.new(j.pull_request)
action = j.action
case action
when 'opened'
when 'closed'
end
when 'pull_request_review'
action = j.action
case action
when 'created'
when 'deleted'
end
when 'pull_request_review_comment'
c = RecursiveOpenStruct.new(j.)
action = j.action
case action
when 'created'
when 'deleted'
when 'edited'
end
when 'commit_comment'
when 'gollum'
p = j.pages
action = j.action
when 'create'
when 'delete'
when 'organization'
action = j.action
case action
when 'member_add'
when 'member_del'
end
when 'repository'
r = RecursiveOpenStruct.new(j.repository)
action = j.action
repo = r.full_name
user = j.sender.login
case action
when 'created'
response << "#{user} created repository #{repo}"
when 'deleted'
response << "#{user} deleted #{r.full_name}"
end
when 'release'
r = RecursiveOpenStruct.new(j.release)
tag = r.tag_name
action = j.action
repo = j.repository.full_name
case action
when 'published'
response << "[#{repo}] released #{tag}!"
else
response << "[#{repo}] #{action} something!"
response << "**\u000304This is a fallback for when new actions are added to the 'ReleaseEvent'**"
response << 'Please submit an issue at https://github.com/IotaSpencer/gitall'
response << ' or join #gitall on the freenode or ElectroCode IRC networks.'
end
when 'watch'
response << "[#{repo}] #{user} starred the repository!"
when 'issue'
repo = j.repository.full_name
url = shorten(j.issue.url)
action = j.action
id = j.issue.number
title = j.issue.title
user = j.issue.user.name
case action
when 'assigned'
when 'unassigned'
when 'labeled'
label = j.label.name
response << "[#{repo}] #{user} added #{label}"
when 'unlabeled'
when 'milestoned'
response << "[#{repo}] #{user} milestoned issue ##{id} "
when 'demilestoned'
when 'reopened'
response << "[#{repo}] #{user} reopened ##{id}"
when 'opened'
response << "[#{repo}] #{user} opened an issue ##{id} - #{title} <#{url}>"
when 'closed'
response << "[#{repo}] #{user} closed issue ##{id} - #{title} <#{url}>"
when 'edited'
response << "[#{repo}] #{user} edited issue ##{id} - #{title} <#{url}>"
end
when 'push'
repo = j.repository.full_name
branch = j.ref.split('/')[-1]
commits = j.commits
added = 0
removed = 0
modified = 0
commits.each do |h|
added += h['added'].length
removed += h['removed'].length
modified += h['modified'].length
end
pusher = j.pusher.name
commit_count = commits.length
compare_url = shorten(j.compare)
response << "[#{repo}] #{pusher} pushed #{commit_count} commit(s) [+#{added}/-#{removed}/±#{modified}] to [#{branch}] <#{compare_url}>"
if commits.length > 3
coms = commits[0..2]
coms.each do |n|
id = n.dig('id')
id = id[0...7]
msg = n.dig('message').lines[0].chomp
author = n.dig 'committer', 'name'
response << "#{author} — #{msg} [#{id}]"
end
response << "and #{commits.length - 3} commits..."
else
commits.each do |n|
id = n.dig('id')
id = id[0...7]
msg = n.dig('message').lines[0].chomp
author = n.dig 'committer', 'name'
response << "#{author} — #{msg} [#{id}]"
end
end
else
'format not implemented'
end
response
end
|