Last active
September 8, 2015 18:18
-
-
Save jackbravo/8554ed315127c7179c54 to your computer and use it in GitHub Desktop.
Auto-pull from a gitlab server everytime there is a push to your branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('REMOTE', '199.198.197.196'); # gitlab server | |
define('BRANCH', 'development'); | |
define('USER', 'remote_user'); # remote user with SSH keys to gitlab | |
openlog('gitlab', LOG_PID | LOG_ODELAY, LOG_LOCAL1); | |
if ($_SERVER['REMOTE_ADDR'] != REMOTE) { | |
syslog(LOG_NOTICE, 'Calling wrong git server ' . $_SERVER['REMOTE_ADDR']); | |
} | |
$data = json_decode(file_get_contents('php://input')); | |
if ($data->ref == 'refs/heads/' . BRANCH) { | |
$out = shell_exec('/usr/bin/sudo -u ' . USER . ' /usr/bin/git pull'); | |
syslog(LOG_NOTICE, $out); | |
} else { | |
syslog(LOG_NOTICE, $data->ref); | |
} | |
closelog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to add this line to the
/etc/sudoers
file: