This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
github-webhook.txt
54 lines (46 loc) · 1.71 KB
/
github-webhook.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// Set the payload.
$githubdump_payload = $_POST['payload'];
// Define the branch to check for commit.
// If you want to monitor all commits, set value to 'allcommits'.
$githubdump_branch = 'master';
// Check the branch commit belongs to.
$githubdump_check_branch = githubdump_compare_branch($githubdump_payload, $githubdump_branch);
/**
* Do your stuff here.
* @param: object of json provided in payload by Github.
*/
function githubdump($payload_object) {
// Write your code here.
//echo shell_exec( 'cd /var/customers/webs/hase/2014.multimediajugend.de/ && git reset --hard HEAD && git pull 2>&1' );
echo shell_exec( 'cd /var/www/screen/html/ && git pull 2>&1' );
}
/**
* Compare the branch.
*/
function githubdump_compare_branch($githubdump_payload, $githubdump_required_branch) {
$githubdump_get_branch = githubdump_get_branch($githubdump_payload, $githubdump_required_branch);
$githubdump_received_branch = $githubdump_get_branch['branch'];
$githubdump_payload = $githubdump_get_branch['object'];
if ($githubdump_received_branch == $githubdump_required_branch && $githubdump_required_branch !== 'allcommits') {
githubdump($githubdump_payload);
return TRUE;
}
return FALSE;
}
/**
* Get the branch.
*/
function githubdump_get_branch($githubdump_payload, $githubdump_required_branch) {
if (isset($githubdump_payload) && !empty($githubdump_payload)) {
// Convert json into object.
$githubdump_received_object = json_decode($githubdump_payload);
// Get the branch.
$githubdump_received_branch = str_replace('refs/heads/', '', $githubdump_received_object->ref);
return array(
'object' => $githubdump_received_object,
'branch' => $githubdump_received_branch,
);
}
return FALSE;
}