Skip to content

Add GitHub Enterprise (GHE) hostname support to dependency parsing#8

Merged
danielmeppiel merged 4 commits intomicrosoft:mainfrom
richgo:main
Oct 28, 2025
Merged

Add GitHub Enterprise (GHE) hostname support to dependency parsing#8
danielmeppiel merged 4 commits intomicrosoft:mainfrom
richgo:main

Conversation

@richgo
Copy link
Contributor

@richgo richgo commented Oct 17, 2025

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.

@richgo richgo mentioned this pull request Oct 17, 2025
@richgo richgo marked this pull request as draft October 17, 2025 16:50
remove all hard coded github.com and replace with parameterised
GPT5 mocking the docs... :)
@richgo richgo marked this pull request as ready for review October 17, 2025 18:59
@danielmeppiel danielmeppiel requested a review from Copilot October 27, 2025 10:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_host utility module that centralizes GitHub hostname validation and URL construction
  • Updates dependency parsing to accept custom GHE hostnames (e.g., orgname.ghe.com) in addition to github.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)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment on lines +198 to +200
# Ensure host is set for enterprise repos
if getattr(dep_ref, 'host', None):
self.github_host = dep_ref.host
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
danielmeppiel added a commit that referenced this pull request Oct 28, 2025
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>
@danielmeppiel
Copy link
Collaborator

We will need to document GITHUB_HOST and APM_GITHUB_HOSTS based on src/apm_cli/utils/github_host.py‎ for different use cases and scenarios (github.com, GHE Server, GHE DR Cloud)

@danielmeppiel danielmeppiel merged commit 245a4b3 into microsoft:main Oct 28, 2025
sergio-sisternes-epam added a commit to sergio-sisternes-epam/apm that referenced this pull request Mar 2, 2026
…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)
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.

3 participants