-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
68 lines (57 loc) · 1.68 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
header('Content-Type: text/plain');
if (isset($_REQUEST['payload']))
{
$payload = json_decode(stripslashes($_REQUEST['payload']));
list($refs, $type, $name) = explode('/', $payload->ref);
$hash = $payload->after;
}
elseif (isset($_GET['type'], $_GET['name'], $_GET['hash']))
{
$refs = 'refs';
$type = $_GET['type'];
$name = $_GET['name'];
$hash = $_GET['hash'];
}
else
{
die('missing arguments');
}
if ($refs == 'refs' && $type == 'tags')
{
echo 'working dir: ', getcwd(), "\n";
$res = system(getcwd() . '/repack ' . $name . ' ' . substr($hash, 0, 7), $status);
if (false === $res)
die('system failed');
echo 'status: ', $status, "\n";
}
die('done');
$payload = json_decode(stripslashes($_REQUEST['payload']));
list($refs, $type, $name) = explode('/', $payload->ref);
if ($refs == 'refs')
{
switch ($type)
{
case 'tags':
system('repack');
/*
$message = "Created tag '$name'";
$zip_url = 'https://github.com/md2perpe/hook-test/zipball/' . $name;
$tmp_path = tempnam('/tmp', 'hook-test-');
mail('[email protected]', 'GitHub Hook', '$zip_url = ' . $zip_url . "\n" . '$tmp_path = ' . $tmp_path);
rename($zip_url, $tmp_path);
mail('[email protected]', 'GitHub Hook', 'Renamed $zip_url = ' . $zip_url . ' to ' . '$tmp_path = ' . $tmp_path);
chdir(dirname($tmp_path));
system('unzip ' . basename($tmp_path));
$tmp_content = `ls $tmp_path`;
mail('[email protected]', 'GitHub Hook', '$tmp_content = ' . $tmp_content);
*/
break;
default:
$message = "Pushed to '{$payload->ref}'";
break;
}
}
echo '<p>Sending mail with $_REQUEST</p>';
mail('[email protected]', 'GitHub Hook', $message . "\n\n" . print_r($payload, true));
echo '<p>Done</p>';