forked from VentureBeat/wpvip-hipchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-webhook.php
53 lines (41 loc) · 1.35 KB
/
deploy-webhook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
* WordPress VIP to HipChat Deploy Webhook
*
* Converts a web-hook request from WordPress VIP to an API call to HipChat for notification delivery.
*
* TODO: Cleanup the process and make the code more robust and extendable, this was a quick-hack first version
*/
/*
* Standard Variables / Constants
*/
$auth_token = '0440c72286921a139bc2ef2318b903';
$room_id = '198932';
/*
* The 'meat' of the functionality
*/
if( $_REQUEST['repo'] == 'vip' ) {
$fields = array(
'room_id' => urlencode($room_id),
'from' => urlencode('WordPress VIP'),
'message' => urlencode( '[VIP]['. $_REQUEST['theme'] .'] Deploy Notification (r/'. $_REQUEST['deployed_revision'] .') by '.$_REQUEST['deployer'] . '. >>' . $_REQUEST['revision_log']),
'notify' => 1,
'color' => urlencode('purple'),
'format' => urlencode('json'),
'auth_token' => urlencode( $auth_token ),
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, 'https://api.hipchat.com/v1/rooms/message');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
?>