Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add \Illuminate\Http\Client\Response->paginated() macro #103

Open
Gummibeer opened this issue May 25, 2021 · 0 comments
Open

Add \Illuminate\Http\Client\Response->paginated() macro #103

Gummibeer opened this issue May 25, 2021 · 0 comments

Comments

@Gummibeer
Copy link
Member

Gummibeer commented May 25, 2021

relates to #82

Instead of doing $this->paginated(...) in the job it would be cool to do Http::github()->get()->paginated(fn() => ...).

The paginated macro should accept one closure argument that runs for each response and gets the response instance as it's own argument.

Http::github()
    ->get("/orgs/{$this->organization->name}/repos")
    ->paginated(function(\Illuminate\Http\Client\Response $response): void {
        $response->collect()->map(...);
    });

do {
$start = $end->subMonths(3);
$response = $this->user->github()->post('/graphql', [
'query' => $this->query(),
'variables' => [
'from' => $start->startOfDay()->toIso8601ZuluString(),
'to' => $end->endOfDay()->toIso8601ZuluString(),
],
])->json('data.viewer.contributionsCollection');
foreach (data_get($response, 'commitContributionsByRepository.*.repository.nameWithOwner') as $name) {
$repository = Repository::fromName($name);
if ($repository === null) {
continue;
}
$repository->contributors()->syncWithoutDetaching($this->user);
}
$end = $start;
} while ($response['hasActivityInThePast']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant