Skip to content

fix(tia): support GitHub Enterprise remotes when fetching the shared baseline - #1900

Draft
yamenarahman wants to merge 1 commit into
pestphp:5.xfrom
yamenarahman:fix/tia-baseline-github-enterprise
Draft

fix(tia): support GitHub Enterprise remotes when fetching the shared baseline#1900
yamenarahman wants to merge 1 commit into
pestphp:5.xfrom
yamenarahman:fix/tia-baseline-github-enterprise

Conversation

@yamenarahman

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

Baseline fetching is a silent no-op on GitHub Enterprise Server.

BaselineSync::detectGitHubRepo() matched the origin remote against a literal github.com in all three URL shapes and returned null for anything else. fetchIfAvailable() returns false on that null before gh is reached, so on a remote such as git@github.foodics.com:pay/capital-api.git the whole feature turns itself off: no run is queried, no artifact is downloaded, no warning is printed, and the suite quietly records a local baseline instead. Setting GH_HOST cannot help, because gh is never invoked.

This makes the detection host-aware:

  • Pest\Plugins\Tia\GitHubRepository parses the origin remote of any host across the three shapes Pest already accepted — user@host:owner/repo, https://host[:port]/owner/repo and ssh://[user@]host[:port]/owner/repo — and carries the host next to the owner/repo name.
  • gh run list and gh run download get -R host/owner/repo, which is the [HOST/]OWNER/REPO form --repo documents.
  • gh api keeps the repos/owner/repo/actions/runs/<id>/artifacts path and gains --hostname host.
  • gh auth status gains --hostname host.
  • On github.com every one of those calls keeps its current arguments byte for byte: qualifiedName() returns the bare owner/repo and hostnameArguments() returns an empty array.

A remote that is not on github.com counts as GitHub only when gh is authenticated for its host. That is the rule gh itself applies to a repository's remotes, and it keeps a GitLab or Bitbucket remote the silent local-recording no-op it is today instead of turning it into a gh-is-not-authenticated panic.

Storage::projectKey() already read the origin remote host-agnostically, so the on-disk state key is untouched.

Tests:

  • tests/Unit/Plugins/Tia/GitHubRepository.php — the three URL shapes on github.com and on Enterprise hosts (git@github.foodics.com:pay/capital-api.git, https://github.example.com/org/repo, ssh://git@ghe.example.com:2222/org/repo.git), the shapes that stay rejected, reading .git/config, and the gh argument fragments each host produces.
  • tests/Features/Tia/RemoteBaseline.php — an end-to-end fetch from git@github.foodics.com:pay/capital-api.git asserting the recorded gh argv carries -R github.foodics.com/pay/capital-api, auth status --hostname github.foodics.com and api --hostname github.foodics.com repos/pay/capital-api/...; plus a case proving a host gh does not know records locally and never reaches gh run list. The existing github.com test now also asserts -R pestphp/tia-fixture and that no --hostname is passed anywhere.
  • The gh stub records its argv and honours gh auth status --hostname.

Run on PHP 8.4:

php bin/pest tests/Unit/Plugins/Tia/GitHubRepository.php   24 passed (70 assertions)
php bin/pest tests/Features/Tia/RemoteBaseline.php         12 passed (52 assertions)
php bin/pest --group=tia                                   204 passed, 1 skipped, 1 failed*
composer test:lint                                         rector OK, pint PASS (610 files)
composer test:type:check                                   phpstan: No errors

* Tests\Features\Tia\StateReclamation > a fatal error mid-file is a test error, not a truncation with dataset "parallel" fails the same way on a pristine 5.x checkout in my container, so it is not from this change.

Related:

Docs companion: pestphp/docs#378


🤖 Generated with Claude Code

…baseline

BaselineSync matched the origin remote against a literal github.com, so
fetchIfAvailable() returned false before gh ran on a GitHub Enterprise
Server remote. --tia --baselined then turned itself off with no warning,
and GH_HOST could not help because gh was never invoked.

GitHubRepository now parses the host out of the three remote shapes Pest
already accepted. gh run list and gh run download take the documented
-R [HOST/]OWNER/REPO, while gh api and gh auth status take --hostname
<host>; the gh api path keeps its repos/OWNER/REPO form. Every call on
github.com keeps its current arguments.

A host other than github.com counts as GitHub only when gh is
authenticated for it, so a GitLab remote stays the local-recording no-op
it is today.
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