Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 6 additions & 32 deletions plugins/github_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ class Cinch::GitHubWebhooks
# get event type from http header
event = request.env["HTTP_X_GITHUB_EVENT"]

# we ignore some events (TODO: use whitelist instead of blacklist)
halt 202 if [
'ping', # test, when enabling webhook
'gollum', # wiki changes
'deployment', # ?
'deployment_status', # ?
'label', # repository labels
'member', # collaborator added
'milestone', # repository milestones
'page_build', # github pages built
'project', # projects
'project_card', #
'project_column', #
'public', # repository visibility
'status', # internal git commit events
'team_add' # user added to team
].include? event

# get common info: affected repository and user
repo = data["repository"]["name"]
unless event == "push"
Expand Down Expand Up @@ -191,15 +173,16 @@ class Cinch::GitHubWebhooks
message << "…" if comment.length > 200

when "pull_request_review"
# review (can be with comment)
# review (have been with comment)

# we ignore possible other actions (that may be added in the future)
halt 202 unless data["action"] == "submitted"

# we ignore comments (since they are empty now)
halt 202 if data["review"]["state"] == "commented"

if data["review"]["state"] == "approved"
state = "\x0303approved\x0F"
elsif data["review"]["state"] == "commented"
state = "reviewed"
else
state = "\x0304requested changes\x0F"
end
Expand All @@ -214,14 +197,6 @@ class Cinch::GitHubWebhooks
data["pull_request"]["title"],
data["review"]["html_url"])

# add up to 200 characters of the comment, sans all whitespace
comment = data["review"]["body"]
unless comment.nil?
comment = comment.gsub(/\s+/,' ').strip
message << "\n> " + comment[0, 200] if comment.length > 0
message << "…" if comment.length > 200
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I can restore this block.

when "commit_comment"
# comment on commit

Expand Down Expand Up @@ -279,9 +254,8 @@ class Cinch::GitHubWebhooks
data["release"]["html_url"])

else
# something we do not know, yet
info "Error: Unknown '#{event}' event for #{repo} repository! :[]"
204
# we ignore all other events
halt 202
end

# output
Expand Down