h-ishak/git-webhook-handler
Composer 安装命令:
composer require h-ishak/git-webhook-handler
包简介
The simple way to automatically update your app using a webhook.
README 文档
README
All credits goes to Sevak https://github.com/sevaske
Git Webhook Handler
The simple way to automatically update your app using a webhook.
This script listens to the bitbucket/github webhook and updates the current brunch of your project.
What does it do?
git fetch
git pull origin {current_branch_name}
Install
composer require h-ishak/git-webhook-handler
Examples
You can create a file: {your_project_path}/webhook/index.php
Handlers
You have 2 Existing Handlers :
- BitbucketHandler
- GithubHandler
need more handlers ? you can add any handler you want just by extending AbstractHandler class
Just update the project
<?php require_once __DIR__ . '/../vendor/autoload.php'; $projectRootPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; $requestContent = file_get_contents("php://input"); $gitAlias = 'git'; $webhook = new \GitWebhookHandler\Webhook( new BitbucketHandler($requestContent), $projectRootPath, $gitAlias ); $result = $webhook->handlePull(); // boolean
Update and process the results
<?php require_once __DIR__ . '/../vendor/autoload.php'; $projectRootPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; $requestContent = file_get_contents("php://input"); $gitAlias = 'git'; $webhook = new \GitWebhookHandler\Webhook( new BitbucketHandler($requestContent), $projectRootPath, $gitAlias ); // update and get results of executions $fetchResult = $webhook->git->fetch(); $pullResult = $webhook->git->pull(); // Execution details $fetchResult->output; // The result of executing the command "git fetch" $pullResult->output; // The result of executing the command "git pull origin {your_current_branch}" $noChanges = \GitWebhookHandler\Terminal\Git::catchNoChanges($pullResult); // True if no changes $pullErrors = \GitWebhookHandler\Terminal\Git::catchErrors($pullResult); // Array of errors // Errors & the repo details $webhook->errors; // Array of errors $webhook->git->branchName; // Current branch of your project $webhook->requestHandler->authors; // Array of changes authors (full name, email and nickname) $webhook->requestHandler->request->repository->full_name; // Repository name // maybe you want to do something else? $composerUpdateCommand = "export COMPOSER_HOME=/home/sevaske/.composer && cd {$projectRootPath} && composer update"; $composerUpdateResult = \GitWebhookHandler\Terminal\Command::exec($composerUpdateCommand); $composerUpdateResult->output; // The result of executing the command "composer update"
Errors?
If you have any errors related to accessing the repository, you can run the following command:
git config --global --add safe.directory {project_path}
sudo git remote set-url origin https://{bitbucket_user}:{auth_pass}@bitbucket.org/{project_name}/{repo_name}.git
Also, the script must have access to all the files of your project otherwise you may have an error. A quick solution (but unsafe, so be careful):
sudo chown -R www-data:www-data {project_path}
What about security?
The webhook checks the branch name and checks if such a branch exists in the repository. The execution command is fixed and does not contain anything dynamic.
You should add your server's ip to the webhook whitelist .
h-ishak/git-webhook-handler 适用场景与选型建议
h-ishak/git-webhook-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 h-ishak/git-webhook-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 h-ishak/git-webhook-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-29