当前位置: 首页>>代码示例>>PHP>>正文


PHP Github\Client类代码示例

本文整理汇总了PHP中Github\Client的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setToken

 /**
  * Set oauth token (to increase API limit to 5000 per hour, instead of default 60)
  *
  * @param Client $client
  */
 protected function setToken(Client $client)
 {
     $token = getenv('BOWERPHP_TOKEN');
     if (!empty($token)) {
         $client->authenticate($token, null, Client::AUTH_HTTP_TOKEN);
     }
 }
开发者ID:iamduyu,项目名称:bowerphp,代码行数:12,代码来源:Command.php

示例2: execute

 /**
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $changelog = array();
     $client = new Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache')));
     $client->authenticate($input->getArgument("token"), null, Client::AUTH_HTTP_TOKEN);
     $pullRequestAPI = $client->api('pull_request');
     $paginator = new ResultPager($client);
     $parameters = array($input->getArgument("organisation"), $input->getArgument("repository"), array('state' => 'closed'));
     $pullRequests = $paginator->fetchAll($pullRequestAPI, 'all', $parameters);
     $mergedPullRequests = array_filter($pullRequests, function ($pullRequest) {
         return !empty($pullRequest["merged_at"]);
     });
     foreach ($mergedPullRequests as $pullRequest) {
         if (empty($pullRequest['milestone'])) {
             $milestone = "No Milestone Selected";
         } else {
             $milestone = $pullRequest['milestone']['title'] . " / " . strftime("%Y-%m-%d", strtotime($pullRequest['milestone']['due_on']));
         }
         if (!array_key_exists($milestone, $changelog)) {
             $changelog[$milestone] = array();
         }
         $changelog[$milestone][] = $pullRequest;
     }
     uksort($changelog, 'version_compare');
     $changelog = array_reverse($changelog);
     echo "# Changelog";
     foreach ($changelog as $milestone => $pullRequests) {
         echo "\n\n## {$milestone}\n\n";
         foreach ($pullRequests as $pullRequest) {
             echo "* " . $pullRequest['title'] . " [#" . $pullRequest['number'] . "](" . $pullRequest['html_url'] . ") ([@" . $pullRequest['user']['login'] . "](" . $pullRequest['user']['html_url'] . ")) \n";
         }
     }
     //var_dump($changelog);
 }
开发者ID:kunstmaan,项目名称:github-flow-changelog,代码行数:39,代码来源:ChangelogCommand.php

示例3: showPage

 public function showPage()
 {
     if (isset($_POST["register-data"]) && isset($_POST["register-password"])) {
         try {
             $client = new Client();
             $client->authenticate($_POST["register-data"], Client::AUTH_HTTP_TOKEN);
             $user = $client->api('current_user')->show();
             $repos = [];
             foreach ($client->api('current_user')->repositories('member', 'updated', 'desc') as $repo) {
                 $repos[] = ["name" => $repo["full_name"], "isPrivate" => $repo["private"]];
             }
             if (strlen($_POST["register-password"]) >= 6) {
                 Users::createUser($user["login"], $client->api('current_user')->emails()->all()[0], $_POST["register-password"], $_POST["register-data"], $repos);
                 Channels::addChannels($repos);
                 echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["user" => $user])]);
             } else {
                 echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["error" => "Passwords must be at least 6 characters long."])]);
             }
         } catch (\Exception $e) {
             echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["error" => "Oh no! Your registration couldn't be completed. Do you already have an account? Is your token valid?"])]);
         }
     } else {
         echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), [])]);
     }
     //echo $this->getTemplateEngine()->render($this->getTemplate(), []);
 }
开发者ID:xpyctum,项目名称:ShogChat,代码行数:26,代码来源:register.php

示例4: execute

 /**
  * (non-PHPdoc)
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelper('dialog');
     try {
         $client = new Client();
         $username = $input->getOption('username');
         if (!$username) {
             $username = $dialog->ask($output, 'Please enter your GitHub username: ');
         }
         $password = $input->getOption('password');
         if (!$password) {
             $password = $dialog->askHiddenResponse($output, 'Please enter your GitHub password: ');
         }
         $client->authenticate($username, $password, Client::AUTH_HTTP_PASSWORD);
         $forkService = $this->getForkService($input, $client);
         $forkedRepositoryList = $forkService->fork();
         $message = $this->formatMessage($forkedRepositoryList);
     } catch (\InvalidArgumentException $exception) {
         $message = $exception->getMessage();
     } catch (GithubRuntimeException $exception) {
         $message = $exception->getMessage();
         $message = "<error>{$message}</error>";
     } finally {
         $output->writeln($message);
     }
 }
开发者ID:kinncj,项目名称:forker,代码行数:30,代码来源:Fork.php

示例5: handleResponse

 public function handleResponse(UserResponseInterface $response, UserService $userService)
 {
     $fields = $response->getResponse();
     $gitHubLogin = $fields['login'];
     $accessToken = $response->getAccessToken();
     $user = $userService->findByGitHubLogin($gitHubLogin);
     if (null === $user) {
         throw new UsernameNotFoundException();
     }
     $oAuthUser = new OAuthUser($user);
     $oAuthUser->addRole('ROLE_GITHUB_USER');
     $oAuthUser->setAccessToken($accessToken);
     if (array_key_exists('name', $fields)) {
         $gitHubName = $fields['name'];
         $oAuthUser->setRealName($gitHubName);
     } else {
         $oAuthUser->setRealName($gitHubLogin);
     }
     $client = new Client();
     $client->setOption('api_version', 'v3');
     $client->authenticate($response->getAccessToken(), Client::AUTH_HTTP_TOKEN);
     /* @var \Github\Api\CurrentUser $currentUserApi */
     $currentUserApi = $client->api('current_user');
     $emails = $currentUserApi->emails();
     $allEMails = $emails->all();
     $oAuthUser->setEmail($this->getPrimaryEmailAddress($allEMails));
     return $oAuthUser;
 }
