Skip to content

Eliminate duplication in Forgejo adapter and tests#77

Merged
Meldiron merged 12 commits intomainfrom
copilot/add-forgejo-adapter-and-tests
Mar 24, 2026
Merged

Eliminate duplication in Forgejo adapter and tests#77
Meldiron merged 12 commits intomainfrom
copilot/add-forgejo-adapter-and-tests

Conversation

Copy link
Contributor

Copilot AI commented Mar 23, 2026

Forgejo::createWebhook() was an exact copy of Gitea::createWebhook() with only the hook type string changed. Similarly, ForgejoTest duplicated two full webhook test methods only to swap X-Gitea-* headers for X-Forgejo-*.

Source changes

  • Extracted getHookType(): string into Gitea (returns 'gitea'); createWebhook() now calls $this->getHookType()
  • Forgejo overrides only getHookType() returning 'forgejo' — the full createWebhook() override is removed
// Gitea.php
protected function getHookType(): string { return 'gitea'; }

// Forgejo.php
protected function getHookType(): string { return 'forgejo'; }

Test changes

  • Added protected string $webhookEventHeader and $webhookSignatureHeader to GiteaTest (defaults: X-Gitea-Event, X-Gitea-Signature); webhook tests use these properties instead of hardcoded strings
  • ForgejoTest overrides only those two properties; the duplicated testWebhookPushEvent() and testWebhookPullRequestEvent() methods are removed

Autoload fix

  • Added "Utopia\\Tests\\VCS\\": "tests/VCS" to autoload-dev in composer.json. The existing "Utopia\\Tests\\" mapping resolved Utopia\Tests\VCS\Adapter\GiteaTest to tests/VCS/VCS/Adapter/GiteaTest.php (incorrect double-VCS), causing a fatal Class "GiteaTest" not found when PHPUnit loaded ForgejoTest.php first (alphabetical order).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • codeberg.org
    • Triggering command: /usr/libexec/docker/cli-plugins/docker-compose /usr/libexec/docker/cli-plugins/docker-compose compose run --rm tests sh -c cd /usr/local/src && php vendor/bin/phpstan analyse --level 8 --memory-limit 512M -c phpstan.neon src tests 2>&1 (dns block)
  • https://api.github.com/repos/Nevay/spi/zipball/e7078767866d0a9e0f91d3f9d42a832df5e39002
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/Nyholm/psr7-server/zipball/4335801d851f554ca43fa6e7d2602141538854dc
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/adhocore/php-jwt/zipball/ad417603d9d45578b6af2089ad5b78f101c82367
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/laravel/pint/zipball/bdec963f53172c5e36330f3a400604c69bf02d39
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/opentelemetry-php/api/zipball/df5197c6fd0ddd8e9883b87de042d9341300e2ad
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/opentelemetry-php/context/zipball/d4c4470b541ce72000d18c339cfee633e4c8e0cf
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/opentelemetry-php/gen-otlp-protobuf/zipball/673af5b06545b513466081884b47ef15a536edde
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/opentelemetry-php/sem-conv/zipball/e613bc640a407def4991b8a936a9b27edd9a3240
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/php-http/discovery/zipball/82fe4c73ef3363caed49ff8dd1539ba06044910d
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/ebe8010a61b2ae0cff0d246fe1c4d44e9f7dfa6d
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/e4df00b9b3571187db2831ae9aada2c6efbd715d
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/14c6ba52f95a36c3d27c835d65efc7123c446e8c
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/b6781316bdcd28260904e7cc18ec983d0d2ef4f6
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)
  • https://api.github.com/repos/symfony/polyfill-php82/zipball/5d2ed36f7734637dacc025f179698031951b1692
    • Triggering command: /usr/local/bin/php php /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist b99b5529006b5cbechmod (http block)

If you need me to access, download, or install something from one of these locations, you can either:


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI and others added 2 commits March 23, 2026 15:49
…same dir structure as Gitea)

Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/utopia-php/vcs/sessions/b7718762-2b6f-4dc1-8f0d-3561ae2b01e4
@Meldiron
Copy link
Contributor

@greptile

@greptile-apps
Copy link

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR cleanly eliminates duplication between the Forgejo and Gitea adapters and their test suites by introducing a getHookType(): string hook method and parameterised webhook header properties, while also adding a full Forgejo Docker service for integration testing. The changes are well-structured and the volume/path wiring between forgejo-bootstrap and ForgejoTest is correct.

  • Gitea::getHookType() returns 'gitea'; createWebhook() now calls $this->getHookType() — the previously duplicated method body in Forgejo is removed.
  • Forgejo is reduced to only getName() and getHookType() overrides, inheriting all other behaviour from Gitea.
  • GiteaTest gains $webhookEventHeader / $webhookSignatureHeader instance properties; ForgejoTest overrides them with X-Forgejo-* values so the inherited webhook tests assert the correct headers.
  • The request-catcher URL env-var name (TESTS_GITEA_REQUEST_CATCHER_URL) is still hardcoded inside the inherited webhook test methods; when ForgejoTest runs those tests it resolves the Gitea-specific variable, which is a minor inconsistency with the otherwise complete parameterization.

Confidence Score: 4/5

  • Safe to merge; the refactoring is logically correct with one minor style gap remaining.
  • All functional logic is sound: the hook-type extraction, volume paths, and header overrides are correct. The only issue is the hardcoded TESTS_GITEA_REQUEST_CATCHER_URL env-var name inside the inherited webhook methods, which is a naming inconsistency rather than a runtime bug.
  • tests/VCS/Adapter/GiteaTest.php — lines 1485 and 1542 use a Gitea-specific env-var name that ForgejoTest now silently inherits.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/Gitea.php Adds getHookType(): string returning 'gitea' and replaces the hardcoded 'gitea' string in createWebhook() with $this->getHookType() — clean, minimal change.
src/VCS/Adapter/Git/Forgejo.php New adapter that only overrides getName() and getHookType() — the previously duplicated createWebhook() body is now correctly removed.
tests/VCS/Adapter/GiteaTest.php Introduces $webhookEventHeader / $webhookSignatureHeader instance properties and uses them in the two webhook tests; also widens setupGitea() visibility to protected. The request-catcher URL env var (TESTS_GITEA_REQUEST_CATCHER_URL) remains hardcoded in inherited methods, leaving an incomplete parameterization for subclasses.
tests/VCS/Adapter/ForgejoTest.php New test class that overrides only the Forgejo-specific pieces (adapter, headers, token setup) and inherits all ~40 test methods from GiteaTest — correct approach.
docker-compose.yml Adds Forgejo and forgejo-bootstrap services following the exact same pattern as Gitea; token written to /data/gitea/token.txt on the forgejo-data volume and read by the tests container at /forgejo-data/gitea/token.txt — paths are consistent.

Reviews (2): Last reviewed commit: "Fix test namespaces" | Re-trigger Greptile

Copilot AI and others added 2 commits March 23, 2026 16:19
…d createWebhook()

Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/utopia-php/vcs/sessions/9018a712-0c46-43ff-9933-d768660aaebe
Copilot AI changed the title Supporting Forgejo adapter based on Gitea Eliminate duplication in Forgejo adapter and tests Mar 23, 2026
@Meldiron Meldiron marked this pull request as ready for review March 23, 2026 16:28
Copy link
Contributor

@Meldiron Meldiron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Meldiron Meldiron merged commit 863361e into main Mar 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants