Add GitHub Enterprise (GHE) hostname support to dependency parsing#8
Add GitHub Enterprise (GHE) hostname support to dependency parsing#8danielmeppiel merged 4 commits intomicrosoft:mainfrom
Conversation
remove all hard coded github.com and replace with parameterised
GPT5 mocking the docs... :)
There was a problem hiding this comment.
Pull Request Overview
This PR adds GitHub Enterprise (GHE) hostname support to dependency parsing so apm can correctly detect and normalize repository references hosted on self-managed GitHub instances.
Key Changes:
- Introduces a new
github_hostutility module that centralizes GitHub hostname validation and URL construction - Updates dependency parsing to accept custom GHE hostnames (e.g.,
orgname.ghe.com) in addition togithub.com - Adds environment variable support (
GITHUB_HOST,APM_GITHUB_HOSTS) for configuring custom GitHub instances - Updates all tests to use the new hostname utilities for consistency
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/apm_cli/utils/github_host.py | New utility module providing hostname validation, URL construction, and token sanitization for GitHub and GHE instances |
| src/apm_cli/models/apm_package.py | Updates DependencyReference to support GHE hostnames, storing host information and using new utilities for validation |
| src/apm_cli/deps/github_downloader.py | Refactors to use github_host utilities for URL construction and token sanitization, adds host tracking for enterprise repos |
| src/apm_cli/adapters/client/copilot.py | Replaces hardcoded hostname allowlist with is_github_hostname() utility |
| tests/unit/test_github_host.py | New test file covering default_host(), is_github_hostname(), and sanitize_token_url_in_message() |
| tests/test_apm_package_models.py | Updates tests to use github_host utilities and adds GHE URL parsing test cases |
| tests/test_github_downloader_token_precedence.py | Updates URL assertions to use github_host utilities for consistency |
| tests/unit/test_registry_integration.py | Updates mock URLs to use default_host() for consistency |
| tests/unit/test_registry_client.py | Updates mock URLs to use default_host() for consistency |
| CONTRIBUTING.md | Updates testing instructions to recommend uv for running tests, adds fallback instructions for standard venv |
| class DependencyReference: | ||
| """Represents a reference to an APM dependency.""" | ||
| repo_url: str # e.g., "user/repo" or "github.com/user/repo" | ||
| host: Optional[str] = None # Optional host (github.com or enterprise host) |
There was a problem hiding this comment.
The comment describes the host field but doesn't explain when it's None vs when it's populated. Consider clarifying that host is extracted from the parsed dependency string and defaults to default_host() if not explicitly specified.
| host: Optional[str] = None # Optional host (github.com or enterprise host) | |
| host: Optional[str] = None # Host (e.g., github.com or enterprise host); extracted from the dependency string if specified, otherwise None. If None, defaults to default_host() when needed. |
| # Ensure host is set for enterprise repos | ||
| if getattr(dep_ref, 'host', None): | ||
| self.github_host = dep_ref.host |
There was a problem hiding this comment.
This pattern of checking and setting self.github_host is duplicated three times (lines 199-200, 213-214, 228-229). Consider extracting this into a helper method or setting it once before the conditional blocks to reduce duplication.
The runtime manager was calling setup_runtime_environment() without passing the env dict, which caused it to create a new os.environ.copy() and lose any tokens set in the CI environment. This fixes integration test failures where GITHUB_TOKEN and other secrets configured in GitHub Actions weren't reaching the runtime setup scripts, causing unauthenticated API requests and rate limiting. Fixes integration test failures in PR #8 and similar CI environments.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
We will need to document |
…osoft#8) - Drop unittest.TestCase from all 6 test classes - Replace self.assert* with bare assert statements - Replace tempfile.TemporaryDirectory with tmp_path fixture - Remove unused imports (tempfile, unittest)
Add support for GitHub Enterprise (GHE) hostnames in dependency parsing so apm can correctly detect and normalize repository references hosted on self-managed GitHub instances.
What changed
Update the dependency parsing logic to accept and validate custom GHE hostnames in addition to github.com.
Preserve backwards compatibility for existing github.com parsing behavior.
Add unit tests covering:
standard github.com repo strings
GHE hostname variants (with and without ports)
edge cases and invalid hostnames
Why
Users running packages on self-hosted GitHub instances faced incorrect parsing of dependency references. This change allows apm to work in GHE environments.
How to test
Run the included unit tests: uv run pytest (test docs updated)
Manually verify parsing by providing dependency strings that reference a GHE hostname (e.g., acompany.ghe.com/owner/repo) and confirming correct repo extraction.
Notes
No behavior change for public GitHub users.
Backwards-compatible and covered by tests.