shamebot 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/VERSION +1 -1
  4. data/bin/shamebot +81 -77
  5. metadata +1 -2
  6. data/Gemfile.lock +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26da6e6c4cbaf5c0a5fb4841993418e84c9430a9
4
- data.tar.gz: c3e8cdc7e23e98a26fdb3f2d05ba04a2d5a2e3c4
3
+ metadata.gz: f83fb7908bfd3f14054f70ab6c1ea71b42721c58
4
+ data.tar.gz: a375e607f8453d107e6f28fa88cf8e8bd22db538
5
5
  SHA512:
6
- metadata.gz: 25c55617c299cd2a631a57dd0362fc0c7c1594f1ad52951f0a948120d4df0f125af52956bad793c554d4837d0d20802c379cadbdf7e5e2983359a0ccd25d1b27
7
- data.tar.gz: 307b3b94f5e9cb1ed650b5f34ebc0056a1a8f812b97bd5d1d181594a5dfb221b1dd540dd8ed32550841253791725df76d225d2268b2ac445e182597f07124159
6
+ metadata.gz: ac399f2ee74bf0c01b81657ede3baded908c4b7bd5c1af88cf826416a0cc7d09a412235f6944f91b293b0a1547f9bcde5bf66c2e3fb774c109d1732b4e908c1d
7
+ data.tar.gz: 73251e56c83168cb725881fa977dd7501917dbcb9a91ebf3d6b185f8e5b7fd23562c8b4fa7118c47abe5b5dce97149f8e414210cffa2a3308fc580085b8a0a12
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  *.swp
6
6
  *.json
7
7
  *.log
8
+ *.lock
8
9
  .chef
9
10
  .kitchen
10
11
  .vagrant
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -98,91 +98,95 @@ end
98
98
 
99
99
 
100
100
  # Part 3. Take requests from Gitlab WebHooks
101
- require 'sinatra'
102
-
103
- set :port, Opts[:port]
104
- set :environment, Opts[:env]
105
- set :bind, Opts[:bind]
106
- set :raise_errors, true
107
- set :dump_errors, true
108
- set :show_exceptions, true
109
- set :logging, ::Logger::DEBUG if DEBUG
110
-
111
- get '/' do
112
- content_type :text
113
- "shamebot #{Shamebot::VERSION}"
114
- end
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
- now = Time.now
118
- last_half_hour = now - 30 * 60
119
- request.body.rewind
120
- data = JSON.parse request.body.read
121
-
122
- # Bad commits don't contain JIRA tags...
123
- # And they aren't merge commits
124
- commits = data['commits'].delete_if { |c| c['message'] =~ MERGE_COMMIT }
125
- good_commits, bad_commits = commits.partition { |c| c['message'] =~ JIRA_TAG }
126
-
127
- # Good commits might contain bogus JIRA tags
128
- bad_commits += good_commits.keep_if do |c|
129
- good_tag = false
130
- c['message'].scan(JIRA_TAG).each do |(project, number)|
131
- tag = '%s-%d' % [project.upcase, number.to_i]
132
- tag_page = `curl --silent http://jira.bluejeansnet.com/browse/#{tag}` rescue ''
133
- next if tag_page =~ /The issue you are trying to view does not exist/i
134
- good_tag = true
135
- break
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
- # Grab user info from Gitlab
141
- begin
142
- user = Gitlab.user(data['user_id'].to_i)
143
- rescue
144
- $stderr.puts "Warning: Gitlab user for commit author not found"
145
- return
146
- end
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
- # For whatever reason we get a lot of duplicate POSTs, so we need to
149
- # keep track of which commits have already triggered shamings so we
150
- # don't end up repeatedly shaming users for the same mistake. We also
151
- # make sure the commits aren't too old.
152
- new_bad_commits = []
153
- bad_commits.each do |commit|
154
- unless DEBUG
155
- next if DB.has_key? commit['id']
156
- commit_time = DateTime.strptime(commit['timestamp']).to_time
157
- next unless commit_time >= last_half_hour
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
- # Shame the user with a random template
164
- commit_ids = new_bad_commits.map { |c| c['id'] }
165
- commit_urls = new_bad_commits.map { |c| c['url'] }
166
- puts "%s: %s" % [ user.username, commit_ids.inspect ]
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
- hipchat_users = []
169
- 0.upto(5) do |i|
170
- 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']
171
- end
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
- hipchat_user = hipchat_users.select { |u| u['name'] =~ /#{user.name}/i }
174
- $stderr.puts hipchat_user
174
+ hipchat_user = hipchat_users.select { |u| u['name'] =~ /#{user.name}/i }
175
+ $stderr.puts hipchat_user
175
176
 
176
- if hipchat_user.empty?
177
- hipchat_user = user.name
178
- else
179
- hipchat_user = '@' + hipchat_user.first['mention_name']
180
- end
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
- shame_user(random_template, {
183
- :name => hipchat_user,
184
- :nick => user.username,
185
- :urls => commit_urls.join(' ')
186
- }, ROOM, HIPCHAT, BOTNAME) unless commit_ids.empty? || DEBUG
187
- return commit_ids.inspect
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.2
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
@@ -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