* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Thanks\Command; use Composer\Command\BaseCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Thanks\GitHubClient; /** * @author Nicolas Grekas
*/
class ThanksCommand extends BaseCommand
{
private $star = '★ ';
private $love = '💖 ';
protected function configure()
{
if ('Hyper' === getenv('TERM_PROGRAM')) {
$this->star = '⭐ ';
$this->love = '💖 ';
} elseif ('\\' === \DIRECTORY_SEPARATOR) {
$this->star = '*';
$this->love = '<3';
}
$this->setName('thanks')
->setDescription(sprintf('Give thanks (in the form of a GitHub %s) to your fellow PHP package maintainers.', $this->star))
->setDefinition([
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Don\'t actually send the stars'),
])
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$gitHub = new GitHubClient($composer, $this->getIO());
$repos = $gitHub->getRepositories($failures);
$template = '%1$s: addStar(input:{clientMutationId:"%s",starrableId:"%s"}){clientMutationId}'."\n";
$graphql = '';
$notStarred = [];
foreach ($repos as $alias => $repo) {
if (!$repo['viewerHasStarred']) {
$graphql .= sprintf($template, $alias, $repo['id']);
$notStarred[$alias] = $repo;
}
}
if (!$notStarred) {
$output->writeln('You already starred all your GitHub dependencies.');
} else {
if (!$input->getOption('dry-run')) {
$notStarred = $gitHub->call(sprintf("mutation{\n%s}", $graphql));
}
$output->writeln('Stars