Skip to content

GitHub Adapter

Wraps the knplabs/github-api SDK. Currently focused on issues (not PRs, releases, etc.).

Part of the pocketarc/laravel-integrations-adapters package.

Setup

php
// config/integrations.php
'providers' => [
    'github' => \Integrations\Adapters\GitHub\GitHubProvider::class,
],
php
$integration = Integration::create([
    'provider' => 'github',
    'name' => 'My Repo',
    'credentials' => ['token' => 'ghp_...'],
    'metadata' => ['owner' => 'acme', 'repo' => 'widgets'],
]);
CredentialsMetadata
token (string) -- GitHub personal access tokenowner (string) -- repository owner
repo (string) -- repository name

Resources

php
$client = new GitHubClient($integration);
ResourceMethodDescription
$client->issues()->create($title, $body, $labels)Create an issue. Returns GitHubIssueData.
->get($number)Get a single issue by number.
->since($since, $callback)Iterate issues updated since a timestamp. Skips PRs.
->close($number, $stateReason)Close an issue. Optional state reason (completed, not_planned, duplicate).
->reopen($number)Reopen a closed issue.
->timeline($number, $callback)Iterate timeline events (labels, assignments, etc.).
$client->comments()->list($number, $callback)Iterate all comments on an issue.
->add($number, $body)Add a comment to an issue. Returns ?GitHubCommentData.
$client->assets()->download($url)Download an asset with token auth for GitHub-hosted URLs.

All methods go through Integration::request() / requestAs() internally, so every API call is logged, health-tracked, and rate-limited.

Retry handling

The provider implements CustomizesRetry so the core handles retry for GitHub SDK exceptions (rate limits, server errors, connection failures) with method-aware defaults (GET = 3 attempts, non-GET = 1).

Sync

The adapter syncs issues via $client->issues()->since(). Each issue dispatches a GitHubIssueSynced event. Failed items dispatch GitHubIssueSyncFailed and don't advance the sync cursor past them. After the sync completes, GitHubSyncCompleted fires with the SyncResult.

First sync (null cursor) fetches all issues from timestamp 0. Set sync_cursor on the integration to control the starting point:

php
$integration->updateSyncCursor('2024-05-01T00:00:00+00:00');

Every sync subtracts a 1-hour buffer from the cursor to catch items updated between syncs. Consumers should use updateOrCreate() in their event listeners since overlap is expected.

Defaults: 5-minute sync interval, 60 requests/minute rate limit.

Data classes

ClassDescription
GitHubIssueDataIssue with body, state, user, labels, assignees, attachments (extracted from body HTML). Stores original API response.
GitHubCommentDataComment with body, user, attachments (extracted from body HTML). Stores original API response.
GitHubEventDataTimeline event with formatted descriptions. Handles cross-reference ID synthesis.
GitHubUserDataUser with login, avatar, name, email.
GitHubAttachmentDataAttachment URL extracted from issue/comment HTML body.

Enums

EnumValues
GitHubEventType~50 timeline event types with human-readable descriptions.
GitHubIssueStateReasonCompleted, NotPlanned, Duplicate, Reopened