tan-tan-kanarek / github-php-client

MIT License
184 stars 120 forks source link

How to get all Issues from an Organisation? #139

Closed ff1601com closed 3 years ago

ff1601com commented 3 years ago

Hello there,

I used your api a lot and i really like it. Yesterday I ran into an use-case where I would like to get every issue (assigned and not assigned) in an Organisation.

Is there a way to achieve this?

tan-tan-kanarek commented 3 years ago

Thank you, I appreciate it. I guess you could iterate through all the org repos and get the issues for each one of them.

ff1601com commented 3 years ago

Yeah. That's what I thought. Thanks for answering :)

ff1601com commented 3 years ago

So for anyone in the future wondering how to do it. I found this way to get the job done.

Just like @tan-tan-kanarek mentioned:

Get each repository-Name in the given Organization

$repositories = $client->repos->listOrganizationRepositories('Organization');

        $repositoryNames = [];
        while (true) {
            $page = $client->getPage();
            foreach ($repos as $repo) {
                $repositoryNames[] = $repo->getName();
            }

            if (!$client->hasNextPage())
                break;

            $repos = $client->getNextPage();
            if ($client->getPage() == $page)
                break;
        }
    }

After that just iterate through the repositoryNames and add your functionality:

        $issueList= [];
        $issueCount = 1;

        foreach($repositoryNames as $repo) {
            foreach($client->issues->listIssues('Owner', $repo) as $issue) {
                $issueList[] = [
                    'index' => $issueCount,
                    'title' => $issue->getTitle(),
                    'href' => $issue->getHtmlUrl(),
                    ...
                ];
                $issueCount++;
            }
        }