Coder Social home page Coder Social logo

Comments (3)

davemg3 avatar davemg3 commented on September 28, 2024

Ok link to previous one #78

The quickest solution i found was to use

$client = resolve('github.connection');//to get the services provided by the provider
and then use on it the paginator of native lib KnpLabs/php-github-api
 $repoApi = $client->api('repo');
            $paginator  = new \Github\ResultPager($client );
            $parameters = array($org_name, ['page' => 1, 'per_page' => 100]);
            $repos_array  = $paginator->fetch($repoApi, $method, $parameters);

from laravel-github.

GrahamCampbell avatar GrahamCampbell commented on September 28, 2024

Thanks for getting in touch. Yeh, you'll need to use the paginator. You don't need to pass the extra page info however, and the fetchAll method is probably the one you're after here. The repo api is not what you want though - that will end up listing everything on all of GitHub. I stead, you'll want the organization API:

The following will suffice (using dependency injection to get the client instance - equivalent to manual resolution of the alias like you did):

<?php

use Github\Client;
use Github\ResultPager;

class Example
{
    function getRepos(Client $client)
    {
        $pager = new ResultPager($client);
        
        return $pager->fetchAll(
            $client->organization(),
            'repositories',
            ['some_org_name']
        );
    }
}

app()->call('Example@getRepos');

If you're ever in doubt of what stuff is available, take a gander at https://github.com/KnpLabs/php-github-api/tree/master/lib/Github/Api. That's essentially what I pulled up to write this example for you. :)

from laravel-github.

davemg3 avatar davemg3 commented on September 28, 2024

Thank you for advises. I was looking for a clean way to still use dependency injection with some other arguments in my method which is called by a job.
Based on your solution i slightly modified it and put it in case someone has same question as me.
Hopefully it is not dirty.

<?php
namespace App\Service;
use Github\Client;
use Github\ResultPager;

class Example
{
    function getRepos(Client $client, $argument)
    {
        $pager = new ResultPager($client);
        //argument for example for in place of 'some_org_name'
        return $pager->fetchAll(
            $client->organization(),
            'repositories',
            ['some_org_name']
        );
    }
}

      $example = App::make('App\Service\Example');
        App::call([$example ,'getRepos'],['argument'=>$someArgument]);

from laravel-github.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.