Create a webhook to automate pull events on remote server

Hello!

Just as the title reads… anyone has done a similar task?? I tried to do it by my self with no good results, I’m running Gitea 1.9.0+dev-311-gfb4438a81 on a VPS.

I did as follows… Created a webhook under the repository configuration and pointed the Target URL to my VPS: http://123.456.78.9/pull.php, the rest of the webhook config is the default, HTTP Method, POST Content Type and so on.

On the server, I’ve created the file pull.php with this content

<?php
if ($_POST[‘payload’]) {

  • shell_exec(‘cd /path/to/the/project/ && git reset --hard HEAD && git pull’);*
  • echo ‘Execution Success’;*
    } else {
  • echo ‘Execution Failed’;*
    }
    ?>

When I do git push the pull.php it’s supposed to catch the data, but if I do var_dump($_POST); instead the code above it returns

array(0){
}

Any help would be appreciated

regards

Try to look at what it sent to your page.
Go to <your_repo> -> Settings -> Webhooks, then click at your webhook, then scroll to the end of the page, to ’ Recent Deliveries’, then click to the latest (upper) one. There you can see exact headers and content which were sent to you page.

If you don’t mind exposing data too much you could use https://webhook.site/ as a testing target to check if any data is really sent. Alternatively you could run something like ‘nc -l -p $port’ on the server where you are hosting the php script and then use http://$server:$port as hook target (with $port being an unused port number >1024 and $server being the FQDN of the server hosting the PHP script). That will give you the raw http request.

Thank you both!!

@elfuego actually I did it, I checked all headers content but I’m still not able to catch them. Every time I git push I need to log into the VPS go to the project folder and git pull the changes, there’s something I’m really missing

@BasicBaer This site sounds good, I’ll give it a try using your advice :D, do you know if this site logs data??

Regards!!

No, I don’t know if that site is logging data - that was the reason so stating “if you don’t mind exposing data” :slight_smile:

Cheers
Hendrik