From a77fe4d4ed126b544f9990ed3575966355c1a75b Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sun, 27 Sep 2026 16:26:56 +0200 Subject: [PATCH] fix(webhooks): deploy Gitea pull requests at their head commit The Gitea handler read the pull request commit from a top-level head.sha that Gitea does not send, so preview deployments always used HEAD. It now reads pull_request.head.sha, with the top-level after of newer Gitea versions as a fallback. Co-Authored-By: Claude Opus 5.5 --- app/Http/Controllers/Webhook/Gitea.php | 3 ++- tests/Feature/Webhook/WebhookPayloadTypesTest.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Webhook/Gitea.php b/app/Http/Controllers/Webhook/Gitea.php index 83c1eaf887..6fb2b39364 100644 --- a/app/Http/Controllers/Webhook/Gitea.php +++ b/app/Http/Controllers/Webhook/Gitea.php @@ -58,7 +58,8 @@ class Gitea extends Controller $skip_deploy_pr = self::shouldSkipDeployAny([$this->webhookPayloadString($payload, 'pull_request.title')]); $branch = $this->webhookString(data_get($payload, 'pull_request.head.ref')); $base_branch = $this->webhookString(data_get($payload, 'pull_request.base.ref')); - $commit = $this->webhookCommitSha($payload, 'head.sha'); + // Gitea sends the head commit in pull_request.head.sha; newer versions also send it as after. + $commit = $this->webhookCommitSha($payload, 'pull_request.head.sha') ?? $this->webhookCommitSha($payload, 'after'); } if (! $branch || ($x_gitea_event === 'pull_request' && ! $base_branch)) { return response('Nothing to do. No branch found in the request.'); diff --git a/tests/Feature/Webhook/WebhookPayloadTypesTest.php b/tests/Feature/Webhook/WebhookPayloadTypesTest.php index f54c60564c..1ae841252e 100644 --- a/tests/Feature/Webhook/WebhookPayloadTypesTest.php +++ b/tests/Feature/Webhook/WebhookPayloadTypesTest.php @@ -376,7 +376,7 @@ function webhookTypesFields(): array ['pull_request.title', 'string', null], ['pull_request.head.ref', 'branch', 'No branch'], ['pull_request.base.ref', 'branch', 'No branch'], - ['head.sha', 'sha', null], + ['pull_request.head.sha', 'sha', null], ['repository.full_name', 'required string', 'Invalid repository'], ], 'gitea manual|pr|closed' => [ @@ -506,7 +506,8 @@ describe('Webhook payload value types', function () { })->with([ 'gitlab manual' => ['gitlab manual', webhookTypesSha()], 'gitlab app' => ['gitlab app', webhookTypesSha()], - 'gitea manual' => ['gitea manual', 'HEAD'], + // Gitea sends the head commit in pull_request.head.sha. + 'gitea manual' => ['gitea manual', webhookTypesSha()], 'bitbucket manual' => ['bitbucket manual', substr(webhookTypesSha(), 0, 12)], ]);