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 +4 -4
- data/Gemfile.lock +1 -1
- data/Readme.md +3 -0
- data/VERSION +1 -1
- data/lib/kitchen_hooks/app.rb +31 -48
- data/lib/kitchen_hooks/helpers.rb +2 -6
- data/web/views/app.erb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b231a360740fd42847f0b9d6ccf89f9fbee0b3ee
|
4
|
+
data.tar.gz: 643ee7d3385463afaf8b98f3139d5c36ec5e734f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fea85d09df6258f7711bd62f91925e6b1bd0ca0846e9a151b402950defa4e96141cc2f3c9b8b79ee1df4979aea5b5bd3faee5d5bfbdff4df5b1a8b441210856
|
7
|
+
data.tar.gz: 5d204a1a8d7468f98c872713f05a40a038d10779f8e45c09cd179de548e45e3e51d3a9cbd774f9cbdfeac1dd284dd730bb491afea3dbdb9795b778a0066645e3
|
data/Gemfile.lock
CHANGED
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.3.2
|
data/lib/kitchen_hooks/app.rb
CHANGED
@@ -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!
|
20
|
-
@@db = Daybreak::DB.new
|
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:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
155
|
+
def gitlab_url event
|
156
156
|
url = git_daemon_style_url(event).sub(/^git/, 'http').sub(/\.git$/, '')
|
157
|
-
|
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
|
-
<%
|
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
|
12
|
-
<h2><%=
|
13
|
-
<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><%=
|
16
|
-
<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"
|
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 %>
|