love-oss/github-event-parser
最新稳定版本:0.8.4
Composer 安装命令:
composer require love-oss/github-event-parser
包简介
PHP library to get a readable representation of events dispatched by Github API v3
关键字:
README 文档
README
This library is a reupload of a library created by Mickaël Andrieu in 2016 for the Lp Digital web agency, Paris, France. We have obtained the authorization from the former creator to change the licence from GNU-GPL v2 to MIT. PHP Developers : consider using love-oss/github-event-parser as a direct replacement of lp-digital/github-event-parser.
Github Event Parser is a naive PHP library aimed to provide readable representations of json responses from Github Events Api v3.
Thanks to the Github webhooks, any administrator of a repository can access and listen theses events returned into json responses.
The only aim of this library is to parse theses responses, and create simple POPO (Plain Old PHP Object) easy to manipulate, extends or even persist in a database.
A lot of usages are available since you can listen all events:
- make statistics on your repositories
- do some tasks after a successful deployment
- send a "thanks" email for each validated contribution
- and so on ...
Installation
$ composer require "love-oss/github-event-parser"
PHP requirements
The library may access to GitHub API to retrieve additional information.
Your PHP configuration may have allow_url_fopen and a valid user_agent enabled, or
some informations won't be retrieved.
You can use InvalidPhpConfigurationException to catch the exception:
<?php use LoveOSS\Github\Exception\InvalidPhpConfigurationException; try { $commits = $pullRequest->getCommits(); // use the GitHub API when called. } catch(InvalidPhpConfigurationException $exception) { // ... }
How to resolve a json response from Github ?
Once your webhook is set up, you should receive POST responses from github each time an event is dispatched by the platform.
For instance, let's consider you have a simple github-hook.php file and have installed your dependency through composer:
<?php include_once('./vendor/autoload.php'); use LoveOSS\Github\Parser\WebhookResolver; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $decodedJson = json_decode(file_get_contents('php://input'), true); $resolver = new WebhookResolver(); $event = $resolver->resolve($decodedJson); // ex: an instance of `IssueCommentEvent` echo($event::name()); // IssueCommentEvent /* ... do your own business */ }
EventTypes
Note that this library is not complete, so only few events are available for now. But, it's realy easy to implement the missing. If you need them, please make a pull request!
IssueCommentEvent
Dispatched when someone comment an issue
You can retrieve the issue, the user and the related comment from this event.
<?php $issueCommentEvent->issue; // instance of LoveOSS/Entity/Issue $issueCommentEvent->user; // instance of LoveOSS/Entity/User $issueCommentEvent->comment; // instance of LoveOSS/Entity/Comment
IssuesEvent
Dispatched when an issue is assigned, unassigned, labeled, unlabeled, opened, closed, or reopened.
You can retrieve the action, the repository and the sender from this event. When available, you can also get assignee and label.
<?php $issuesEvent->action; // Can be one of "assigned", "unassigned", "labeled", "unlabeled", "opened", "closed", or "reopened". $issuesEvent->assignee; // optional: the assignee of the issue(LoveOSS/Entity/User) $issuesEvent->issue; // instance of LoveOSS/Entity/Issue $issuesEvent->label; // optional: the label of the issue(LoveOSS/Entity/Label) $issuesEvent->repository; // instance of LoveOSS/Entity/Repository $issuesEvent->sender; // instance of LoveOSS/Entity/User
ForkEvent
Dispatched when someone fork the repository
You can retrieve the forked repository, the owner, the new repository and the "forker".
<?php $forkEvent->forkedRepository; // instance of LoveOSS/Entity/Repository $forkEvent->owner; // instance of LoveOSS/Entity/User $forkEvent->repository; // instance of LoveOSS/Entity/Repository $forkEvent->forker; // instance of LoveOSS/Entity/User
DeploymentStatusEvent
Dispatched when a deployement's status changes
You can retrieve the deployment, the sender and the related repository.
<?php $deploymentStatusEvent->deployment; // instance of LoveOSS/Entity/Deployment $deploymentStatusEvent->sender; // instance of LoveOSS/Entity/User $deploymentStatusEvent->repository; // instance of LoveOSS/Entity/Repository
PullRequestEvent
Dispatched when a pull request is assigned, unassigned, labeled, unlabeled, opened, closed, reopened, or synchronized.
$pullRequestEvent->pullRequest; // instance of LoveOSS/Entity/PullRequest $pullRequest->action; /** * Can be one of “assigned”, “unassigned”, “labeled”, “unlabeled”, “opened”, “closed”, or “reopened”, or “synchronize”. * If the action is “closed” and the merged key is false, the pull request was closed with unmerged commits. * If the action is “closed” and the merged key is true, the pull request was merged. */ $pullRequest->number; // the pull request number $pullRequest->repository; // instance of LoveOSS/Entity/Repository
PushEvent
Dispatched when a repository branch is pushed to. In addition to branch pushes, webhook push events are also triggered when repository tags are pushed.
$pushEvent->ref // the full Git ref that was pushed ex: refs/heads/master $pushEvent->head // the SHA of the most recent commit on ref after the push $pushEvent->before // the SHA of the most recent commit on ref before the push $pushEvent->size // the number of commits in the push $pushEvent->commits // an array of objects that describe the pushed commits
StatusEvent
Dispatched when the status of a Git commit changes. Events of this type are not visible in timelines, they are only used to trigger hooks.
You can retrieve the sha, the status, the committer and the related repository. More others informations are available.
<?php $statusEvent->sha; // something like "9049f1265b7d61be4a8904a9a27120d2064dab3b" $statusEvent->status; // Can be one of "success", "failure" or "error". $statusEvent->commiter; // instance of LoveOSS/Entity/User $statusEvent->repository; // instance of LoveOSS/Entity/Repository
WatchEvent
The WatchEvent is related to starring a repository, not watching. See this API blog post for an explanation. The event’s actor is the user who starred a repository, and the event’s repository is the repository that was starred.
<?php $watchEvent->action; // "started" $watchEvent->user // instance of LoveOSS\Entity\User $watchEvent->repository // instance of LoveOSS\Entity\Repository
PullRequestReviewCommentEvent
Dispatched when a comment is created on a portion of the unified diff of a pull request.
<?php $pullRequestReviewCommentEvent->action // "created" $pullRequestReviewCommentEvent->comment // instance of LoveOSS\Entity\Comment $pullRequestReviewCommentEvent->pullRequest // instance of LoveOSS\Entity\PullRequest $pullRequestReviewCommentEvent->repository // instance of LoveOSS\Entity\Repository $pullRequestReviewCommentEvent->sender // instance of LoveOSS\Entity\User
GollumEvent
Dispatched when a Wiki page is created or updated.
<?php $gollumEvent->pages // an array of LoveOSS\Entity\Page objects $gollumEvent->repository // instance of LoveOSS\Entity\Repository $gollumEvent->sender // instance of LoveOSS\Entity\User
Entities
Each object from Github API have his PHP class.
- Comment
- Commit (and CommitUser)
- Deployment
- Issue
- Label
- Page (Wiki)
- PullRequest
- Release
- Repository
- User
Roadmap
- Improve and monitor the quality of this library
- Add the missing missing events
- Add doctrine mapping file for doctrine/dbal
How to contribute ?
All features are tested, and all contributions need to be tested in order to be accepted.
Features from roadmap and bug fixes are prioritized. Fork the repository, create a feature branch and then launch the testsuite:
$ ./vendor/bin/phpunit
Thank you for help, let us know if you use this library ;)
love-oss/github-event-parser 适用场景与选型建议
love-oss/github-event-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「event」 「github」 「json parser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 love-oss/github-event-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 love-oss/github-event-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 love-oss/github-event-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Symfony bundle for broadway/broadway.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-07