This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.rb
73 lines (61 loc) · 2.33 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
require 'bundler/setup'
require 'sinatra'
require 'json'
require 'httparty'
require 'active_support/core_ext/hash/indifferent_access'
require File.expand_path("../github", __FILE__)
require File.expand_path("../comment_helper", __FILE__)
class Spreebot < Sinatra::Base
attr_reader :payload
before do
@payload = JSON.parse(request.body.read).with_indifferent_access
@gh = Github.new
end
post "/github" do
content_type :json
repo = payload['repository']
repo_name = repo['full_name']
action = payload['action']
issue = payload['issue']
issue_number = issue['number'] if issue
context = payload['context']
commit = payload['commit']
description = payload['description']
event = env['HTTP_X_GITHUB_EVENT']
if issue
# remove any unofficial labels
@gh.remove_invalid_labels(repo_name, issue_number)
# add the unverified label if it's a new issue
@gh.mark_issue_unverified(repo_name, issue_number) if action == 'opened'
end
if event == 'issue_comment' and action == 'created'
comment_body = payload['comment']['body'].downcase
comment_user = payload['comment']['user']['login']
# check for rejection comments
if(label = CommentHelper.parse_body(comment_body,"reject"))
@gh.close_and_label_issue(repo_name, issue_number, comment_user, label)
end
# check for triage comments
if(label = CommentHelper.parse_body(comment_body,"triage"))
if label == "security"
@gh.redact_and_email_security_issue(repo_name, issue_number)
else
@gh.create_issue_label(repo_name, issue_number, label)
@gh.remove_issue_label(repo_name, issue_number, 'unverified') if label == 'verified'
end
end
# check for close comments
if(label = CommentHelper.parse_body(comment_body,"close"))
@gh.close_and_label_issue(repo_name, issue_number, comment_user, label)
@gh.remove_issue_label(repo_name, issue_number, 'unverified')
end
end
if event == 'issues'
# label the issue if it has been reopened
@gh.create_issue_label(repo_name, issue_number, 'reopened') if action == 'reopened'
# removed the 'reopened' label when closing (if applicable)
@gh.remove_issue_label(repo_name, issue_number, 'reopened') if action == 'closed'
end
"OK\n"
end
end