Coverage for polar/benefit/strategies/github_repository/schemas.py: 100%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from typing import Annotated, Literal
3from pydantic import UUID4, Field
4from pydantic.json_schema import SkipJsonSchema
6from polar.kit.schemas import Schema
7from polar.models.benefit import BenefitType
9from ..base.schemas import (
10 BenefitBase,
11 BenefitCreateBase,
12 BenefitSubscriberBase,
13 BenefitUpdateBase,
14)
16## GitHub Repository
18Permission = Annotated[
19 Literal["pull", "triage", "push", "maintain", "admin"],
20 Field(
21 description=(
22 "The permission level to grant. "
23 "Read more about roles and their permissions on "
24 "[GitHub documentation](https://docs.github.com/en/organizations/managing-user-access-to-your-organizations-repositories/managing-repository-roles/repository-roles-for-an-organization#permissions-for-each-role)."
25 )
26 ),
27]
28RepositoryOwner = Annotated[
29 str,
30 Field(description="The owner of the repository.", examples=["polarsource"]),
31]
32RepositoryName = Annotated[
33 str,
34 Field(description="The name of the repository.", examples=["private_repo"]),
35]
38class BenefitGitHubRepositoryCreateProperties(Schema):
39 """
40 Properties to create a benefit of type `github_repository`.
41 """
43 repository_owner: str = Field(
44 description="The owner of the repository.", examples=["polarsource"]
45 )
46 repository_name: str = Field(
47 description="The name of the repository.", examples=["private_repo"]
48 )
49 permission: Permission
52class BenefitGitHubRepositoryProperties(Schema):
53 """
54 Properties for a benefit of type `github_repository`.
55 """
57 repository_owner: RepositoryOwner
58 repository_name: RepositoryName
59 permission: Permission
60 repository_id: SkipJsonSchema[UUID4 | None] = Field(None, deprecated=True)
63class BenefitGitHubRepositorySubscriberProperties(Schema):
64 """
65 Properties available to subscribers for a benefit of type `github_repository`.
66 """
68 repository_owner: RepositoryOwner
69 repository_name: RepositoryName
72class BenefitGitHubRepositoryCreate(BenefitCreateBase):
73 type: Literal[BenefitType.github_repository]
74 properties: BenefitGitHubRepositoryCreateProperties
77class BenefitGitHubRepositoryUpdate(BenefitUpdateBase):
78 type: Literal[BenefitType.github_repository]
79 properties: BenefitGitHubRepositoryCreateProperties | None = None
82class BenefitGitHubRepository(BenefitBase):
83 """
84 A benefit of type `github_repository`.
86 Use it to automatically invite your backers to a private GitHub repository.
87 """
89 type: Literal[BenefitType.github_repository]
90 properties: BenefitGitHubRepositoryProperties
93class BenefitGitHubRepositorySubscriber(BenefitSubscriberBase):
94 type: Literal[BenefitType.github_repository]
95 properties: BenefitGitHubRepositorySubscriberProperties