本文整理汇总了PHP中Github\Client::api方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::api方法的具体用法?PHP Client::api怎么用?PHP Client::api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Github\Client
的用法示例。
在下文中一共展示了Client::api方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContributors
public function getContributors($link = null)
{
$api = $this->client->api('repo');
$paginator = new ResultPager($this->client);
$parameters = [$this->config['contributors']['user'], $this->config['contributors']['repository']];
return ['contributors' => $paginator->fetch($api, 'contributors', $parameters), 'links' => $paginator->getPagination()];
}
示例2: 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(), []);
}
示例3: build
public function build($username, $repository)
{
$this->repository = new Repository($username, $repository);
// repository data
$data = $this->client->api('repo')->show($this->repository->username, $this->repository->repository);
$this->repository->size = $data['size'];
$this->repository->stargazersCount = $data['stargazers_count'];
$this->repository->forks = $data['forks'];
$this->repository->openIssues = $data['open_issues'];
$this->repository->subscribersCount = $data['subscribers_count'];
// repository commit activity
do {
$activity = $this->client->api('repo')->activity($this->repository->username, $this->repository->repository);
$responseStatusCode = $this->client->getHttpClient()->getLastResponse()->getStatusCode();
if ($responseStatusCode != 200) {
sleep(3);
} else {
break;
}
} while (true);
$commitsLastYear = array_map(function (array $weekCommits) {
return $weekCommits['total'];
}, $activity);
$this->repository->commitsCount = array_sum($commitsLastYear);
$this->repository->commitsLastMonthCount = array_sum(array_slice($commitsLastYear, -4));
$this->repository->avgCommitsPerWeek = count($commitsLastYear) > 0 ? floor(array_sum($commitsLastYear) / count($commitsLastYear)) : 0;
// repository contributors
$paginator = new ResultPager($this->client);
$contributors = $paginator->fetchAll($this->client->api('repo'), 'contributors', [$this->repository->username, $this->repository->repository, true]);
$this->repository->contributorsCount = count($contributors);
// user data
$user = $this->client->api('user')->show($this->repository->username);
$this->repository->userPublicRepos = $user['public_repos'];
return $this;
}
示例4: find
/**
* Finds the repositories
*
* @return array
*/
public function find()
{
/** @var Repo $repositoryApi */
$repositoryApi = $this->github->api('repo');
$repositories = $this->fetchRepositoryApi($repositoryApi, $this->query);
$forkedRepositories = $this->fetchRepositoryApi($repositoryApi, $this->forkedRepoQuery);
return array_merge($repositories, $forkedRepositories);
}
示例5: getGist
/**
* @param $gistId
* @return array
* @throws GistNotFoundException
*/
public function getGist($gistId)
{
try {
return $this->github->api('gists')->show($gistId);
} catch (Exception $e) {
throw new GistNotFoundException($gistId, $e->getMessage());
}
}
示例6: execute
/**
* @param Package $package
*
* @return \Guzzle\Http\EntityBodyInterface|mixed|string
*/
public function execute(Package $package)
{
/** @var Repo $githubRepository */
$githubRepository = $this->client->api('repo');
$fork = $githubRepository->forks()->create($package->getUsername(), $package->getRepoName());
$this->dispatchEvent(StepsEvents::REPOSITORY_FORKED, new RepositoryForkedEvent($fork));
return $fork;
}
示例7: analysePR
/**
* Analyse Pull Request
*
* @param string $repositoryOwner
* @param string $repositoryName
* @param integer $pullRequestID
* @return array
*/
public function analysePR($repositoryOwner, $repositoryName, $pullRequestID)
{
$commits = $this->githubClient->api('pull_request')->commits($repositoryOwner, $repositoryName, $pullRequestID);
if (!$commits) {
throw new Exception('Cannot fetch Pull Request data');
}
$commitsAnalysisResults = $this->commitReader->analyseCommits($commits);
return $commitsAnalysisResults;
}
示例8: getFileContents
/**
* Get the file contents
*
* @param string $file
* @param string $branch
*
* @return string
*/
public function getFileContents($file, $branch = 'master')
{
try {
$fileContent = $this->client->api('repo')->contents()->download($this->project->getVendorName(), $this->project->getPackageName(), $file, $branch);
return $this->parseJson($fileContent);
} catch (\Github\Exception\RuntimeException $e) {
return "";
}
}
示例9: 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;
}
示例10: run
/**
*
*/
public function run()
{
$repos = $this->client->api('organization')->repositories($this->githubSettings['organization'], 'member');
/*
* @var Github\Api\Repo
*/
foreach ($repos as $repo) {
$this->composerChecker->check($repo);
}
}
示例11: getCommits
/**
* {@inheritdoc}
*/
public function getCommits()
{
$commits = $this->client->api('repo')->commits()->all($this->user, $this->repo, ['sha' => $this->branch]);
if (!count($commits)) {
return;
}
foreach ($commits as $commit) {
(yield $this->createCommit($commit));
}
}
示例12: checkComposerLock
/**
* @param $organization
* @param array $repository
*/
private function checkComposerLock($organization, array $repository)
{
$tempFile = tempnam(sys_get_temp_dir(), 'sec');
$handle = fopen($tempFile, 'w');
fwrite($handle, $this->client->api('repo')->contents()->download($organization, $repository['name'], 'composer.lock'));
fclose($handle);
$alerts = $this->securityChecker->check($tempFile);
$contributors = $this->client->api('repo')->contributors($organization, $repository['name']);
$this->alertHandler->handleAlerts($repository, $contributors, $alerts);
unlink($tempFile);
}
示例13: getMessages
/**
* Get an array of commit messages for a specific PR
*
* @param string $username
* @param string $repository
* @param int $pullRequestId
*
* @return array
*/
public function getMessages(string $username, string $repository, int $pullRequestId) : array
{
/** @var \Github\Api\PullRequest $prApi */
$prApi = $this->client->api('pr');
$response = $prApi->commits($username, $repository, $pullRequestId);
$messages = [];
foreach ($response as $commit) {
$messages[] = new GitHubMessageImplementation($commit['commit']['message'], $commit['sha']);
}
return $messages;
}
示例14: getDepBowerJson
/**
* Get remote bower.json file (or package.json file)
*
* @param string $version
* @return string
*/
private function getDepBowerJson($version)
{
list($repoUser, $repoName) = explode('/', $this->clearGitURL($this->url));
$contents = $this->githubClient->api('repo')->contents();
if ($contents->exists($repoUser, $repoName, 'bower.json', $version)) {
$json = $contents->download($repoUser, $repoName, 'bower.json', $version);
} else {
$isPackageJson = true;
if ($contents->exists($repoUser, $repoName, 'package.json', $version)) {
$json = $contents->download($repoUser, $repoName, 'package.json', $version);
} elseif ($version != 'master') {
return $this->getDepBowerJson('master');
}
// try anyway. E.g. exists() return false for Modernizr, but then it downloads :-|
$json = $contents->download($repoUser, $repoName, 'package.json', $version);
}
if (substr($json, 0, 3) == "") {
$json = substr($json, 3);
}
// for package.json, remove dependencies (see the case of Modernizr)
if (isset($isPackageJson)) {
$array = json_decode($json, true);
if (isset($array['dependencies'])) {
unset($array['dependencies']);
}
$json = Json::encode($array);
}
return $json;
}
示例15: 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;
}