PHP code example of gevman / git-hook
1. Go to this page and download the library: Download gevman/git-hook library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gevman / git-hook example snippets
$gitHubRepo = new \Gevman\GitHook\GitHub\Repository();
$gitHubRepo->onPush(function() {
exec('cd /path/to/your/project && git pull');
});
$gitHubRepo = new \Gevman\GitHook\GitHub\Repository();
$slackBot = new \Gevman\SlackBot\IncomingBot('YOUR_SLACK_HOOK_URL');
$gitHubRepo->onPullRequest(function($payload) use ($slackBot) {
$message = sprintf(
'%s just %s pull request: `%s`',
$payload['pull_request']['user']['login'],
$payload['action'],
$payload['pull_request']['title']
);
$slackBot->send($message)
->withIcon('https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png')
->to('general');
});
$bitBucketRepo = new \Gevman\GitHook\BitBucket\Repository();
$bitBucketRepo->onPush(function() {
exec('cd /path/to/your/project && git pull');
});
$bitBucketRepo = new \Gevman\GitHook\BitBucket\Repository();
$slackBot = new \Gevman\SlackBot\IncomingBot('YOUR_SLACK_HOOK_URL');
$notifier = function($action) use ($slackBot) {
return function($payload) use ($action, $slackBot) {
$message = sprintf(
'%s just %s pull request: `%s`',
$payload['actor']['display_name'],
$action,
$payload['pullrequest']['title']
);
$slackBot->send($message)
->withIcon('https://wac-cdn.atlassian.com/assets/img/icons/logo/bitbucket_rgb_blue.svg')
->to('general');
};
};
$bitBucketRepo->onPullRequestApproved($notifier('Approved'))
->onPullRequestApprovalRemoved($notifier('ApprovalRemoved'))
->onPullRequestCreated($notifier('Created'))
->onPullRequestMerged($notifier('Merged'))
->onPullRequestUpdated($notifier('Updated'));