diff --git a/application/models/repository_model.php b/application/models/repository_model.php index f00e9bf..762232e 100755 --- a/application/models/repository_model.php +++ b/application/models/repository_model.php @@ -650,7 +650,7 @@ class Repository_model extends CI_Model "cd {$repositoryPath}", "git init --bare", "rm -r hooks", - "ln -s ../hooks hooks", + "ln -s ../../misc/hooks hooks", "chmod -R 0777 {$repositoryPath}", ]; break; @@ -661,7 +661,7 @@ class Repository_model extends CI_Model "git clone --bare {$command} .", "git remote remove origin", "rm -r hooks", - "ln -s ../hooks hooks", + "ln -s ../../misc/hooks hooks", "chmod -R 0777 {$repositoryPath}", ]; break; diff --git a/misc/hooks/main b/misc/hooks/main new file mode 100755 index 0000000..9007bcd --- /dev/null +++ b/misc/hooks/main @@ -0,0 +1,58 @@ +#!/usr/local/php/bin/php + $config['gateway']['hooks'], + 'token' => $config['gateway']['token'] + ]; +} else { + echo '[CodeFever Community]: Bad configuration, Contact site administrator if operation rejected!.'; + exit(255); +} + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, $config['endpoint']); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Token: ' . $config['token'], + 'Content-Type: application/json', + 'Accept: application/json', +]); +curl_setopt($ch, CURLOPT_POST, 1); + +$input = fopen('php://stdin', 'r'); +stream_set_blocking($input, 0); +$data = [ + 'uid' => getenv('PGYER_UID'), + 'args' => $argv, + 'stdin' => stream_get_contents($input) +]; + +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + +$response = curl_exec($ch); + +curl_close($ch); + +$result = json_decode($response, TRUE); + +if ($result) { + if (!$result['code']) { + if ($result['data'] && $result['data']['remote']) { + echo $result['data']['remote']; + } + exit(0); + } else { + echo 'Operation Stopped: '; + if ($result['data'] && $result['data']['remote']) { + echo $result['data']['remote'] . "\n"; + } + echo 'Request-ID: ' . $result['request-id'] . "\n"; + } +} else { + echo 'Contact site administrator if operation rejected!'; +} + +exit(255); diff --git a/misc/hooks/post-receive b/misc/hooks/post-receive new file mode 120000 index 0000000..88d050b --- /dev/null +++ b/misc/hooks/post-receive @@ -0,0 +1 @@ +main \ No newline at end of file diff --git a/misc/hooks/pre-receive b/misc/hooks/pre-receive new file mode 120000 index 0000000..88d050b --- /dev/null +++ b/misc/hooks/pre-receive @@ -0,0 +1 @@ +main \ No newline at end of file diff --git a/misc/hooks/update b/misc/hooks/update new file mode 120000 index 0000000..88d050b --- /dev/null +++ b/misc/hooks/update @@ -0,0 +1 @@ +main \ No newline at end of file