فهرست منبع

quick workaround for Github API limit

Thomas Adam 12 سال پیش
والد
کامیت
1bd5d88b02
2فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 13 0
      src/Composer/Repository/Vcs/GitHubDriver.php
  2. 6 0
      src/Composer/Util/RemoteFilesystem.php

+ 13 - 0
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -292,6 +292,19 @@ class GitHubDriver extends VcsDriver
                         $this->io->setAuthorization($this->originUrl, $username, $password);
                         break;
 
+                    case 403:
+                        if (!$this->io->hasAuthorization($this->originUrl)) {
+                            if (!$this->io->isInteractive()) {
+                                $this->io->write('<error>API limit exhausted. Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your username and password to increase the API limit</error>');
+                                throw $e;
+                            }
+                            $this->io->write('API limit exhausted. Authentication required for larger API limit (<info>'.$this->url.'</info>):');
+                            $username = $this->io->ask('Username: ');
+                            $password = $this->io->askAndHideAnswer('Password: ');
+                            $this->io->setAuthorization($this->originUrl, $username, $password);
+                        }
+                        break;
+
                     default:
                         throw $e;
                         break;

+ 6 - 0
src/Composer/Util/RemoteFilesystem.php

@@ -207,6 +207,12 @@ class RemoteFilesystem
                 }
                 break;
 
+            case STREAM_NOTIFY_AUTH_RESULT:
+                if (403 === $messageCode) {
+                    throw new TransportException($message, 403);
+                }
+                break;
+
             case STREAM_NOTIFY_FILE_SIZE_IS:
                 if ($this->bytesMax < $bytesMax) {
                     $this->bytesMax = $bytesMax;