Restore gitHub resource, namespace Gitea build spans, surface token-refresh failures

- app/init/resources.php: re-register the gitHub DI resource (still
  needed by Template/Duplicate Create.php for the always-GitHub
  template path), lost during the adapter-driven Factory refactor.
- GitHub/Deployment.php: derive the build-lifecycle span namespace from
  the adapter instead of hardcoding vcs.github.*, so Gitea deployments
  are no longer mislabeled as GitHub in monitoring.
- Gitea/Events/Create.php: a failed OAuth2 token refresh was silently
  swallowed (console warning only), returning Gitea a 200 with no
  retry and no signal to the project owner. Now aggregated into a
  thrown exception, mirroring GitHub's error-aggregation pattern, so
  the webhook delivery fails visibly and shows up in Gitea's redelivery log.
This commit is contained in:
harsh mahajan committed 2026-07-15 17:17:44 +05:30
1 parent 6784fd0240
commit 8dd7549eeb
3 files changed
+29 -6

No files matched your search

+1
View File
@@ -379,6 +379,7 @@ $container->set('servers', function () {
$container->set('promiseAdapter', fn ($register) => $register->get('promiseAdapter'), ['register']);
$container->set('vcsFactory', fn (Cache $cache) => new VcsFactory($cache), ['cache']);
$container->set('gitHub', fn (VcsFactory $vcsFactory) => $vcsFactory->fromProvider('github'), ['vcsFactory']);
$container->set('installationTokens', fn () => new InstallationTokens(), []);
$container->set('repositoryWebhooks', fn (VcsFactory $vcsFactory) => new RepositoryWebhooks($vcsFactory), ['vcsFactory']);
@@ -53,8 +53,9 @@ trait Deployment
?Backend $deployments = null,
) {
$errors = [];
$provider = $vcs->getName();
foreach ($repositories as $repository) {
$logBase = 'vcs.github.event.repo.unknown';
$logBase = "vcs.{$provider}.event.repo.unknown";
try {
$repositoryId = $repository->getId();
@@ -62,7 +63,7 @@ trait Deployment
$resourceId = $repository->getAttribute('resourceId');
$resourceType = $repository->getAttribute('resourceType');
$logBase = "vcs.github.event.repo.{$repositoryId}";
$logBase = "vcs.{$provider}.event.repo.{$repositoryId}";
Span::add('project.id', $projectId);
Span::add("{$logBase}.resource.id", $resourceId);
Span::add("{$logBase}.resource.type", $resourceType);
@@ -102,7 +102,15 @@ class Create extends Action
return $installation;
}
private function resolveAdapterForRepository(Document $repository, VcsFactory $vcsFactory, InstallationTokens $installationTokens, Database $dbForPlatform, Authorization $authorization): ?Git
/**
* Resolves the adapter for a repository's installation, refreshing its
* OAuth2 token first. A null installation (not a Gitea installation) is
* not an error -- the caller silently skips it. A token-refresh/adapter
* failure, on the other hand, is pushed onto $errors so the caller can
* surface it instead of dropping it silently -- Gitea's webhook delivery
* gets a non-2xx response and the failure shows up in its redelivery log.
*/
private function resolveAdapterForRepository(Document $repository, VcsFactory $vcsFactory, InstallationTokens $installationTokens, Database $dbForPlatform, Authorization $authorization, array &$errors): ?Git
{
$installation = $this->resolveGiteaInstallation($repository, $dbForPlatform, $authorization);
@@ -122,7 +130,10 @@ class Create extends Action
return $vcsFactory->fromInstallation($installation);
} catch (\Throwable $error) {
Console::warning("Failed to resolve Gitea adapter for installation '{$installation->getId()}': " . $error->getMessage());
$message = "Failed to resolve Gitea adapter for installation '{$installation->getId()}': " . $error->getMessage();
Console::warning($message);
Span::add("vcs.gitea.event.installation.{$installation->getId()}.error", $message);
$errors[] = $message;
return null;
}
}
@@ -166,8 +177,9 @@ class Create extends Action
$providerAffectedFiles = $parsedPayload['affectedFiles'] ?? [];
$errors = [];
foreach ($repositories as $repository) {
$adapter = $this->resolveAdapterForRepository($repository, $vcsFactory, $installationTokens, $dbForPlatform, $authorization);
$adapter = $this->resolveAdapterForRepository($repository, $vcsFactory, $installationTokens, $dbForPlatform, $authorization, $errors);
if ($adapter === null) {
continue;
@@ -177,6 +189,10 @@ class Create extends Action
$this->createGitDeployments($adapter, $providerInstallationId, [$repository], $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthorName, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', $providerAffectedFiles, false, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform);
}
if (!empty($errors)) {
throw new Exception(Exception::GENERAL_UNKNOWN, \implode("\n", $errors));
}
}
private function handlePullRequestEvent(
@@ -219,8 +235,9 @@ class Create extends Action
Query::limit(100),
]));
$errors = [];
foreach ($repositories as $repository) {
$adapter = $this->resolveAdapterForRepository($repository, $vcsFactory, $installationTokens, $dbForPlatform, $authorization);
$adapter = $this->resolveAdapterForRepository($repository, $vcsFactory, $installationTokens, $dbForPlatform, $authorization, $errors);
if ($adapter === null) {
continue;
@@ -245,6 +262,10 @@ class Create extends Action
$this->createGitDeployments($adapter, $providerInstallationId, [$repository], $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $providerAffectedFiles, $external, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform);
}
if (!empty($errors)) {
throw new Exception(Exception::GENERAL_UNKNOWN, \implode("\n", $errors));
}
} elseif ($action === 'closed') {
$providerRepositoryId = $parsedPayload['repositoryId'] ?? '';
$providerPullRequestId = $parsedPayload['pullRequestNumber'] ?? '';