shamebot 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/bin/shamebot +81 -77
- metadata +1 -2
- data/Gemfile.lock +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83fb7908bfd3f14054f70ab6c1ea71b42721c58
|
4
|
+
data.tar.gz: a375e607f8453d107e6f28fa88cf8e8bd22db538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac399f2ee74bf0c01b81657ede3baded908c4b7bd5c1af88cf826416a0cc7d09a412235f6944f91b293b0a1547f9bcde5bf66c2e3fb774c109d1732b4e908c1d
|
7
|
+
data.tar.gz: 73251e56c83168cb725881fa977dd7501917dbcb9a91ebf3d6b185f8e5b7fd23562c8b4fa7118c47abe5b5dce97149f8e414210cffa2a3308fc580085b8a0a12
|
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/bin/shamebot
CHANGED
@@ -98,91 +98,95 @@ end
|
|
98
98
|
|
99
99
|
|
100
100
|
# Part 3. Take requests from Gitlab WebHooks
|
101
|
-
require 'sinatra'
|
102
|
-
|
103
|
-
|
104
|
-
set :
|
105
|
-
set :
|
106
|
-
set :
|
107
|
-
set :
|
108
|
-
set :
|
109
|
-
set :
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
101
|
+
require 'sinatra/base'
|
102
|
+
|
103
|
+
class Shamebot::App < Sinatra::Application
|
104
|
+
set :port, Opts[:port]
|
105
|
+
set :environment, Opts[:env]
|
106
|
+
set :bind, Opts[:bind]
|
107
|
+
set :raise_errors, true
|
108
|
+
set :dump_errors, true
|
109
|
+
set :show_exceptions, true
|
110
|
+
set :logging, ::Logger::DEBUG if DEBUG
|
111
|
+
|
112
|
+
get '/' do
|
113
|
+
content_type :text
|
114
|
+
"shamebot #{Shamebot::VERSION}"
|
115
|
+
end
|
115
116
|
|
116
|
-
post '/' do
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
117
|
+
post '/' do
|
118
|
+
now = Time.now
|
119
|
+
last_half_hour = now - 30 * 60
|
120
|
+
request.body.rewind
|
121
|
+
data = JSON.parse request.body.read
|
122
|
+
|
123
|
+
# Bad commits don't contain JIRA tags...
|
124
|
+
# And they aren't merge commits
|
125
|
+
commits = data['commits'].delete_if { |c| c['message'] =~ MERGE_COMMIT }
|
126
|
+
good_commits, bad_commits = commits.partition { |c| c['message'] =~ JIRA_TAG }
|
127
|
+
|
128
|
+
# Good commits might contain bogus JIRA tags
|
129
|
+
bad_commits += good_commits.keep_if do |c|
|
130
|
+
good_tag = false
|
131
|
+
c['message'].scan(JIRA_TAG).each do |(project, number)|
|
132
|
+
tag = '%s-%d' % [project.upcase, number.to_i]
|
133
|
+
tag_page = `curl --silent http://jira.bluejeansnet.com/browse/#{tag}` rescue ''
|
134
|
+
next if tag_page =~ /The issue you are trying to view does not exist/i
|
135
|
+
good_tag = true
|
136
|
+
break
|
137
|
+
end
|
138
|
+
!good_tag
|
136
139
|
end
|
137
|
-
!good_tag
|
138
|
-
end
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
# Grab user info from Gitlab
|
142
|
+
begin
|
143
|
+
user = Gitlab.user(data['user_id'].to_i)
|
144
|
+
rescue
|
145
|
+
$stderr.puts "Warning: Gitlab user for commit author not found"
|
146
|
+
return
|
147
|
+
end
|
147
148
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
149
|
+
# For whatever reason we get a lot of duplicate POSTs, so we need to
|
150
|
+
# keep track of which commits have already triggered shamings so we
|
151
|
+
# don't end up repeatedly shaming users for the same mistake. We also
|
152
|
+
# make sure the commits aren't too old.
|
153
|
+
new_bad_commits = []
|
154
|
+
bad_commits.each do |commit|
|
155
|
+
unless DEBUG
|
156
|
+
next if DB.has_key? commit['id']
|
157
|
+
commit_time = DateTime.strptime(commit['timestamp']).to_time
|
158
|
+
next unless commit_time >= last_half_hour
|
159
|
+
end
|
160
|
+
new_bad_commits << commit
|
161
|
+
DB[commit['id']] = true
|
158
162
|
end
|
159
|
-
new_bad_commits << commit
|
160
|
-
DB[commit['id']] = true
|
161
|
-
end
|
162
163
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
# Shame the user with a random template
|
165
|
+
commit_ids = new_bad_commits.map { |c| c['id'] }
|
166
|
+
commit_urls = new_bad_commits.map { |c| c['url'] }
|
167
|
+
puts "%s: %s" % [ user.username, commit_ids.inspect ]
|
167
168
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
hipchat_users = []
|
170
|
+
0.upto(5) do |i|
|
171
|
+
hipchat_users += HTTParty.get("https://api.hipchat.com/v2/user", :query => { 'start-index' => 100 * i, :start_index => 100 * i, 'max-results' => 100, :max_results => 1000, :auth_token => CONFIG['hipchat']['auth_token_v2'] })['items']
|
172
|
+
end
|
172
173
|
|
173
|
-
|
174
|
-
|
174
|
+
hipchat_user = hipchat_users.select { |u| u['name'] =~ /#{user.name}/i }
|
175
|
+
$stderr.puts hipchat_user
|
175
176
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
177
|
+
if hipchat_user.empty?
|
178
|
+
hipchat_user = user.name
|
179
|
+
else
|
180
|
+
hipchat_user = '@' + hipchat_user.first['mention_name']
|
181
|
+
end
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
shame_user(random_template, {
|
184
|
+
:name => hipchat_user,
|
185
|
+
:nick => user.username,
|
186
|
+
:urls => commit_urls.join(' ')
|
187
|
+
}, ROOM, HIPCHAT, BOTNAME) unless commit_ids.empty? || DEBUG
|
188
|
+
return commit_ids.inspect
|
189
|
+
end
|
188
190
|
end
|
191
|
+
|
192
|
+
Shamebot::App.run!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shamebot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Clemmer
|
@@ -89,7 +89,6 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- Gemfile
|
92
|
-
- Gemfile.lock
|
93
92
|
- Rakefile
|
94
93
|
- Readme.md
|
95
94
|
- VERSION
|
data/Gemfile.lock
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
shamebot (1.0.0)
|
5
|
-
gitlab (~> 3.1.0)
|
6
|
-
hipchat (~> 1)
|
7
|
-
sinatra (~> 1)
|
8
|
-
sys-proctable (~> 0)
|
9
|
-
trollop (~> 2)
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: https://rubygems.org/
|
13
|
-
specs:
|
14
|
-
coderay (1.1.0)
|
15
|
-
gitlab (3.1.0)
|
16
|
-
httparty
|
17
|
-
terminal-table
|
18
|
-
hipchat (1.4.0)
|
19
|
-
httparty
|
20
|
-
httparty (0.13.3)
|
21
|
-
json (~> 1.8)
|
22
|
-
multi_xml (>= 0.5.2)
|
23
|
-
json (1.8.1)
|
24
|
-
method_source (0.8.2)
|
25
|
-
minitest (5.5.0)
|
26
|
-
multi_xml (0.5.5)
|
27
|
-
pry (0.10.1)
|
28
|
-
coderay (~> 1.1.0)
|
29
|
-
method_source (~> 0.8.1)
|
30
|
-
slop (~> 3.4)
|
31
|
-
rack (1.6.0)
|
32
|
-
rack-protection (1.5.3)
|
33
|
-
rack
|
34
|
-
rake (10.4.2)
|
35
|
-
rubygems-tasks (0.2.4)
|
36
|
-
sinatra (1.4.5)
|
37
|
-
rack (~> 1.4)
|
38
|
-
rack-protection (~> 1.4)
|
39
|
-
tilt (~> 1.3, >= 1.3.4)
|
40
|
-
slop (3.6.0)
|
41
|
-
sys-proctable (0.9.4)
|
42
|
-
terminal-table (1.4.5)
|
43
|
-
tilt (1.4.1)
|
44
|
-
trollop (2.0)
|
45
|
-
version (1.0.0)
|
46
|
-
yard (0.8.7.6)
|
47
|
-
|
48
|
-
PLATFORMS
|
49
|
-
ruby
|
50
|
-
|
51
|
-
DEPENDENCIES
|
52
|
-
minitest
|
53
|
-
pry
|
54
|
-
rake
|
55
|
-
rubygems-tasks
|
56
|
-
shamebot!
|
57
|
-
version
|
58
|
-
yard
|