• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ericfortmeyer / activity-log / 20527476519

26 Dec 2025 06:39PM UTC coverage: 42.491%. Remained the same
20527476519

push

github

web-flow
fix: remove validation (#67)

Signed-off-by: Eric Fortmeyer <e.fortmeyer01@gmail.com>

0 of 10 new or added lines in 2 files covered. (0.0%)

348 of 819 relevant lines covered (42.49%)

1.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Http/NotifyReleaseEventMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace EricFortmeyer\ActivityLog\Http;
6

7
use EricFortmeyer\ActivityLog\AppReleaseEvent;
8
use EricFortmeyer\ActivityLog\Services\AppConfigService;
9
use EricFortmeyer\ActivityLog\Utils\Hasher;
10
use PhpCommonEnums\HttpMethod\Enumeration\HttpMethodEnum;
11
use PhpCommonEnums\HttpResponseCode\Enumeration\HttpResponseCodeEnum;
12
use Psr\Http\Message\ResponseFactoryInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
use Psr\Http\Message\ResponseInterface;
15
use Psr\Http\Server\MiddlewareInterface;
16
use Psr\Http\Server\RequestHandlerInterface;
17

18
final class NotifyReleaseEventMiddleware implements MiddlewareInterface
19
{
20
    private const SIGNATURE_HEADER_KEY = "X-Hub-Signature-256";
21
    private const SUPPORTED_METHODS = [HttpMethodEnum::Post];
22

23
    public function __construct(
24
        private string $releaseEventDestination,
25
        private string $releaseEventHookPath,
26
        private ResponseFactoryInterface $responseFactory,
27
        private AppConfigService $appVersionUpdater,
28
        private Hasher $verifier,
29
    ) {}
×
30

31
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
32
    {
NEW
33
        $requestBody = $request->getBody()->getContents();
×
34
        return match (false) {
×
35
            in_array($request->getUri()->getPath(), [$this->releaseEventHookPath]) => $handler->handle($request),
×
36
            in_array(HttpMethodEnum::from($request->getMethod()), self::SUPPORTED_METHODS) =>
×
37
            $this->responseFactory->createResponse(
×
38
                (int) HttpResponseCodeEnum::MethodNotAllowed->value,
×
39
                HttpResponseCodeEnum::MethodNotAllowed->name
×
40
            ),
×
41
            str_starts_with(
×
42
                $request->getHeader("User-Agent")[0] ?? "invalid!!!",
×
43
                "GitHub-Hookshot",
×
44
            ) => $this->responseFactory->createResponse(
×
45
                (int) HttpResponseCodeEnum::Unauthorized->value,
×
46
                HttpResponseCodeEnum::Unauthorized->name
×
47
            ),
×
48
            $this->verifier->verify(
×
NEW
49
                data: $requestBody,
×
50
                signature: ltrim($request->getHeader(self::SIGNATURE_HEADER_KEY)[0] ?? "ignore", "sha256="),
×
51
            ) => $this->responseFactory->createResponse(
×
52
                (int) HttpResponseCodeEnum::Unauthorized->value,
×
53
                HttpResponseCodeEnum::Unauthorized->name
×
54
            ),
×
55
            AppReleaseEvent::isReleaseEventRequest($request) => $this->responseFactory->createResponse(
×
56
                (int) HttpResponseCodeEnum::NotImplemented->value,
×
57
                HttpResponseCodeEnum::NotImplemented->name
×
58
            ),
×
NEW
59
            AppReleaseEvent::fromRequest($requestBody, $request)->isValid() => $this->responseFactory->createResponse(
×
60
                (int) HttpResponseCodeEnum::BadRequest->value,
×
61
                HttpResponseCodeEnum::BadRequest->name
×
62
            ),
×
NEW
63
            AppReleaseEvent::isCreatedRelease($requestBody) => $this->responseFactory->createResponse(
×
64
                (int) HttpResponseCodeEnum::Accepted->value,
×
65
                HttpResponseCodeEnum::Accepted->name
×
66
            ),
×
67
            $this->handleReleaseEvent(
×
NEW
68
                AppReleaseEvent::fromRequest($requestBody, $request),
×
NEW
69
                $requestBody,
×
70
            ) =>
×
71
            $this->responseFactory->createResponse(
×
72
                (int) HttpResponseCodeEnum::InternalServerError->value,
×
73
                HttpResponseCodeEnum::InternalServerError->name
×
74
            ),
×
75
            default => $this->responseFactory->createResponse(
×
76
                (int) HttpResponseCodeEnum::Accepted->value,
×
77
                HttpResponseCodeEnum::Accepted->name
×
78
            ),
×
79
        };
×
80
    }
81

82
    private function handleReleaseEvent(
83
        AppReleaseEvent $event,
84
        string $requestBody,
85
    ): bool {
86
        return file_put_contents(
×
87
            sprintf(
×
88
                "%s/%d.json",
×
89
                $this->releaseEventDestination,
×
NEW
90
                $event->release->id,
×
91
            ),
×
NEW
92
            $requestBody,
×
93
        ) !== false
×
94
            && $this->appVersionUpdater->updateVersion($event->release->tagName);
×
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc