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
|
# File 'lib/stalkerr/target/github.rb', line 41
def parse(event)
obj = event.payload
= status = title = link = ''
body = []
none_repository = false
notice_body = false
case event.type
when 'CommitCommentEvent'
status = "commented on commit"
title = "#{obj.comment.path}"
body = body + (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.comment.path}"
else
title = obj..path
end
body = body + (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 = body + (obj..body)
link = obj..html_url
when 'IssuesEvent'
status = "#{obj.action} issue ##{obj.issue.number}"
title = obj.issue.title
body = body + (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 = body + (obj.pull_request.body)
link = obj.pull_request.html_url
when 'PushEvent'
notice_body = 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 = "#{HOST}/#{event.repo.name}/commit/#{commit.sha}"
line = "#{StringIrc.new(name).silver}: #{commit.message}"
line << " - #{StringIrc.new(shorten url).blue}"
body = body + (line)
end
link = "#{HOST}/#{event.repo.name}"
when 'CreateEvent'
if obj.ref_type.eql? 'repository'
none_repository = true
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 = "#{HOST}/#{event.repo.name}"
when 'DeleteEvent'
status = "deleted #{obj.ref_type}:#{obj.ref}"
link = "#{HOST}/#{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'
none_repository = true
status = "#{obj.action} repository"
title = event.repo.name
link = "#{HOST}/#{event.repo.name}"
when 'FollowEvent'
none_repository = true
notice_body = true
user = obj.target
status = "followed"
title = user.login
title = "#{title} (#{user.name})" if user.name && user.name != ''
profile = ["#{StringIrc.new('repos').silver}: #{user.public_repos}"]
profile << "#{StringIrc.new('followers').silver}: #{user.followers}"
profile << "#{StringIrc.new('following').silver}: #{user.following}"
profile << "#{StringIrc.new('location').silver}: #{user.location && user.location != '' ? user.location : '-'}"
profile << "#{StringIrc.new('company').silver}: #{user.company && user.company != '' ? user.company : '-'}"
profile << "#{StringIrc.new('bio').silver}: #{user.bio && user.bio != '' ? user.bio : '-'}"
profile << "#{StringIrc.new('blog').silver}: #{user.blog && user.blog != '' ? user.blog : '-'}"
body << profile.join(', ')
link = "#{HOST}/#{user.login}"
when 'MemberEvent'
user = obj.member
status = "#{obj.action} member"
title = user.login
link = "#{HOST}/#{user.login}"
when 'GistEvent'
none_repository = true
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
nick = event.actor.login
unless status.eql? ''
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
= StringIrc.new(status).send(color)
= "(#{event.repo.name}) #{header}" unless none_repository
end
= "#{header} #{title}" unless title.eql? ''
= "#{header} - #{StringIrc.new(shorten link).blue}" unless link.eql? ''
@post.call nick, NOTICE, CHANNEL, unless .eql? ''
mode = notice_body ? NOTICE : PRIVMSG
body.each { |b| @post.call nick, mode, CHANNEL, b } unless body.eql? ''
event.id
end
|