I'm running GitLab v5.2 on the same server as my production webserver (Document Root in /var/www).
I'm trying to setup a standard GitLab Post-Receive Hook but am finding surprisingly little information about how to set up a script to process the posted JSON data. I'm not trying to do anything custom, just right out of the box, I want to receive the post-receive data at my website location (remember on the same server), and then pull from origin-master when it gets received (provided the post-receive data originating push was to the master branch). This way, the website found in /var/www is always same a master.
Could someone either, give me an example of a pull script from the post data or point me in the right direction for me to create one?
GitLab Hook Request Example - For those without a GitLab instance, here is what the GitLab Post-Receive JSON data looks like (straight from the GitLab help)
{
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"user_id": 4,
"user_name": "John Smith",
"repository": {
"name": "Diaspora",
"url": "git@localhost:diaspora.git",
"description": "",
"homepage": "http://localhost/diaspora",
},
"commits": [
{
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"message": "Update Catalan translation to e38cb41.",
"timestamp": "2011-12-12T14:27:31+02:00",
"url": "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"author": {
"name": "Jordi Mallach",
"email": "jordi@softcatala.org",
}
},
// ...
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://localhost/diaspora/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)",
},
},
],
"total_commits_count": 4,
};
Up to date docs are in the application itself: https://docs.gitlab.com/ce/user/project/integrations/webhooks.html
Alright, after extensive digging I've found enough docs to create my own script, and here it is:
PHP
So, this works perfectly for its purpose. But now I need to rethink the logic and potentially even the philosophy. This methodology will automatically keep the /var/www/website/directory up-to-date with master; however, what about various other branches? I need some methodology in place to be able to view other branches through my web server, so the dev teams can view their work...
Here is what I'm thinking:
Rather than my code just looking for "master" within the ref section of the post string, I split the post string on the "/" delimiter and pop off the end element:
Then I check to see if this branch has a working directory within the /var/www/website/directory/, like
/var/www/website/directory/master
:This logic seems relatively solid, just posting it on here to see people's opinions. With this method, a developer can create a new remote branch, and push to it, then the branch will get pulled into the /var/www web directory for viewing.
Can anyone think of another way to allow developers to view their dev branches or any recommendations as to how to make this script better?
Thanks