开发者ID:terretta,项目名称:gitki.php,代码行数:28,代码来源:GitHubResponseHandler.php

示例6: testInjectApi

 public function testInjectApi()
 {
     $client = new Client();
     $userApiMock = $this->getMockBuilder('Github\\Api\\ApiInterface')->getMock();
     $client->setApi('user', $userApiMock);
     $this->assertSame($userApiMock, $client->getUserApi());
 }
开发者ID:nickl-,项目名称:php-github-api,代码行数:7,代码来源:ClientTest.php

示例7: register

 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app['github'] = $app->share(function () {
         $client = new Client(new CachedHttpClient(['cache_dir' => __DIR__ . '/../../../app/cache/github-api-cache']));
         return new GithubAdapter($client->getHttpClient());
     });
 }
开发者ID:CipHuK,项目名称:phansible,代码行数:10,代码来源:GithubProvider.php

示例8: getEngine

 protected function getEngine()
 {
     $client = new Client();
     if ($client->rateLimit()->getCoreLimit() < 1) {
         $this->markTestSkipped('The github API rate limit is reached, so this engine cannot be tested.');
     }
     return new GitHubMarkdownEngine();
 }
开发者ID:qasim,项目名称:twig-markdown,代码行数:8,代码来源:GithubMarkdownEngineTest.php

示例9: setup

 /**
  * Construct GitSpam instance with its dependencies
  *
  * @param $username
  * @param $password
  *
  * @return GitSpam
  */
 private function setup($username, $password)
 {
     $client = new GithubAPIClient();
     $client->authenticate($username, $password);
     $commitReader = new YouTrackCommitReader();
     $gitSpammer = new GitSpammer($client, $commitReader);
     return $gitSpammer;
 }
开发者ID:matks,项目名称:gitspammer,代码行数:16,代码来源:ConsoleManager.php

示例10: run

/**
 * Runs pull request validation
 *
 * @param Client $client    GitHub client
 * @param Config $config    Configuration
 * @param array  $arguments Command line arguments
 *
 * @return int              Exit code
 * @throws \InvalidArgumentException
 */
function run(Client $client, Config $config, array $arguments)
{
    $config = $config->getParams();
    $client->authenticate($config['token'], null, Client::AUTH_URL_TOKEN);
    $changeset = new Changeset($client, array_shift($arguments), array_shift($arguments), array_shift($arguments));
    $runner = new Runner();
    return $runner->run($changeset, $arguments);
}
开发者ID:morozov,项目名称:diff-sniffer-pull-request,代码行数:18,代码来源:diff-sniffer.php

示例11: getClient

 protected function getClient()
 {
     $httpClient = new CachedHttpClient(['cache_dir' => storage_path(config('services.github.cache_url'))]);
     $client = new Client($httpClient);
     //dd($client);
     $client->authenticate(auth()->user()->github_token, 'http_token');
     return $client;
 }
