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
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/stalkerr/target/github.rb', line 48
def parse(event)
obj = event.payload
repository = event.repo.name
status = title = link = ''
body = []
notice = false
case event.type
when 'CommitCommentEvent'
status = "commented on commit"
title = "#{obj..path}"
body = obj..body.split_by_crlf if obj..body
link = obj..html_url
when 'PullRequestReviewCommentEvent'
status = "commented on pull request"
if obj..pull_request_url
pull_id = obj..pull_request_url.match(/\/pulls\/([0-9]+)/)[1]
pull = client.pull(event.repo.name, pull_id)
title = "#{pull.title}: #{obj..path}"
else
title = obj..path
end
body = obj..body.split_by_crlf if obj..body
link = obj..html_url
when 'IssueCommentEvent'
if obj.action == 'created'
status = "commented on issue ##{obj.issue.number}"
title = obj.issue.title
else
status = "#{obj.action} issue comment"
end
body = obj..body.split_by_crlf if obj..body
link = obj..html_url
when 'IssuesEvent'
status = "#{obj.action} issue ##{obj.issue.number}"
title = obj.issue.title
body = obj.issue.body.split_by_crlf if obj.issue.body
body << "assignee: #{obj.issue.assignee.login}" if obj.issue.assignee
body << "milestone: #{obj.issue.milestone.title}[#{obj.issue.milestone.state}]" if obj.issue.milestone
link = obj.issue.html_url
when 'PullRequestEvent'
status = "#{obj.action} pull request ##{obj.number}"
title = obj.pull_request.title
body = obj.pull_request.body.split_by_crlf if obj.pull_request.body
link = obj.pull_request.html_url
when 'PushEvent'
notice = true
status = "pushed to #{obj.ref.gsub('refs/heads/', '')}"
obj.commits.each do |commit|
verbose_commit = client.commit(event.repo.name, commit.sha)
name = verbose_commit.author ? verbose_commit.author.login : commit.author.name
url = "#{client.web_endpoint}#{event.repo.name}/commit/#{commit.sha}"
line = "#{name.to_irc_color.silver}: #{commit.message}"
line << " - #{shorten(url).to_irc_color.blue}"
body = line.split_by_crlf
end
link = "#{client.web_endpoint}#{event.repo.name}"
when 'CreateEvent'
if obj.ref_type.eql? 'repository'
repository = nil
status = "created repository"
title = event.repo.name
title = "#{title}: #{obj.description}" if obj.description
else
status = "created #{obj.ref_type}:#{obj.ref}"
title = obj.description
end
link = "#{client.web_endpoint}#{event.repo.name}"
when 'DeleteEvent'
status = "deleted #{obj.ref_type}:#{obj.ref}"
link = "#{client.web_endpoint}#{event.repo.name}"
when 'DownloadEvent'
status = "download #{obj.name}"
title = obj.description
link = obj.html_url
when 'ForkEvent'
status = "forked #{obj.forkee.full_name} [#{obj.forkee.language}]"
title = obj.forkee.description
link = obj.forkee.html_url
when 'TeamAddEvent'
status = "add team"
title = obj.team.name
when 'WatchEvent'
repository = nil
status = "#{obj.action} repository"
title = event.repo.name
link = "#{client.web_endpoint}#{event.repo.name}"
when 'FollowEvent'
repository = nil
notice = true
user = obj.target
status = "followed"
title = user.login
title = "#{title} (#{user.name})" if user.name && user.name != ''
profile = ["#{'repos'.to_irc_color.silver}: #{user.public_repos}"]
profile << "#{'followers'.to_irc_color.silver}: #{user.followers}"
profile << "#{'following'.to_irc_color.silver}: #{user.following}"
profile << "#{'location'.to_irc_color.silver}: #{user.location && user.location != '' ? user.location : '-'}"
profile << "#{'company'.to_irc_color.silver}: #{user.company && user.company != '' ? user.company : '-'}"
profile << "#{'bio'.to_irc_color.silver}: #{user.bio && user.bio != '' ? user.bio : '-'}"
profile << "#{'blog'.to_irc_color.silver}: #{user.blog && user.blog != '' ? user.blog : '-'}"
body << profile.join(', ')
link = "#{client.web_endpoint}#{user.login}"
when 'MemberEvent'
user = obj.member
status = "#{obj.action} member"
title = user.login
link = "#{client.web_endpoint}#{user.login}"
when 'GistEvent'
repository = nil
status = "#{obj.action}d gist"
title = obj.gist.description unless obj.gist.description.eql? ''
link = obj.gist.html_url
when 'DownloadEvent',
'ForkApplyEvent',
'GollumEvent',
'PublicEvent'
return false
end
unless status.empty?
color = case
when status.include?('created') then :pink
when status.include?('commented') then :yellow
when status.include?('pushed') then :lime
when status.include?('forked') then :orange
when status.include?('closed') then :brown
when status.include?('deleted') then :red
when status.include?('started') then :rainbow
when status.include?('followed') then :seven_eleven
else :aqua
end
status = status.to_irc_color.send(color)
end
unless body.eql? ''
if body.length > 20
body_footer = body[-3..-1]
body = body[0...15]
body << '-----8<----- c u t -----8<-----'
body = body + body_footer
end
end
{
event_id: event.id,
nick: event.actor.login,
status: status,
repository: repository,
link: link,
title: title,
body: body,
notice: notice
}
end
|