Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(webhooks): deploy Gitea pull requests at their head commit

Andras Bacsaia77fe4d4ed12
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)],
]);