-
Notifications
You must be signed in to change notification settings - Fork 9
Allow web-hooks to be configured to fire on test or deploy #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c580b78
ee51fa8
114c0e6
23c5ec0
42230f2
1dd82bc
732c935
7978f01
4954f7e
2a7aaca
6cd19d8
e5f9b1f
5104d89
db2dea3
2a01d08
a4c8d84
9b51c2c
d2b859a
48804b1
80b81de
f719e82
f9d245d
a2690f1
69dfece
9e2b2ea
d126b0e
fb857c5
7fc137b
7f970de
cb07912
f6f4b45
59eb646
db6e770
1311f8e
9fda18d
9d5e346
1f8509a
454b4c7
213189b
e196fc5
b77a97d
a08cc25
a2a3a2f
1b6be53
72f88ab
604490a
aef361d
620cfa3
2589d8b
0e43845
6a41da7
a0c6bd7
4c11c91
e9e4d31
355987b
63d36d4
4cf3886
b7ca04c
f77902b
587f8e9
f2552f9
720bad4
553483b
3494da1
4339003
3353a9d
d015949
dd134d1
edb8161
885c03b
bae5201
0ae6b93
d62a842
029ace9
a5cd3aa
dd80c2b
116a5cc
a6a790c
16dbf0c
7fc4095
e84a918
0d2566b
ab54857
f6d9fec
d5122ef
7ead023
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,63 @@ | ||
<div id="project_config_webhooks" class="well"> | ||
<div id="project_config_webhooks" class="tab-pane well"> | ||
<fieldset> | ||
<legend>Webhooks</legend> | ||
<div class="alert alert-success hide"></div> | ||
<p> | ||
Target URLs will receive a HTTP POST from Strider | ||
with a JSON payload on each project test run. These | ||
enable you to receive and process real-time push | ||
notifications from our system. Push notifications | ||
are signed cryptographically with HMAC-SHA1 using a | ||
shared secret so you can verify their | ||
authenticity. Signatures are transmitted in | ||
the | ||
<a href="http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify"> | ||
X-Signature-Hub header. | ||
</a> | ||
<a href="https://gist.github.com/3029840">See a sample payload.</a> | ||
</p> | ||
<div class="row-fluid"> | ||
<div class="span9"> | ||
Target URLs will receive a HTTP POST from Strider | ||
with a JSON payload on each project test run. These | ||
enable you to receive and process real-time push | ||
notifications from our system. Push notifications | ||
are signed cryptographically with HMAC-SHA1 using a | ||
shared secret so you can verify their | ||
authenticity. Signatures are transmitted in | ||
the | ||
<a href="http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify"> | ||
X-Signature-Hub header. | ||
</a> | ||
<a href="https://gist.github.com/3029840">See a sample payload.</a> | ||
</p> | ||
<table class="table"> | ||
<thead> | ||
<th>Hook Title</th> | ||
<th>TargetURL for HTTP Post</th> | ||
<th>Shared secret for HMAC-SHA1 signature</th> | ||
<th>Hook Trigger</th> | ||
<th>Delete</th> | ||
</thead> | ||
<tbody> | ||
|
||
<tr ng-repeat-start="hook in hooks"> | ||
<td><input ng-model="hook.title"></td> | ||
<td><input ng-model="hook.url"</td> | ||
<td><input ng-model="hook.secret"></td> | ||
<td class="remove"> | ||
<button class="btn btn-danger" ng-disabled="saving" ng-click="remove(hook)"> | ||
<i class="icon-remove"></i> | ||
</button> | ||
</td> | ||
</tr> | ||
<tr ng-repeat-end> | ||
<td colspan="4"> | ||
<textarea | ||
placeholder="You can put a custom payload format here" | ||
ng-model="hook.format"> | ||
</textarea> | ||
</td> | ||
<form class="form-inline"> | ||
<td><input type="text" ng-model="hook.title"></td> | ||
<td><input type="text" ng-model="hook.url"></td> | ||
<td><input type="text" ng-model="hook.secret"></td> | ||
<td> | ||
<label class="radio inline"> | ||
<input type="radio" value="test" ng-model="hook.trigger"> Test | ||
</label> | ||
<label class="radio inline"> | ||
<input type="radio" value="deploy" ng-model="hook.trigger"> Deploy | ||
</label> | ||
</td> | ||
<td> | ||
<button class="btn-sm btn-danger" ng-disabled="saving" ng-click="remove(hook)"> | ||
<i class="icon-remove"></i> | ||
</button> | ||
</td> | ||
<tr> | ||
<td colspan="4"> | ||
<textarea | ||
placeholder="You can put a custom payload format here" | ||
ng-model="hook.format"> | ||
</textarea> | ||
</td> | ||
</tr> | ||
</form> | ||
</tr> | ||
<tr ng-repeat-end></tr> | ||
</tbody> | ||
</table> | ||
<button class="btn btn-success" ng-click="add()" ng-disabled="saving">Add</button> | ||
<button class="btn" ng-click="save()" ng-disabled="saving">Save Hooks</button> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
|
||
#project_config_webhooks { | ||
.input-append { | ||
input { | ||
display: block; | ||
width: 100%; | ||
} | ||
} | ||
|
||
textarea { | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
|
||
table { | ||
width: 100%; | ||
} | ||
|
||
fieldset { | ||
max-width: 970px; | ||
} | ||
|
||
.icon-remove { | ||
padding-left: 0px; | ||
padding-right: 0px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,50 @@ module.exports = { | |
var hooks = utils.makeWebHooks(config || [], job) | ||
cb(null, { | ||
listen: function (io, context) { | ||
function onTested(id, data) { | ||
io.removeListener('job.status.tested', onTested) | ||
io.on('job.status.tested', onTested) | ||
|
||
// add deploy listener if job will be deploying | ||
if(job.type === 'TEST_AND_DEPLOY'){ | ||
io.on('job.status.deployed', onDeployed) | ||
} | ||
|
||
function onTested (id, data){ | ||
hooks.forEach(function (hook) { | ||
context.comment('Firing webhook ' + hook.title) | ||
try { | ||
var payload = hook.prepare(data, job) | ||
io.emit('plugin.webhooks.fire', hook.url, hook.secret, payload) | ||
} catch (e) { | ||
context.comment('Failed to prepare webhook payload: ' + e.message); | ||
return | ||
if(hook.trigger === 'test'){ | ||
context.comment('Firing Test webhook ' + hook.title) | ||
try { | ||
var payload = hook.prepare(data, job) | ||
io.emit('plugin.webhooks.fire', hook.url, hook.secret, payload) | ||
} catch (e) { | ||
context.comment('Failed to prepare webhook payload: ' + e.message); | ||
} | ||
} | ||
}); | ||
//always remove test listener | ||
io.removeListener('job.status.tested', onTested); | ||
//remove deploy listener if tests failed and one was registered | ||
if (data.exitCode !== 0 && job.type === 'TEST_AND_DEPLOY'){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the tests failed and a deploy listener was registered we need to remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you put these notes in as comments? |
||
io.removeListener('job.status.deployed', onDeployed); | ||
} | ||
} | ||
|
||
function onDeployed (id, data){ | ||
hooks.forEach(function (hook) { | ||
if(hook.trigger === 'deploy'){ | ||
context.comment('Firing Deploy webhook ' + hook.title) | ||
try { | ||
var payload = hook.prepare(data, job) | ||
payload['deploy_exitcode'] = (data.exitCode === 0) ? 0 : 1 | ||
io.emit('plugin.webhooks.fire', hook.url, hook.secret, payload) | ||
} catch (e) { | ||
context.comment('Failed to prepare webhook payload: ' + e.message); | ||
} | ||
} | ||
}) | ||
//always remove deploy listener | ||
io.removeListener('job.status.deployed', onDeployed); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if onDeployed is called remove listener after firing hooks |
||
} | ||
io.on('job.status.tested', onTested) | ||
} | ||
}) | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only register the deploy listener if the job is going to deploy.