swop/github-webhook

处理GitHub webhook请求的库(签名验证与有效载荷解析)

v3.1 2020-11-14 10:26 UTC

This package is not auto-updated.

Last update: 2024-09-15 00:52:14 UTC


README

Build Status

此库提供了一些工具,当处理GitHub webhook请求时可能会很有用。

安装

建议通过Composer安装此库

composer require "swop/github-webhook"

使用

有效载荷签名检查

SignatureValidator将验证传入的GitHub webhook请求是否正确签名。

use Swop\GitHubWebHook\Security\SignatureValidator;

$validator = new SignatureValidator();

/** @var \Psr\Http\Message\ServerRequestInterface $request */
if ($validator->validate($request, 'secret')) {
    // Request is correctly signed
}

创建GitHub事件对象

GitHubEventFactory可以构建代表GitHub事件的GitHubEvent对象。

use Swop\GitHubWebHook\Event\GitHubEventFactory;

$factory = new GitHubEventFactory();

/** @var \Psr\Http\Message\ServerRequestInterface $request */
$gitHubEvent = $factory->buildFromRequest(RequestInterface $request);

$gitHubEvent->getType(); // Event type
$gitHubEvent->getPayload(); // Event deserialized payload

贡献

查看CONTRIBUTING文件。

原始信用

许可证

此库在MIT许可证下发布。请参阅捆绑的完整LICENSE文件。