承接 thecodingmachine/gitlab-hook-middleware 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thecodingmachine/gitlab-hook-middleware

Composer 安装命令:

composer require thecodingmachine/gitlab-hook-middleware

包简介

A PSR-15 middleware to manage Gitlab hooks.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Coverage Status

Gitlab hook PSR-15 middleware

This package is a PSR-15 Middleware to receive events sent by a Gitlab webhook and send them to a listener.

It's possible to use directly the hookReceiver to build the event object, but you could check the Gitlab authentification.

How does it work

The middleware checks the header named X-GITLAB-TOKEN and builds an event object. The object is dispatched to a listener that you must implement.

The middleware takes care of unserializing the payload and provides you with nice PHP objects instead of raw JSON data. It's possible to get the initial array payload with the getPayload() function.

Your listener will receive all events. If you want to listen on a specific event type, you must check the object type.

Event List:

Scope Hook Header Object
Project Push Hook Push Hook TheCodingMachine\GitlabHook\Model\Push
Project Tag Push Hook Tag Push Hook TheCodingMachine\GitlabHook\Model\TagPush
Project Note Hook Note Hook Not implemented
Project Pipeline Hook Pipeline Hook TheCodingMachine\GitlabHook\Model\Pipeline
Project Build Hook Build Hook TheCodingMachine\GitlabHook\Model\Build
Group Project created System Hook TheCodingMachine\GitlabHook\Model\ProjectCreate
Group Project destroyed System Hook TheCodingMachine\GitlabHook\Model\ProjectDestroy
Group Project renamed System Hook TheCodingMachine\GitlabHook\Model\ProjectRename
Group Project transferred System Hook TheCodingMachine\GitlabHook\Model\ProjectTrasnfer
Group New Team Member System Hook TheCodingMachine\GitlabHook\Model\TeamMemberAdd
Group Team Member Removed System Hook TheCodingMachine\GitlabHook\Model\TeamMemberRemove
Group User created System Hook TheCodingMachine\GitlabHook\Model\UserCreate
Group User removed System Hook TheCodingMachine\GitlabHook\Model\UserDestroy
Group User failed login System Hook TheCodingMachine\GitlabHook\Model\UserFailedLogin
Group User renamed System Hook TheCodingMachine\GitlabHook\Model\UserRename
Group Key added System Hook TheCodingMachine\GitlabHook\Model\KeyCreate
Group Key removed System Hook TheCodingMachine\GitlabHook\Model\KeyDestroy
Group Group created System Hook TheCodingMachine\GitlabHook\Model\GroupCreate
Group Group removed System Hook TheCodingMachine\GitlabHook\Model\GroupDestroy
Group Group renamed System Hook TheCodingMachine\GitlabHook\Model\GroupRename
Group New Group Member System Hook TheCodingMachine\GitlabHook\Model\UserGroupAdd
Group Group Member Removed System Hook TheCodingMachine\GitlabHook\Model\UserGroupRemove
Group Push events System Hook TheCodingMachine\GitlabHook\Model\Push
Group Tag events System Hook TheCodingMachine\GitlabHook\Model\Tag
Group Merge request events System Hook TheCodingMachine\GitlabHook\Model\MergeRequest
Group Repository Update events System Hook TheCodingMachine\GitlabHook\Model\RepositoryUpdate

Example

Listener implementation

<?php
namespace Test;

class Listener implements HookListenerInterface {
    /**
     * @param \TheCodingMachine\GitlabHook\EventInterface $event
     */
     public function onEvent(EventInterface $event) {
         // Compute Push event
         if($event instanceof TheCodingMachine\GitlabHook\Model\Push::class) {
             // Display before
             echo $event->getBefore();
             // Display the project name
             echo $event->getProject()->getName();
         }
         // Compute MergeRequest event
         if($event instanceof TheCodingMachine\GitlabHook\Model\MergeRequest::class) {
             // Display target branch (this is in object_attributes)
             echo $event->getTargetBranch();
             // Get initial payload
             var_dump($event->getPayload());
         }
     }
}
?>

Use without middleware

// Create your listener
$listener = new Test\Listerner();

// Register your listener in the main HookReceiver instance
$hookReceiver = new TheCodingMachine\GitlabHook\HookReceiver([$listener]);

// Call handler function to execute check
// $payload is array (json_decode) of data send by Gitlab webhook
// $header is the result of HTTP_X_GITLAB_TOKEN header 
$hookReceiver->handle($payload, $header);

Use a middleware

// Create your listener
$listener = new Test\Listerner();

// Register your listener in the main HookReceiver instance
$hookReceiver = new TheCodingMachine\GitlabHook\HookReceiver([$listener]);

// Create a PSR-3 logger
$logger = new Psr\Log\NullLogger(); 

// Inject hookReceiver in Gitlab middleware
// You must inject this middleware in the middleware pipe of your favorite framework.
// See your framework documentation on how to do that.
$middleware = new TheCodingMachine\GitlabHook\GitlabHookMiddleware($hookReceiver, 'secret', $logger);

thecodingmachine/gitlab-hook-middleware 适用场景与选型建议

thecodingmachine/gitlab-hook-middleware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 71 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「middleware」 「HOOK」 「gitlab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 thecodingmachine/gitlab-hook-middleware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 thecodingmachine/gitlab-hook-middleware 我们能提供哪些服务?
定制开发 / 二次开发

基于 thecodingmachine/gitlab-hook-middleware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 71
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 6
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-08