Coverage for polar/benefit/strategies/github_repository/schemas.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 17:15 +0000

1from typing import Annotated, Literal 1a

2 

3from pydantic import UUID4, Field 1a

4from pydantic.json_schema import SkipJsonSchema 1a

5 

6from polar.kit.schemas import Schema 1a

7from polar.models.benefit import BenefitType 1a

8 

9from ..base.schemas import ( 1a

10 BenefitBase, 

11 BenefitCreateBase, 

12 BenefitSubscriberBase, 

13 BenefitUpdateBase, 

14) 

15 

16## GitHub Repository 

17 

18Permission = Annotated[ 1a

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[ 1a

29 str, 

30 Field(description="The owner of the repository.", examples=["polarsource"]), 

31] 

32RepositoryName = Annotated[ 1a

33 str, 

34 Field(description="The name of the repository.", examples=["private_repo"]), 

35] 

36 

37 

38class BenefitGitHubRepositoryCreateProperties(Schema): 1a

39 """ 

40 Properties to create a benefit of type `github_repository`. 

41 """ 

42 

43 repository_owner: str = Field( 1a

44 description="The owner of the repository.", examples=["polarsource"] 

45 ) 

46 repository_name: str = Field( 1a

47 description="The name of the repository.", examples=["private_repo"] 

48 ) 

49 permission: Permission 1a

50 

51 

52class BenefitGitHubRepositoryProperties(Schema): 1a

53 """ 

54 Properties for a benefit of type `github_repository`. 

55 """ 

56 

57 repository_owner: RepositoryOwner 1a

58 repository_name: RepositoryName 1a

59 permission: Permission 1a

60 repository_id: SkipJsonSchema[UUID4 | None] = Field(None, deprecated=True) 1a

61 

62 

63class BenefitGitHubRepositorySubscriberProperties(Schema): 1a

64 """ 

65 Properties available to subscribers for a benefit of type `github_repository`. 

66 """ 

67 

68 repository_owner: RepositoryOwner 1a

69 repository_name: RepositoryName 1a

70 

71 

72class BenefitGitHubRepositoryCreate(BenefitCreateBase): 1a

73 type: Literal[BenefitType.github_repository] 1a

74 properties: BenefitGitHubRepositoryCreateProperties 1a

75 

76 

77class BenefitGitHubRepositoryUpdate(BenefitUpdateBase): 1a

78 type: Literal[BenefitType.github_repository] 1a

79 properties: BenefitGitHubRepositoryCreateProperties | None = None 1a

80 

81 

82class BenefitGitHubRepository(BenefitBase): 1a

83 """ 

84 A benefit of type `github_repository`. 

85 

86 Use it to automatically invite your backers to a private GitHub repository. 

87 """ 

88 

89 type: Literal[BenefitType.github_repository] 1a

90 properties: BenefitGitHubRepositoryProperties 1a

91 

92 

93class BenefitGitHubRepositorySubscriber(BenefitSubscriberBase): 1a

94 type: Literal[BenefitType.github_repository] 1a

95 properties: BenefitGitHubRepositorySubscriberProperties 1a