From 43154ee63bf9f37b67dc272b37e634c74aef0c79 Mon Sep 17 00:00:00 2001 From: Benjamin Bradley Date: Tue, 26 Apr 2022 15:36:00 -0500 Subject: [PATCH] Allow config-based overrides of github server hostname --- README.md | 12 ++++++++++++ .../RepositoryProviders/GitHub/GitHubProvider.php | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff427474..4da1f203 100644 --- a/README.md +++ b/README.md @@ -413,6 +413,18 @@ build-tools: url: hostname ``` +#### Self-Hosted GitHub + +The GitHub URL used by Build Tools can be defined by updating the `build-tools:provider:git:github:url` configuration value, as demonstrated by the example below. Note that you will need to replace `hostname` with the actual GitHub instance hostname. + +``` +build-tools: + provider: + git: + github: + url: hostname +``` + #### Starter Site Shortcuts If you often create sites based on certain common starter sites, you may also use your Terminus configuration file to define custom starter site shortcuts. The example below defines shortcuts for the Lightning and Contenta distributions: diff --git a/src/ServiceProviders/RepositoryProviders/GitHub/GitHubProvider.php b/src/ServiceProviders/RepositoryProviders/GitHub/GitHubProvider.php index d257c4a3..8f1d2518 100644 --- a/src/ServiceProviders/RepositoryProviders/GitHub/GitHubProvider.php +++ b/src/ServiceProviders/RepositoryProviders/GitHub/GitHubProvider.php @@ -4,6 +4,7 @@ use Pantheon\TerminusBuildTools\ServiceProviders\RepositoryProviders\BaseGitProvider; use Psr\Log\LoggerAwareInterface; +use Robo\Config\Config; use Pantheon\Terminus\Exceptions\TerminusException; use Pantheon\TerminusBuildTools\Credentials\CredentialClientInterface; use Pantheon\TerminusBuildTools\ServiceProviders\RepositoryProviders\GitProvider; @@ -25,9 +26,19 @@ class GitHubProvider extends BaseGitProvider implements GitProvider, LoggerAware protected $api; + public function __construct(Config $config) + { + parent::__construct($config); + $privateGithub = $this->config->get('build-tools.provider.git.github.url'); + if (!empty($privateGithub)) { + $this->baseGitUrl = 'git@' . $privateGithub; + } + } + public function infer($url) { - return strpos($url, 'github.com') !== false; + $githubDomain = explode('@', $this->baseGitUrl)[1]; + return strpos($url, $githubDomain) !== false; } /**