/** * @param array $pull_request_data * @param string $reject_reason */ private function rejectPullRequest(array $pull_request_data, $reject_reason) { $client = new \Github\Client(); $params = array(); $params['state'] = 'closed'; $base = $pull_request_data['base']; $head = $pull_request_data['head']; $user = $head['user']; $repo = $base['repo']; $owner = $repo['owner']; $id = $pull_request_data['number']; if (!defined('GITHUB_API_OAUTH2TOKEN')) { throw new InvalidArgumentException(); } $client->authenticate(GITHUB_API_OAUTH2TOKEN, null, \Github\Client::AUTH_HTTP_TOKEN); $client->api('pull_request')->update($owner['login'], $repo['name'], $id, $params); $params = array(); $comment_body = ''; switch ($reject_reason) { case self::NON_MEMBER_REJECT_REASON: case self::NON_FOUNDATION_MEMBER_REJECT_REASON: $comment_body = sprintf('User %s is not an OpenStack Foundation Member. Please go to https://www.openstack.org/join/register/ and complete the registration form in order to become a Foundation Member. After that, please take a look at How to Contribute to Openstack (https://wiki.openstack.org/wiki/How_To_Contribute) and make sure you sign the Contributer License Agreement (http://docs.openstack.org/infra/manual/developers.html#account-setup).', $user['login']); break; case self::NON_SIGNED_CLA_REJECT_REASON: $comment_body = sprintf('User %s has not signed the Contributer License Agreement. Please take a look at How to Contribute to Openstack (https://wiki.openstack.org/wiki/How_To_Contribute) and make sure you sign the CLA (http://docs.openstack.org/infra/manual/developers.html#account-setup).', $user['login']); break; } $params['body'] = $comment_body; $client->api('issue')->comments()->create($owner['login'], $repo['name'], $id, $params); }
public function onStart(EnvironmentEvent $event) { $io = $event->getIO(); $configValues = $event->getConfigValues(); $io->write('Getting Github metadata...'); $repository = $this->getRepositoryComponents($configValues['repository']); if (2 != count($repository)) { $io->write('<error>Invalid repository name.</error>'); return; } $client = new \Github\Client(); $metadataRepo = $client->api('repo')->show($repository['vendor'], $repository['name']); $metadata = ['name' => $metadataRepo['name'], 'full_name' => $metadataRepo['full_name'], 'description' => $metadataRepo['description'], 'fork' => $metadataRepo['fork'], 'html_url' => $metadataRepo['html_url'], 'clone_url' => $metadataRepo['clone_url'], 'git_url' => $metadataRepo['git_url'], 'ssh_url' => $metadataRepo['ssh_url'], 'mirror_url' => $metadataRepo['mirror_url'], 'homepage' => $metadataRepo['homepage'], 'forks_count' => $metadataRepo['forks_count'], 'stargazers_count' => $metadataRepo['stargazers_count'], 'watchers_count' => $metadataRepo['watchers_count'], 'size' => $metadataRepo['size'], 'default_branch' => $metadataRepo['default_branch'], 'open_issues_count' => $metadataRepo['open_issues_count'], 'has_issues' => $metadataRepo['has_issues'], 'has_wiki' => $metadataRepo['has_wiki'], 'has_pages' => $metadataRepo['has_pages'], 'has_downloads' => $metadataRepo['has_downloads'], 'pushed_at' => $metadataRepo['pushed_at'], 'created_at' => $metadataRepo['created_at'], 'updated_at' => $metadataRepo['updated_at'], 'owner' => ['login' => $metadataRepo['owner']['login'], 'avatar_url' => $metadataRepo['owner']['avatar_url'], 'gravatar_id' => $metadataRepo['owner']['gravatar_id'], 'html_url' => $metadataRepo['owner']['html_url']], 'organization' => [], 'source' => [], 'contributors' => []]; if (isset($metadataRepo['organization'])) { $metadata['organization'] = ['login' => $metadataRepo['organization']['login'], 'avatar_url' => $metadataRepo['organization']['avatar_url'], 'html_url' => $metadataRepo['organization']['html_url']]; } if (isset($metadataRepo['source'])) { $metadata['source'] = ['name' => $metadataRepo['source']['name'], 'full_name' => $metadataRepo['source']['full_name'], 'description' => $metadataRepo['source']['description'], 'html_url' => $metadataRepo['source']['html_url'], 'clone_url' => $metadataRepo['source']['clone_url'], 'git_url' => $metadataRepo['source']['git_url'], 'ssh_url' => $metadataRepo['source']['ssh_url'], 'svn_url' => $metadataRepo['source']['svn_url'], 'mirror_url' => $metadataRepo['source']['mirror_url'], 'homepage' => $metadataRepo['source']['homepage'], 'forks_count' => $metadataRepo['source']['forks_count'], 'stargazers_count' => $metadataRepo['source']['stargazers_count'], 'watchers_count' => $metadataRepo['source']['watchers_count'], 'size' => $metadataRepo['source']['size'], 'default_branch' => $metadataRepo['source']['default_branch'], 'open_issues_count' => $metadataRepo['source']['open_issues_count'], 'has_issues' => $metadataRepo['source']['has_issues'], 'has_wiki' => $metadataRepo['source']['has_wiki'], 'has_pages' => $metadataRepo['source']['has_pages'], 'has_downloads' => $metadataRepo['source']['has_downloads'], 'pushed_at' => $metadataRepo['source']['pushed_at'], 'created_at' => $metadataRepo['source']['created_at'], 'updated_at' => $metadataRepo['source']['updated_at']]; } $contributors = $client->api('repo')->contributors($repository['vendor'], $repository['name']); foreach ($contributors as $contributor) { $metadata['contributors'][] = ['login' => $contributor['login'], 'avatar_url' => $contributor['avatar_url'], 'html_url' => $contributor['html_url'], 'type' => $contributor['type'], 'contributions' => $contributor['contributions']]; } $configValues['github'] = $metadata; $event->setConfigValues($configValues); }
function getGithubClient() { $token = getenv('GITHUB_TOKEN'); $client = new \Github\Client(); $client->authenticate($token, $token, Github\Client::AUTH_HTTP_TOKEN); return $client; }
public function progress($offset, $limit) { $source = $this->connection->fetchAll("\n SELECT `id`, `name`\n FROM `s_names`\n WHERE `github_response_code` = 0\n LIMIT {$offset}, {$limit};\n "); $names = array_column($source, 'name', 'id'); $responseCodeIdMap = []; /* @var $api \Github\Api\User */ $client = new \Github\Client(); $client->authenticate($this->authToken, \Github\Client::AUTH_HTTP_PASSWORD); $api = $client->api('user'); foreach ($names as $id => $name) { try { $api->show($name); $code = 200; } catch (\Github\Exception\RuntimeException $e) { // "You have reached GitHub hour limit! Actual limit is: 5000" if (empty($code = $e->getCode())) { break; } } $responseCodeIdMap[$code][] = $id; } foreach ($responseCodeIdMap as $code => $idList) { $idStringList = join(',', $idList); $this->connection->executeUpdate("\n UPDATE `s_names`\n SET `github_response_code` = {$code}\n WHERE `id` IN ({$idStringList})\n "); } }
/** * undocumented function * * @return void * @author **/ public function takeCare() { $req = Request::instance(); $token = $this->client->getAccessToken('authorizationCode', ['code' => $req->get('code')]); $github = new \Github\Client(); $github->authenticate($token->accessToken, 'http_token'); $response = $github->getHttpClient()->get('user'); $user = \Github\HttpClient\Message\ResponseMediator::getContent($response); $verifiedEmails = $this->getVerifiedEmails($token->accessToken); $email = $this->getPrimaryEmail($verifiedEmails); $result['uid'] = $user['id']; $result['email'] = $email; $result['username'] = $user['login']; $result['url'] = $user['html_url']; $result['location'] = isset($user['location']) ? $user['location'] : null; $fresult = $this->findUser($result['email']); if ($fresult['found']) { $fuser = $fresult['user']; $result['first_name'] = $fuser->first_name; $result['last_name'] = $fuser->last_name; } else { if (isset($user['name'])) { $name = explode(' ', $user['name']); $result['first_name'] = $name[0]; $result['last_name'] = isset($name[1]) ? $name[1] : $name[0]; } else { $result['first_name'] = $result['last_name'] = $result['username']; } } $result['access_token'] = $token->accessToken; return $result; }
/** * Execute the console command. * * @param Settings $settings * @return mixed */ public function handle() { $client = new \Github\Client(); if ($this->cache && config('game-of-tests.cache') && class_exists(CacheItemPool::class)) { $client->addCache(new CacheItemPool($this->cache)); } $this->info('Getting repository list'); if ($this->argument('organisation') !== false) { $repositories = $client->organization()->repositories($this->argument('organisation'), 'owner'); } $repositoryUrls = array_pluck($repositories, 'clone_url'); $this->info('Found ' . count($repositoryUrls) . ' repositories on Github'); $progresbar = $this->output->createProgressBar(count($repositoryUrls)); $progresbar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message% '); $progresbar->setMessage('Searching...'); \Swis\GotLaravel\Models\Results::unguard(); $inspector = new Inspector($this->settings); foreach ($repositoryUrls as $gitUrl) { $repository = $inspector->getRepositoryByUrl($gitUrl); // Check modified date if (null !== $this->option('modified')) { $modifiedTimestamp = strtotime($this->option('modified')); /** * @var $date \DateTime */ try { $commitDate = $repository->getHeadCommit()->getCommitterDate(); } catch (\Gitonomy\Git\Exception\ReferenceNotFoundException $e) { $this->error($e->getMessage()); $this->error('Error finding reference for ' . $gitUrl); } if ($modifiedTimestamp === false || $commitDate->getTimestamp() < $modifiedTimestamp) { $progresbar->advance(); continue; } } $repository->setLogger(new ConsoleLogger($this->getOutput())); $resultSet = $inspector->inspectRepository($repository); $remote = $resultSet['remote']; if (count($resultSet['results']) > 0) { $progresbar->setMessage('Found ' . count($resultSet['results']) . ' tests for ' . $remote); } if (!$this->option('dry-run')) { foreach ($resultSet['results'] as $result) { $insert = $result->toArray(); $insert['remote'] = $remote; $insert['author_slug'] = Str::slug($result->getAuthor()); $insert['created_at'] = Carbon::createFromTimestamp($insert['date']); try { \Swis\GotLaravel\Models\Results::updateOrCreate(array_only($insert, ['remote', 'filename', 'line']), $insert); } catch (\Exception $e) { $this->error('Couldnt insert: ' . $e->getMessage() . PHP_EOL . print_r($insert, 1)); } } } $progresbar->advance(); } Artisan::call('got:normalize-names'); }
public function __construct(\Github\Client $client) { $client = new \Github\Client(); $auth = new Oauth(); $user = $auth::where('user_id', Auth::id())->first(); $client->authenticate($user->access_token, null, \Github\Client::AUTH_HTTP_TOKEN); $this->client = $client; }
public function __construct() { //CodeReview --repo=clickbus-mexico --pr=24 --flags=clean-code,psr2 //CodeReview --repo=clickbus-mexico --branch=feature/LMX-788 --flags=clean-code,psr2 $client = new \Github\Client(); $repositories = $client->api('user')->repositories('ajaxman'); var_dump($repositories); echo "working..."; }
/** * @param Github\Client $client * @param Github\Api\Repo $repoApi * @param Github\Api\Repository\Commits $commitsApi */ function it_should_not_collect_merge_commits($client, $repoApi, $commitsApi) { $client->api('repos')->willReturn($repoApi); $repoApi->commits()->willReturn($commitsApi); $commitsApi->all('author1', 'repo1', Argument::type('array'))->shouldBeCalled()->willReturn($this->repo1Commits); $this->repo2Commits[0]['commit']['message'] = 'Merged something into something'; $commitsApi->all('author1', 'repo2', Argument::type('array'))->shouldBeCalled()->willReturn($this->repo2Commits); $this->collect(array('author1' => array('repo1', 'repo2')))->shouldReturn(array('john doe' => 1, 'jane doe' => 1)); }
protected function getApiMock() { $httpClient = $this->getMock('Guzzle\\Http\\Client', array('send')); $httpClient->expects($this->any())->method('send'); $mock = $this->getMock('Github\\HttpClient\\HttpClient', array(), array(array(), $httpClient)); $client = new \Github\Client($mock); $client->setHttpClient($mock); return $this->getMockBuilder($this->getApiClass())->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put'))->setConstructorArgs(array($client))->getMock(); }
protected function fetchExtensionPerBranch() { $path = 'ext'; $extensionsPerBranch = []; foreach ($this->branches as $name => $branch) { $fileInfo = $this->client->api('repo')->contents()->show('php', 'php-src', $path, $branch['commit']['sha']); $extensionsPerBranch[$name] = $this->getBundledExtensions($fileInfo); } return $extensionsPerBranch; }
public function showAction($slug) { $em = $this->getDoctrine()->getEntityManager(); $q = "SELECT p FROM DdnetPortfolioBundle:Project p WHERE p.slug = :slug"; $q = $em->createQuery($q)->setParameter('slug', $slug); $r = $q->getSingleResult(); $gh = new \Github\Client(); $commits = $gh->api('repo')->commits()->all($r->getGithubUser(), $r->getGithubRepo(), array('sha' => $r->getGithubBranch())); return $this->render('DdnetPortfolioBundle:Project:show.html.twig', array('portfolio' => $r, 'commits' => $commits)); }
function umc_github_client_connect($owner, $repo) { require_once '/home/includes/composer/vendor/autoload.php'; $cache_dir = "/tmp/github-{$repo}-{$owner}-cache"; $token_file = __DIR__ . "/github-{$repo}-{$owner}.token"; $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => $cache_dir))); $token = file_get_contents($token_file); $client->authenticate($token, \Github\Client::AUTH_HTTP_TOKEN); return $client; }
protected function getApiMock() { $httpClient = $this->getMock('Buzz\\Client\\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); $httpClient->expects($this->any())->method('setTimeout')->with(10); $httpClient->expects($this->any())->method('setVerifyPeer')->with(false); $httpClient->expects($this->any())->method('send'); $mock = $this->getMock('Github\\HttpClient\\HttpClient', array(), array(array(), $httpClient)); $client = new \Github\Client($httpClient); $client->setHttpClient($mock); return $this->getMockBuilder($this->getApiClass())->setMethods(array('get', 'post', 'patch', 'delete', 'put'))->setConstructorArgs(array($client))->getMock(); }
/** * Obtain the user information from GitHub. * * @return Response */ public function callback(Request $request) { $user = Socialite::with('github')->user(); // TODO: Nice error page $request->session()->set('github', ['token' => $user->token, 'id' => $user->getId(), 'nickname' => $user->getNickname(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'avatar' => $user->getAvatar()]); $client = new \Github\Client(); $client->authenticate($user->token, false, \Github\Client::AUTH_HTTP_TOKEN); //$repos = $client->api('user')->repositories($user->getNickname()); // Get this users repos $content = $client->api('repo')->contents()->show('ashleyhindle', 'fodor-example', 'fodor.json', 'master'); dd(base64_decode($content['content'])); }
public static function check($token, $user, $repo, $branch) { //TODO probar más cosas try { $client = new \Github\Client(); $client->authenticate($token, false, Github\Client::AUTH_URL_TOKEN); } catch (Exception $e) { return false; } return true; }
public function sendScreenshot($cloudName, $apiKey, $apiSecret, $authToken) { $this->say('Sending image'); // Upload image Cloudinary::config(array('cloud_name' => $cloudName, 'api_key' => $apiKey, 'api_secret' => $apiSecret)); $result = \Cloudinary\Uploader::upload(realpath(dirname(__FILE__) . '/tests/_output/InstallNenoCest.installNeno.fail.png')); $this->say('Image sent'); $this->say('Creating Github issue'); $client = new \Github\Client(); $client->authenticate($authToken, \Github\Client::AUTH_HTTP_TOKEN); $client->api('issue')->create('Jensen-Technologies', 'neno', array('title' => 'Test error', 'body' => '![Screenshot](' . $result['secure_url'] . ')')); }
/** * Constructor * * @param string $contextRepo The repository context. Pass a GitHub repo * such as 'aptoma/twig-markdown' to render e.g. issues #23 in the * context of the repo. * @param bool $gfm Whether to use GitHub's Flavored Markdown or the * standard markdown. Default is true. * @param string $cacheDir Location on disk where rendered documents should * be stored. * @param \Github\Client $client Client object to use. A new Github\Client() * object is constructed automatically if $client is null. */ public function __construct($contextRepo = null, $gfm = true, $cacheDir = '/tmp/github-markdown-cache', \GitHub\Client $client = null) { $this->repo = $contextRepo; $this->mode = $gfm ? 'gfm' : 'markdown'; $this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; if (!is_dir($this->cacheDir)) { @mkdir($this->cacheDir, 0777, true); } if ($client === null) { $client = new \Github\Client(); } $this->api = $client->api('markdown'); }
protected function installPoshGit(InputInterface $in, OutputInterface $out) { $dir = realpath(__DIR__ . '/../runtime') . '/posh-git-sh'; if (!is_dir($dir)) { mkdir($dir); $client = new \Github\Client(); /** @var Repo $repo */ $repo = $client->api('repo'); /** @var string $data The binary tar data. */ $data = $repo->contents()->archive('lyze', 'posh-git-sh', 'tarball'); $proc = proc_open("tar xvz --strip 1 -C {$dir}", [['pipe', 'r']], $pipes); fwrite($pipes[0], $data); } }
public function githubinvite() { global $admin_token; $admin = new \Github\Client(); $admin->authenticate($admin_token, null, \Github\Client::AUTH_HTTP_TOKEN); // Check if already in the org $rawmembers = $admin->organization()->members()->all("teenscode"); for ($i = 0; $i < count($rawmembers); $i++) { if ($rawmembers[$i]["login"] == $this->username) { echo "Already a member of org"; return; } } // Not in org so add to org $admin->organization()->members()->add("teenscode", $this->username); }
/** * @param Package $package * * @return Package */ public function analyzePackage(Package $package) { $client = new GuzzleClient(); $response = $client->get($this->packageVendor . $package->getName(), array('exceptions' => false)); if ($response->getStatusCode() == 200) { $data = $this->parseJson((string) $response->getBody()); // TODO: Handle this differently $urlChunks = explode("/", $data['url']); $githubClient = new \Github\Client(); $tags = $githubClient->api('repo')->tags($urlChunks[3], substr($urlChunks[4], 0, -4)); $newestVersion = $this->getLatestVersion(array_column($tags, 'name')); $package->setLatestVersion($newestVersion); $package->setLastChecktAt(new \DateTime()); } return $package; }
/** * @return \Github\Client */ public function client() { // create client $client = new \Github\HttpClient\CachedHttpClient(); $client->setCache(new \Github\HttpClient\Cache\FilesystemCache(__DIR__ . '/../tmp/github-cache')); $client = new \Github\Client($client); if (empty(Yii::$app->params['github_token'])) { throw new Exception('Config param "github_token" is not configured!'); } if (empty(Yii::$app->params['github_username'])) { throw new Exception('Config param "github_username" is not configured!'); } // authenticate $client->authenticate(Yii::$app->params['github_token'], '', \Github\Client::AUTH_HTTP_TOKEN); return $client; }
/** * Closes any open pull requests on mirrored repositories. * * Since these are mirrored repos, any pull requests submitted are not * monitored or handled. Since GitHub does not support turning off pull * requests, it is inevitable that users will submit them anyway. * * Note: GitHub supports turning off issues, but not pull requests. * * This utility will simply auto-close any opened pull requests while * directing author to a (hopefully) more appropriate location to submit * changes to. * * @return int Shell return code. */ function main() { $this->out(__('Fetching list of open issues...')); try { $client = new Github\Client(); $client->getHttpClient()->setOption('user_agent', Configure::read('GitHub.user_agent')); $client->authenticate(GITHUB_USERNAME, GITHUB_PASSWORD, Github\Client::AUTH_HTTP_PASSWORD); } catch (Exception $exception) { $this->out(__('<error>Failed to authenticate with GitHub: %s</error>', $exception->getMessage())); $this->_unlock(); return 1; } try { $response = $client->getHttpClient()->get('search/issues', array('q' => sprintf('user:%s state:open', Configure::read('GitHub.org_name')))); $issues = $response->getContent(); } catch (Exception $exception) { $this->out(__('<error>Failed to fetch list of open issues: %s</error>', $exception->getMessage())); $this->_unlock(); return 1; } if ($issues['total_count'] == 0) { $this->out(__('<info>No open pull requests were found.</info>')); $this->_unlock(); return 0; } foreach ($issues['items'] as $pull_request) { $parts = explode('/', $pull_request['html_url']); $user = $parts[3]; $plugin = $parts[4]; $issue_number = $parts[6]; $plugin_page = sprintf(Configure::read('App.plugin_http_url'), $plugin); $support_page = sprintf(Configure::read('App.plugin_support_url'), $plugin); $pull_request_url = sprintf('repos/%s/%s/pulls/%d', $user, $plugin, $issue_number); try { $client->getHttpClient()->post($pull_request['comments_url'], array('body' => sprintf($this->close_reply, $plugin_page, $support_page))); $client->getHttpClient()->patch($pull_request_url, array('state' => 'closed')); } catch (Exception $exception) { $this->out(__('<error>Failed to close pull request <%s>: %s</error>', $pull_request['html_url'], $exception->getMessage())); continue; } $this->out(__('Closed pull request: %s', $pull_request['html_url'])); } $this->out(__('<info>Finished closing open issues on GitHub.</info>')); $this->_unlock(); return 0; }
public function actionCommits() { $http_client = new \Guzzle\Http\Client(); $client = new \Github\Client(); try { $commits = $client->api('repo')->commits()->all('KnpLabs', 'php-github-api', array('sha' => 'master')); foreach ($commits as $commit_info) { $commit_info = json_decode($http_client->get($commit_info['url'])->send()->getBody(), true); $commit = Commits::findOne(['sha' => $commit_info['sha']]); if (!$commit) { $commit = new Commits(); $commit->sha = $commit_info['sha']; $commit->user_name = $commit_info['commit']['committer']['name']; $commit->date_commit = date('Y-m-d', strtotime($commit_info['commit']['committer']['date'])); $commit->message = $commit_info['commit']['message']; $commit->save(); } echo $commit->id . PHP_EOL; foreach ($commit_info['files'] as $file_info) { $commit_file = CommitsFiles::findOne(['sha' => $file_info['sha']]); if (!$commit_file) { $commit_file = new CommitsFiles(); $commit_file->sha = $file_info['sha']; $commit_file->commit_id = $commit->id; $commit_file->filename = $file_info['filename']; $commit_file->status = $file_info['status']; $commit_file->additions = $file_info['additions']; $commit_file->deletions = $file_info['deletions']; $commit_file->changes = $file_info['changes']; $commit_file->blob_url = $file_info['blob_url']; $commit_file->date_add = $commit->date_commit; if (!$commit_file->save()) { print_r($commit_file->getErrors()); die; } } echo '--' . $commit_file->id . PHP_EOL; } } } catch (\Exception $e) { } }
#!/usr/bin/php <?php $config = ['require_services' => ['guzzle3'], 'git_urls' => ['https://github.com/KnpLabs/php-github-api.git' => 'php_github_api/'], 'autoload_config' => ['php_github_api/lib/Github/' => 'Github'], 'example' => function () { $client = new \Github\Client(); $repositories = $client->api('user')->repositories('yfix'); foreach ($repositories as $v) { $a[$v['full_name']] = $v['html_url']; } print_r($a); }]; if ($return_config) { return $config; } require_once __DIR__ . '/_yf_autoloader.php'; new yf_autoloader($config);
/** * Creates a GitHub repository with the given name. * * @param string $repo Name of the repository (slug) * * @return bool True if GitHub repository was created, false otherwise. */ protected function _createGithubRepo($repo) { try { $client = new Github\Client(); $client->getHttpClient()->setOption('user_agent', Configure::read('GitHub.user_agent')); $client->authenticate(GITHUB_USERNAME, GITHUB_PASSWORD, Github\Client::AUTH_HTTP_PASSWORD); $client->getHttpClient()->post('orgs/' . Configure::read('GitHub.org_name') . '/repos', array('name' => $repo, 'description' => Configure::read('GitHub.repo_description'), 'homepage' => sprintf(Configure::read('App.plugin_app_url'), $repo), 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false)); } catch (Exception $exception) { $this->out(__('<warning>Failed to create GitHub repository for "%s": %s</warning>', $repo, $exception->getMessage())); return false; } return true; }
* @return \Symfony\Component\HttpFoundation\Response */ $github_verify_payload = function (Request $request, \Silex\Application $app) { $secretKey = $app['db']->fetchColumn("SELECT value FROM config WHERE key = 'github_webhook_hash' "); $payload_signature = 'sha1=' . hash_hmac('sha1', $request->getContent(), $secretKey, false); $app['monolog']->debug('github signature: ' . $payload_signature); if ($payload_signature !== $request->headers->get('X-Hub-Signature')) { return new \Symfony\Component\HttpFoundation\Response('invalid', 403); } return null; }; /** * creating our services */ $app['github.client'] = $app->share(function () use($app) { $client = new \Github\Client(new CachedHttpClient(['cache_dir' => __DIR__ . '/../cache'])); if (isset($app['config']['github_token'])) { $client->authenticate($app['config']['github_token'], null, \Github\Client::AUTH_HTTP_TOKEN); } return $client; }); $app['zendesk.client'] = $app->share(function () use($app) { $client = new \Zendesk\API\Client($app['config']['zendesk_subdomain'], $app['config']['zendesk_username']); $client->setAuth('token', $app['config']['zendesk_token']); return $client; }); $app['ticket.processor'] = $app->share(function () use($app) { $processor = new TicketProcessor($app['zendesk.client'], $app['github.client'], $app['db'], $app['monolog'], $app['config'], $app['translator']); return $processor; }); $app['flashbag'] = $app->share(function () use($app) {
echo $search->getTotal(), " tarefas em aberto", "\n\n"; foreach ($search->getList() as $key => $issue) { echo 'Código: ', $issue->getKey(), "\n"; echo 'Descrição: ', $issue->getSummary(), "\n"; echo 'Tipo: ', $issue->getIssueType()->getName(), "\n"; echo 'Status:', $issue->getStatus()->getName(), "\n"; echo 'Responsável: ', $issue->getAssignee()->getDisplayName(), "\n"; echo 'Prioridade:', $issue->getPriority()->getName(), "\n"; echo 'Criado em :', $issue->getCreated()->format('d/m/Y H:i:s'), "\n"; echo 'Última atualização em :', $issue->getUpdated()->format('d/m/Y H:i:s'), "\n"; if (getWeekdayDifference($issue->getUpdated(), $now) >= 2) { echo "URGENTE: esta tarefa precisa ser quebrada e entregue hoje. Nenhuma tarefa pode ficar mais de 2 dias parada", "\n"; } echo "\n\n"; } $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache'))); $githubUser = getenv('GITHUB_USER'); $githubPassword = getenv('GITHUB_PASSWORD'); $githubRepo = getenv('GITHUB_REPO'); $client->authenticate($githubUser, $githubPassword, \Github\Client::AUTH_HTTP_PASSWORD); $activity = $client->api('repo')->statistics($githubUser, $githubRepo); echo "Commits \n\n"; foreach ($activity as $a) { $lastWeek = count($a['weeks']) - 1; if ($a['weeks'][$lastWeek]['c'] > 0) { echo $a['author']['login'], " Total de commits: ", $a['total'], '. Commits na última semana (começando em ' . DateTime::createFromFormat('U', $a['weeks'][$lastWeek]['w'])->format('d/m/Y') . ' ):' . $a['weeks'][$lastWeek]['c'], "\n"; } } echo "\n\nOBS: se o nome de alguém não aparece acima não significa que ela não está trabalhando e sim que está commitando em branches diferentes da master pois o Github só entrega estatísticas desta branch. A ausência de alguém na lista acima indica que a sua tarefa está demorando mais de dois dias para terminar e ser aprovada no master o que reforça a necessidade de quebrar a tarefa em pedaços menores.\n"; function getWeekdayDifference(\DateTime $startDate, \DateTime $endDate) {
| | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel, and is | the IoC container for the system binding all of the various parts. | */ $app = new Illuminate\Foundation\Application(realpath(__DIR__ . '/../')); /* |-------------------------------------------------------------------------- | Bind Important Interfaces |-------------------------------------------------------------------------- | | Next, we need to bind some important interfaces into the container so | we will be able to resolve them when needed. The kernels serve the | incoming requests to this application from both the web and CLI. | */ $app->singleton(Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class); $app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class); $app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class); $app->singleton('Github\\Client', function () { $client = new Github\Client(); $token = env('GITHUB_TOKEN'); if (!isset($token)) { dd("Github token is not set."); } $client->authenticate(env('GITHUB_EMAIL'), env('GITHUB_PASSWORD'), Github\Client::AUTH_HTTP_PASSWORD); //$client->authenticate($token, null, Github\Client::AUTH_HTTP_TOKEN); return $client; }); return $app;
<?php // Initialize SimpleCache $cache = new Gilbitron\Util\SimpleCache(); $cache->cache_path = HW_CACHE_DIR . '/'; // Initialize GitHub-API $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => HW_CACHE_DIR))); if (HW_GITHUB_API != '') { $client->authenticate(HW_GITHUB_API, null, Github\Client::AUTH_HTTP_TOKEN); } $paginator = new Github\ResultPager($client);