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); }
/** * 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'); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It is a breeze. Simply tell Lumen the URIs it should respond to | and give it the Closure to call when that URI is requested. | */ $app->get('/', function () use($app) { return Socialite::driver('github')->redirect(); }); $app->get('callback', function () { $user = Socialite::driver('github')->user(); $client = new \Github\Client(); $client->authenticate(config('services.github.user_token'), config('services.github.user_password'), Github\Client::AUTH_URL_TOKEN); $client->organization('wearehx')->teams()->addMember(config('services.github.team'), $user->user['login']); return redirect('https://github.com/wearehx'); });