开发者ID:ilmala,项目名称:snippets,代码行数:8,代码来源:Gist.php

示例12: createClient

 public static function createClient(SettingsManager $settingsManager)
 {
     $settings = new GeneralSettings();
     $settingsManager->loadSettings($settings);
     $client = new Client();
     $client->authenticate($settings->githubToken, null, Client::AUTH_HTTP_TOKEN);
     return $client;
 }
开发者ID:simpleci,项目名称:frontend,代码行数:8,代码来源:GithubApi.php

示例13: interact

 /**
  * {@inheritdoc}
  */
 public function interact(InputInterface $input, OutputInterface $output)
 {
     $config = parent::interact($input, $output);
     // Do authentication now so we can detect 2fa
     if (self::AUTH_HTTP_PASSWORD === $config['authentication']['http-auth-type']) {
         $client = new Client();
         try {
             $client->authenticate($config['authentication']['username'], $config['authentication']['password-or-token']);
             try {
                 // Make a call to test authentication
                 $client->api('authorizations')->all();
             } catch (TwoFactorAuthenticationRequiredException $e) {
                 // Create a random authorization to make GitHub send the code
                 // We expect an exception, which gets cached by the next catch-block
                 // Note. This authorization is not actually created
                 $client->api('authorizations')->create(['note' => 'Gush on ' . gethostname() . mt_rand(), 'scopes' => ['public_repo']]);
             }
         } catch (TwoFactorAuthenticationRequiredException $e) {
             $isAuthenticated = false;
             $authenticationAttempts = 0;
             $authorization = [];
             $scopes = ['user', 'user:email', 'public_repo', 'repo', 'repo:status', 'read:org'];
             $output->writeln(sprintf('Two factor authentication of type %s is required: ', trim($e->getType())));
             // We already know the password is valid, we just need a valid code
             // Don't want fill in everything again when you know its valid ;)
             while (!$isAuthenticated) {
                 // Prevent endless loop with a broken test
                 if ($authenticationAttempts > 500) {
                     $output->writeln('<error>To many attempts, aborting.</error>');
                     break;
                 }
                 if ($authenticationAttempts > 0) {
                     $output->writeln('<error>Authentication failed please try again.</error>');
                 }
                 try {
                     $code = $this->questionHelper->ask($input, $output, (new Question('Authentication code: '))->setValidator([$this, 'validateNoneEmpty']));
                     // Use a date with time to make sure its unique
                     // Its not possible get existing authorizations, only a new one
                     $time = (new \DateTime('now', new \DateTimeZone('UTC')))->format('Y-m-d\\TH:i:s');
                     $authorization = $client->api('authorizations')->create(['note' => sprintf('Gush on %s at %s', gethostname(), $time), 'scopes' => $scopes], $code);
                     $isAuthenticated = isset($authorization['token']);
                 } catch (TwoFactorAuthenticationRequiredException $e) {
                     // Noop, continue the loop, try again
                 } catch (\Exception $e) {
                     $output->writeln("<error>{$e->getMessage()}</error>");
                     $output->writeln('');
                 }
                 ++$authenticationAttempts;
             }
             if ($isAuthenticated) {
                 $config['authentication']['http-auth-type'] = self::AUTH_HTTP_TOKEN;
                 $config['authentication']['password-or-token'] = $authorization['token'];
             }
         }
     }
     return $config;
 }
开发者ID:mistymagich,项目名称:gush,代码行数:60,代码来源:GitHubConfigurator.php

示例14: let

 public function let(Client $client, HookSettings $hookSettings, GithubRepo $githubRepo, Repo $repo, Hooks $hooks)
 {
     $githubRepo->getOwner()->willReturn('owner');
     $githubRepo->getName()->willReturn('repository');
     $client->repo()->willReturn($repo);
     $repo->hooks()->willReturn($hooks);
     $hookSettings->getCreateHookParams()->willReturn(['params']);
     $this->beConstructedWith($client, $hookSettings, $githubRepo);
 }
开发者ID:brankol,项目名称:devboard,代码行数:9,代码来源:HookClientSpec.php

示例15: findProjects

 /**
  * {@inheritdoc}
  */
 public function findProjects($name)
 {
     return $this->requestProjects($name, function ($name) {
         list($user) = explode('/', $name);
         return $this->client->user()->repositories($user);
     }, 'full_name');
 }
开发者ID:digitalkaoz,项目名称:issues,代码行数:10,代码来源:GithubTracker.php


注:本文中的Github\Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。