Skip to content

[BUG] Marketplace add ignores GITHUB_HOST — always resolves to github.com #582

@kkadete

Description

@kkadete

Describe the bug

apm marketplace add OWNER/REPO always contacts api.github.com regardless of the
GITHUB_HOST environment variable. When the marketplace repository lives on a GitHub
Enterprise (GHES or *.ghe.com) instance, the command fails with a misleading error:

[x] No marketplace.json found in 'OWNER/REPO'. Checked: marketplace.json,
.github/plugin/marketplace.json, .claude-plugin/marketplace.json

The file exists in the repository; it is simply unreachable because the wrong host is
contacted.

To Reproduce

  1. Set GITHUB_HOST to a GHE hostname, e.g. export GITHUB_HOST=myghe.example.com
  2. Authenticate: export GITHUB_APM_PAT_MYORG=<ghe-pat>
  3. Run: apm marketplace add myorg/my-marketplace
  4. Observe error — "No marketplace.json found" — even though the file is present at
    .github/plugin/marketplace.json in the repository

Expected behavior

apm marketplace add should resolve the bare OWNER/REPO against GITHUB_HOST (same
as all other APM commands), contact the correct GHE API endpoint, and register the
marketplace successfully.

Root cause (identified)

In src/apm_cli/commands/marketplace.py, the add command constructs MarketplaceSource
without a host field:

probe_source = MarketplaceSource(
    name=display_name,
    owner=owner,
    repo=repo_name,
    branch=branch,
    # host is omitted → defaults to "github.com"
)

MarketplaceSource.host defaults to "github.com" (see models.py), so
_auto_detect_path builds GitHub Contents API URLs against api.github.com instead of
the configured enterprise host.

All other APM commands use default_host() from apm_cli.utils.github_host, which
correctly reads GITHUB_HOST. The marketplace add command simply never calls it.

Proposed fix

Add a new "--host" parameter, to get the specific host get_host() that override the default host of the marketplace when constructing MarketplaceSource in the add command:

probe_source = MarketplaceSource(
    name=display_name,
    owner=owner,
    repo=repo_name,
    branch=branch,
    host=get_host(),   # ← respects GITHUB_HOST, and override from the "--host" parameter
)

The same fix should be applied to the final source = MarketplaceSource(...) constructed
after path detection, to ensure the persisted entry in marketplaces.json also carries
the correct host.

Environment

  • OS: Windows
  • APM Version: 0.8.10

Additional context

The authentication docs
correctly state that GITHUB_HOST controls which host bare package names resolve against.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageNew issue, not yet reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions