GitHub Repository Benefit
Relevant source files
The following files were used as context for generating this wiki page:
- server/polar/benefit/strategies/github_repository/schemas.py
- clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx
- clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/products/new/ai/chat/route.ts/dashboard/[organization]/(header)/products/new/ai/chat/route.ts)
- CLAUDE.md
- README.md
- DEVELOPMENT.md
The GitHub Repository Benefit is a core monetization feature in Polar that allows developers to sell access to private GitHub repositories. When a customer purchases a product containing this benefit, Polar automatically invites them to the specified repository with a predefined permission level.
This system bridges the gap between payment processing and repository access management, enabling automated fulfillment for digital products such as software libraries, private documentation, or early-access source code.
Sources: README.md:16-20, server/polar/benefit/strategies/github_repository/schemas.py:73-77, clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/products/new/ai/chat/route.ts:98-100
Architecture and Data Flow
The GitHub Repository Benefit operates as a strategy within Polar's broader "Benefits" system. It integrates the Polar backend with GitHub's API to manage repository invitations based on subscription or purchase events.
System Components
The following diagram illustrates the relationship between the user, the Polar frontend, the Polar backend, and the GitHub integration.
The diagram shows the flow from initial configuration in the web dashboard to the final invitation trigger via the GitHub API.
Sources: DEVELOPMENT.md:8-23, clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx
Data Models and Schemas
The benefit is defined by specific properties that determine which repository is shared and what level of access is granted.
Configuration Properties
The BenefitGitHubRepositoryCreateProperties schema defines the required fields for setting up the benefit:
| Field | Type | Description |
|---|---|---|
repository_owner | str | The GitHub username or organization name owning the repository. |
repository_name | str | The specific name of the repository. |
permission | Literal | The access level granted (pull, triage, push, maintain, admin). |
Sources: server/polar/benefit/strategies/github_repository/schemas.py:38-50
Subscriber View
When a user subscribes, the properties exposed to them are limited to the repository location, while the internal logic (like the repository_id) is handled by the backend.
Sources: server/polar/benefit/strategies/github_repository/schemas.py:64-70
User Interface and Configuration
The GitHubRepositoryBenefitForm component manages the creation and update flow for this benefit. It requires the user to authenticate their GitHub account via OAuth before they can select repositories.
Repository Selection Logic
- OAuth Connection: Users must connect a GitHub account with the
github_repository_benefitplatform scope. - Organization Validation: For security reasons, Polar does not support configuring repositories on personal GitHub organizations; the owner must be a GitHub organization.
- Billing Warnings: The UI provides explicit warnings if the target GitHub organization is on a paid plan, as each invited subscriber will consume a GitHub seat and may result in additional billing from GitHub.
Sources: clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:55-58, clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:142-152, clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:279-290
Permission Roles
Polar maps GitHub's internal repository roles to user-friendly labels in the configuration form:
| GitHub Role | Polar Label |
|---|---|
pull | Read |
triage | Triage |
push | Write |
maintain | Maintain |
admin | Admin |
Sources: clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:327-340
AI-Assisted Configuration
In the Polar onboarding assistant, the GitHub Repository benefit is identified as an "unsupported benefit type" for direct AI configuration. This is because setting up the benefit requires the user to perform interactive OAuth authentication and third-party service configuration that the LLM cannot execute on the user's behalf.
Diagram showing the handoff from AI chat to manual form configuration for GitHub benefits.
Sources: clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/products/new/ai/chat/route.ts:117-124, clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/products/new/ai/chat/route.ts:468-477
Integration Details
The backend utilizes a specialized GitHub client to manage the interaction.
- OAuth Scopes: Integration relies on the
github_repository_benefitOAuth platform. - Installation: Users can trigger a fresh installation of the Polar GitHub App on their repositories via the dashboard if a repository is not visible in the list.
- SSE Events: The frontend listens for
integrations.github_repository_benefit.installedvia Server-Sent Events to refresh the repository list after a user completes the GitHub App installation flow.
Sources: CLAUDE.md:65-68, clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:75-79, clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:81-99
Summary
The GitHub Repository Benefit provides a seamless way for creators to monetize private source code. By automating the invitation process and mapping standard GitHub roles to Polar products, it reduces the administrative overhead of managing access for hundreds or thousands of subscribers. Developers should be mindful of GitHub's per-seat billing when configuring this benefit on repositories owned by paid GitHub organizations.
Sources: clients/apps/web/src/components/Benefit/GitHubRepositoryBenefitForm.tsx:279-290, server/polar/benefit/strategies/github_repository/schemas.py:73-77