Skip to content

Loading…

Add github-domains config value for GitHub Enterprise setups, fixes #728 #1086

Closed
wants to merge 1 commit into from

4 participants

@Seldaek
Composer member

Not fool proof yet, should be tested, waiting for feedback on #728.

@till

What I just noticed while looking at this – when I add a private github repo to satis, it doesn't seem to populate dist in packages.json? Should I open a seperate issue?

@stof

@till yes, it is a separate thing

@till

@stof Do you think it's for composer, or for satis?

@Seldaek
Composer member

It's a composer thing, and it's at #455

@kriswallsmith

We use GH:E at OpenSky… anything I can do to help get this over the finish line?

@Seldaek Seldaek closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2 doc/04-schema.md
@@ -570,6 +570,8 @@ The following options are supported:
* **github-protocols:** Defaults to `["git", "https", "http"]`. A list of
protocols to use for github.com clones, in priority order. Use this if you are
behind a proxy or have somehow bad performances with the git protocol.
+* **github-domains:** Defaults to `["github.com"]`. A list of domains to use in
+ github mode. This is used for GitHub Enterprise setups.
* **notify-on-install:** Defaults to `true`. Composer allows repositories to
define a notification URL, so that they get notified whenever a package from
that repository is installed. This option allows you to disable that behaviour.
View
7 res/composer-schema.json
@@ -130,6 +130,13 @@
"items": {
"type": "string"
}
+ },
+ "github-domains": {
+ "type": "array",
+ "description": "A list of domains to use in github mode. This is used for GitHub Enterprise setups, defaults to [\"github.com\"].",
+ "items": {
+ "type": "string"
+ }
}
}
},
View
1 src/Composer/Config.php
@@ -23,6 +23,7 @@ class Config
'bin-dir' => '{$vendor-dir}/bin',
'notify-on-install' => true,
'github-protocols' => array('git', 'https', 'http'),
+ 'github-domains' => array('github.com'),
);
public static $defaultRepositories = array(
View
25 src/Composer/Downloader/GitDownloader.php
@@ -51,8 +51,8 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
// capture username/password from github URL if there is one
$this->process->execute(sprintf('cd %s && git remote -v', escapeshellarg($path)), $output);
- if (preg_match('{^composer\s+https://(.+):(.+)@github.com/}im', $output, $match)) {
- $this->io->setAuthorization('github.com', $match[1], $match[2]);
+ if (preg_match('{^composer\s+https://(.+):(.+)@'.$this->getGitHubDomainsRegex().'/}im', $output, $match)) {
+ $this->io->setAuthorization($match[3], $match[1], $match[2]);
}
$commandCallable = function($url) use ($ref, $path, $command) {
@@ -150,7 +150,7 @@ protected function runCommand($commandCallable, $url, $path = null)
$handler = array($this, 'outputHandler');
// public github, autoswitch protocols
- if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
+ if (preg_match('{^(?:https?|git)(://'.$this->getGitHubDomainsRegex().'/.*)}', $url, $match)) {
$protocols = $this->config->get('github-protocols');
if (!is_array($protocols)) {
throw new \RuntimeException('Config value "github-protocols" must be an array, got '.gettype($protocols));
@@ -173,7 +173,7 @@ protected function runCommand($commandCallable, $url, $path = null)
$command = call_user_func($commandCallable, $url);
if (0 !== $this->process->execute($command, $handler)) {
- if (preg_match('{^git@github.com:(.+?)\.git$}i', $url, $match) && $this->io->isInteractive()) {
+ if (preg_match('{^git@'.$this->getGitHubDomainsRegex().':(.+?)\.git$}i', $url, $match) && $this->io->isInteractive()) {
// private github repository without git access, try https with auth
$retries = 3;
$retrying = false;
@@ -181,14 +181,14 @@ protected function runCommand($commandCallable, $url, $path = null)
if ($retrying) {
$this->io->write('Invalid credentials');
}
- if (!$this->io->hasAuthorization('github.com') || $retrying) {
+ if (!$this->io->hasAuthorization($match[1]) || $retrying) {
$username = $this->io->ask('Username: ');
$password = $this->io->askAndHideAnswer('Password: ');
- $this->io->setAuthorization('github.com', $username, $password);
+ $this->io->setAuthorization($match[1], $username, $password);
}
- $auth = $this->io->getAuthorization('github.com');
- $url = 'https://'.$auth['username'] . ':' . $auth['password'] . '@github.com/'.$match[1].'.git';
+ $auth = $this->io->getAuthorization($match[1]);
+ $url = 'https://'.$auth['username'] . ':' . $auth['password'] . '@'.$match[1].'/'.$match[2].'.git';
$command = call_user_func($commandCallable, $url);
if (0 === $this->process->execute($command, $handler)) {
@@ -218,6 +218,11 @@ public function outputHandler($type, $buffer)
}
}
+ protected function getGitHubDomainsRegex()
+ {
+ return '('.implode('|', array_map('preg_quote', $this->config->get('github-domains'))).')';
+ }
+
protected function throwException($message, $url)
{
if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
@@ -230,8 +235,8 @@ protected function throwException($message, $url)
protected function setPushUrl(PackageInterface $package, $path)
{
// set push url for github projects
- if (preg_match('{^(?:https?|git)://github.com/([^/]+)/([^/]+?)(?:\.git)?$}', $package->getSourceUrl(), $match)) {
- $pushUrl = 'git@github.com:'.$match[1].'/'.$match[2].'.git';
+ if (preg_match('{^(?:https?|git)://'.$this->getGitHubDomainsRegex().'/([^/]+)/([^/]+?)(?:\.git)?$}', $package->getSourceUrl(), $match)) {
+ $pushUrl = 'git@'.$match[1].':'.$match[2].'/'.$match[3].'.git';
$cmd = sprintf('git remote set-url --push origin %s', escapeshellarg($pushUrl));
$this->process->execute($cmd, $ignoredOutput, $path);
}
View
5 tests/Composer/Test/Downloader/GitDownloaderTest.php
@@ -23,10 +23,7 @@ protected function getDownloaderMock($io = null, $config = null, $executor = nul
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
if (!$config) {
- $config = $this->getMock('Composer\Config');
- $config->expects($this->any())
- ->method('has')
- ->will($this->returnValue(false));
+ $config = new Config();
}
return new GitDownloader($io, $config, $executor, $filesystem);
Something went wrong with that request. Please try again.