Skip to content

Instantly share code, notes, and snippets.

@jackbravo
Last active September 8, 2015 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbravo/8554ed315127c7179c54 to your computer and use it in GitHub Desktop.
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
<?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();
@jackbravo
Copy link
Author

You need to add this line to the /etc/sudoers file:

www-data ALL=(ALL) NOPASSWD: /usr/bin/git pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment