kitchen_hooks 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f53d2fc0be5382749dc1fdea991bbbeeea94ec0
4
- data.tar.gz: 3d04c7e25053c5462b0759b35603ce74f7896f21
3
+ metadata.gz: b231a360740fd42847f0b9d6ccf89f9fbee0b3ee
4
+ data.tar.gz: 643ee7d3385463afaf8b98f3139d5c36ec5e734f
5
5
  SHA512:
6
- metadata.gz: 23a54b5efb5d6cee545b1a95927f8891573db8e8688cbf2703f26cc69e196010c69a4215be4c101e6b0c2540155dd71acc95337cf515cec5961bfe919bcb8bfb
7
- data.tar.gz: 5f9a71504316534dcc798f794ab4a915010df9713a1c966cf8f1587ebecd120965010cf812adc698ff25c3baef49bb27aa864e9b97d713934d14cd3eaeec80c6
6
+ metadata.gz: 7fea85d09df6258f7711bd62f91925e6b1bd0ca0846e9a151b402950defa4e96141cc2f3c9b8b79ee1df4979aea5b5bd3faee5d5bfbdff4df5b1a8b441210856
7
+ data.tar.gz: 5d204a1a8d7468f98c872713f05a40a038d10779f8e45c09cd179de548e45e3e51d3a9cbd774f9cbdfeac1dd284dd730bb491afea3dbdb9795b778a0066645e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kitchen_hooks (1.3.0)
4
+ kitchen_hooks (1.3.1)
5
5
  berkshelf (~> 3)
6
6
  chef (~> 11.16.4)
7
7
  daybreak (~> 0.3)
data/Readme.md CHANGED
@@ -40,6 +40,9 @@ Use the `server` command to start the WebHook receiver:
40
40
  ### 1.3
41
41
 
42
42
  * Added local database to store history (Daybreak), visualized on homepage
43
+ * Added `database` option to `server` command
44
+ * Corrected GitLab link for tagged commits
45
+ * Process events in the background to avoid duplicate entries [INF-6040]
43
46
 
44
47
  ### 1.2
45
48
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.3.2
@@ -1,4 +1,5 @@
1
1
  require 'pathname'
2
+ require 'thread'
2
3
  require 'json'
3
4
 
4
5
  require 'daybreak'
@@ -16,26 +17,8 @@ module KitchenHooks
16
17
 
17
18
  include KitchenHooks::Helpers
18
19
 
19
- def self.db! db_path
20
- @@db = Daybreak::DB.new db_path
21
- end
22
-
23
- def db &block
24
- if block_given?
25
- @@db.synchronize do
26
- yield
27
- end
28
- else
29
- return @@db
30
- end
31
- end
32
-
33
- def database
34
- db_entries = {}
35
- db.each do |k, v|
36
- db_entries[k] = v
37
- end
38
- return db_entries.sort_by { |stamp, _| stamp }
20
+ def self.db! path
21
+ @@db = Daybreak::DB.new path
39
22
  end
40
23
 
41
24
  def self.config! config
@@ -44,12 +27,14 @@ module KitchenHooks
44
27
  end
45
28
  end
46
29
 
47
- def knives ; @@knives ||= [] end
48
-
49
30
 
50
31
  get '/' do
32
+ db_entries = {}
33
+ db.each do |k, v|
34
+ db_entries[k] = v
35
+ end
51
36
  erb :app, locals: {
52
- database: database
37
+ database: db_entries.sort_by { |stamp, _| stamp }
53
38
  }
54
39
  end
55
40
 
@@ -63,50 +48,48 @@ module KitchenHooks
63
48
  :disposition => 'inline'
64
49
  end
65
50
 
66
-
67
51
  post '/' do
68
52
  request.body.rewind
69
53
  event = JSON::parse request.body.read
54
+ Thread.new do
55
+ process event
56
+ end
57
+ end
58
+
59
+
60
+ private
61
+ def knives ; @@knives ||= [] end
62
+
63
+ def db ; @@db end
70
64
 
65
+ def mark event, type
66
+ db.synchronize do
67
+ db[Time.now.to_f] = {
68
+ type: type,
69
+ event: event
70
+ }
71
+ end
72
+ end
73
+
74
+ def process event
71
75
  if commit_to_kitchen?(event)
72
76
  perform_kitchen_upload(event, knives)
73
- save_event \
74
- type: 'kitchen upload',
75
- author: author(event),
76
- repo: repo_name(event),
77
- raw: event
77
+ mark event, 'kitchen upload'
78
78
  end
79
79
 
80
80
  if tagged_commit_to_cookbook?(event) &&
81
81
  tag_name(event) =~ /^v\d+/ # Tagged with version we're releasing
82
82
  perform_cookbook_upload(event, knives)
83
- save_event \
84
- type: 'cookbook upload',
85
- author: author(event),
86
- repo: repo_name(event),
87
- cookbook: cookbook_name(event),
88
- raw: event
83
+ mark event, 'cookbok upload'
89
84
  end
90
85
 
91
86
  if tagged_commit_to_realm?(event) &&
92
87
  tag_name(event) =~ /^bjn_/ # Tagged with environment we're pinning
93
88
  perform_constraint_application(event, knives)
94
- save_event \
95
- type: 'constraint application',
96
- author: author(event),
97
- repo: repo_name(event),
98
- cookbook: cookbook_name(event),
99
- raw: event
89
+ mark event, 'constraint application'
100
90
  end
101
91
 
102
92
  db.flush
103
93
  end
104
-
105
- private
106
- def save_event e
107
- db do
108
- db[Time.now.to_f] = e
109
- end
110
- end
111
94
  end
112
95
  end
@@ -152,13 +152,9 @@ module KitchenHooks
152
152
  event['repository']['url'].sub(':', '/').sub('@', '://')
153
153
  end
154
154
 
155
- def gitlab_url event, commit_method
155
+ def gitlab_url event
156
156
  url = git_daemon_style_url(event).sub(/^git/, 'http').sub(/\.git$/, '')
157
- if commit_method == :tagged_commit
158
- "#{url}/commits/#{self.send(commit_method, event)}"
159
- else
160
- "#{url}/commit/#{self.send(commit_method, event)}"
161
- end
157
+ "#{url}/commit/#{event['after']}"
162
158
  end
163
159
 
164
160
  def latest_commit event
data/web/views/app.erb CHANGED
@@ -1,6 +1,7 @@
1
1
  <section id="cd-timeline" class="cd-container">
2
- <% database.reverse.each do |entry| %>
3
- <% timestamp, data = entry %>
2
+ <% database.reverse.each do |(timestamp, entry)| %>
3
+ <% type = entry[:type] %>
4
+ <% event = entry[:event] %>
4
5
  <% timestamp = timestamp.to_f %>
5
6
  <% datetime = Time.at(timestamp).iso8601 %>
6
7
  <div class="cd-timeline-block">
@@ -8,14 +9,14 @@
8
9
  <img src="/vendor/img/cd-icon.svg" alt="Picture">
9
10
  </div>
10
11
  <div class="cd-timeline-content">
11
- <% if data[:type] == 'kitchen upload' %>
12
- <h2><%= data[:type] %></h2>
13
- <p><%= data[:author] %> modified <a href="<%= gitlab_url(data[:raw], :latest_commit) %>"><%= data[:repo] %></a></p>
12
+ <% if type == 'kitchen upload' %>
13
+ <h2><%= type %></h2>
14
+ <p><%= author(event) %> modified <a href="<%= gitlab_url(event) %>">the Kitchen</a></p>
14
15
  <% else %>
15
- <h2><%= data[:type] %></h2>
16
- <p><%= data[:author] %> modified <a href="<%= gitlab_url(data[:raw], :tagged_commit) %>"><%= data[:repo] %></a></p>
16
+ <h2><%= type %></h2>
17
+ <p><%= author(event) %> modified <a href="<%= gitlab_url(event) %>"><%= repo_name(event) %></a></p>
17
18
  <% end %>
18
- <span class="cd-date">Triggered <time datetime="<%= datetime %>" pubdate="pubdate" class="time-ago" title="<%= datetime %>"><%= datetime %></time></span>
19
+ <span class="cd-date"><time datetime="<%= datetime %>" pubdate="pubdate" class="time-ago" title="<%= datetime %>"><%= datetime %></time></span>
19
20
  </div>
20
21
  </div>
21
22
  <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Wong