Skip to content
Snippets Groups Projects
Select Git revision
  • 119a4482d83cbdadff3c5656f44f70fb959aab25
  • main default protected
  • studip-rector
  • ci-opt
  • course-members-export-as-word
  • data-vue-app
  • pipeline-improvements
  • webpack-optimizations
  • rector
  • icon-renewal
  • http-client-and-factories
  • jsonapi-atomic-operations
  • vueify-messages
  • tic-2341
  • 135-translatable-study-areas
  • extensible-sorm-action-parameters
  • sorm-configuration-trait
  • jsonapi-mvv-routes
  • docblocks-for-magic-methods
19 results

PluginRepository.class.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    hooks.php 2.13 KiB
    <?php
    use TracToGitlab\EventController;
    use TracToGitlab\EventHandler;
    use TracToGitlab\EventHandlers;
    
    final class HooksController extends EventController
    {
        public function system_action()
        {
            if (!$this->verifySecret(Config::get()->getValue('TRAC2GITLAB_GITLAB_SYSTEMHOOK_SECRET'))) {
                throw new AccessDeniedException();
            }
    
            if (!$this->verifyEvent()) {
                throw new Exception('This is not a valid gitlab event');
            }
    
            $this->processHooks($this->getKnownSystemhooks());
        }
    
        /**
         * @return iterator|EventHandler[]
         */
        private function getKnownSystemhooks(): iterator
        {
            yield app(EventHandlers\UserCreated::class);
        }
    
        public function web_action()
        {
            if (!$this->verifySecret(Config::get()->getValue('TRAC2GITLAB_GITLAB_WEBHOOK_SECRET'))) {
                throw new AccessDeniedException();
            }
    
            $payload = $this->payload();
    
            if (
                !$this->verifyEvent()
                || !isset($payload['project']['id'])
                || $payload['project']['id'] != $this->gitlab_project_id
            ) {
                $this->set_status(500);
                $this->render_json([
                    'payload' => $payload['project']['id'] ?? 'NONE!',
                    'id' => $this->gitlab_project_id,
                    'result' => $this->verifyEvent(),
                    'event' => $_SERVER['HTTP_X_GITLAB_EVENT'] ?? 'NONE',
                    'server' => $_SERVER,
                    'names' => [
                        'event' => $payload['event_name'],
                        'object_kind' => $payload['object_kind'],
                    ],
                ]);
                return;
                throw new Exception('This is not a valid gitlab event');
            }
    
            $this->processHooks($this->getKnownWebhooks());
        }
    
        /**
         * @return iterator|EventHandler[]
         */
        private function getKnownWebhooks(): iterator
        {
            yield app(EventHandlers\AllAutomaticJobsHaveSucceeded::class);
            yield app(EventHandlers\BranchDeleted::class);
            yield app(EventHandlers\BuildImageJobSucceeded::class);
            yield app(EventHandlers\IssueCreated::class);
        }
    }