Skip to content

Support for ghe.com hosts #183

@weyfonk

Description

@weyfonk

Github Apps hosted on Github Enterprise Server instances and data-resident Cloud offerings rely on base URLs other than https://api.github.com.

Attempting to obtain a token for such an app using ghinstallation.New results in an error such as:

Could not authenticate as GitHub App installation: could not refresh installation id <id>'s token: received non 2xx response status "404 Not Found" when fetching https://v-api-github-com.adclosenn.dev/app/installations/<id>/access_tokens

Indeed, ghinstallation.New calls NewAppsTransport which, through NewAppsTransportFromPrivateKey, returns an AppTransport struct with a hard-coded base URL.

This can be worked around as follows:

// instead of a call to `ghinstallation.New`:
atr, err := ghinstallation.NewAppsTransport(tr, appID, privateKey)
if err != nil {
        return nil, fmt.Errorf("failed to create transport for Github App: %w", err)
}

atr.BaseURL, err = getBaseURL(repoURL)
if err != nil {
        return nil, fmt.Errorf("failed to extract base Github App URL from repo URL: %w", err)
}

return ghinstallation.NewFromAppsTransport(atr, installationID), nil

However, that approach feels a bit hacky.
Are there plans to support ghe.com? Asked differently, if I were to submit a pull request in this direction:

  • would there be interest in reviewing and merging it?
  • would anyone be able and willing to test it against an actual Github App hosted on a Github Enterprise Server instance?

Edit: just noticed that the above approach is fairly close to the one used in the README for creating HTTPs clients for Github Enterprise. My use case is git cloning, but this issue may then well be redundant. Happy to discuss.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions