Skip to content

Commit 5ef5a4e

Browse files
authored
🐛 add schema override for timeline event
1 parent 106b51b commit 5ef5a4e

File tree

8 files changed

+231
-46
lines changed

8 files changed

+231
-46
lines changed

codegen/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from typing import Dict
1+
from typing import Any, Dict
22

33
from pydantic import BaseModel
4+
import openapi_schema_pydantic as oas
45

56

67
class Config(BaseModel):
78
rest_descrition_source: str
89
webhook_schema_source: str
910
class_overrides: Dict[str, str] = {}
1011
field_overrides: Dict[str, str] = {}
12+
schema_overrides: Dict[str, Dict[str, Any]] = {}
1113

1214
client_output: str
1315
webhooks_output: str

codegen/parser/schemas/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import openapi_schema_pydantic as oas
55

66
from ...source import Source
7-
from ..utils import schema_from_source
87
from .schema import Property as Property
98
from .schema import AnySchema as AnySchema
109
from .schema import IntSchema as IntSchema
@@ -21,13 +20,16 @@
2120
from .schema import StringSchema as StringSchema
2221
from .. import add_schema, get_schema, get_schemas
2322
from .schema import DateTimeSchema as DateTimeSchema
23+
from ..utils import merge_dict, schema_from_source, get_schema_override
2424

2525

2626
def parse_schema(
2727
source: Source, class_name: str, base_source: Optional[Source] = None
2828
) -> SchemaData:
2929
data = source.data
3030
try:
31+
if overrides := get_schema_override(source):
32+
data = merge_dict(data, overrides)
3133
data = parse_obj_as(Union[oas.Reference, oas.Schema], data)
3234
except Exception as e:
3335
raise TypeError(f"Invalid Schema from {source.uri}") from e

codegen/parser/utils.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
22
import builtins
3+
from copy import deepcopy
34
from keyword import iskeyword
4-
from typing import List, Union
5+
from typing import Any, Dict, List, Union, Optional
56

67
from pydantic import parse_obj_as
78
import openapi_schema_pydantic as oas
@@ -70,7 +71,7 @@ def concat_snake_name(*names: str) -> str:
7071
return "_".join(snake_case(name) for name in names)
7172

7273

73-
def build_boolean(value: bool | str) -> bool:
74+
def build_boolean(value: Union[bool, str]) -> bool:
7475
if isinstance(value, bool):
7576
return value
7677
return value.lower() not in {"false", "f", "no", "n", "0"}
@@ -88,9 +89,28 @@ def build_prop_name(name: str) -> str:
8889
return fix_reserved_words(snake_case(name))
8990

9091

92+
def get_schema_override(source: Source) -> Optional[Dict[str, Any]]:
93+
config = get_config()
94+
return config.schema_overrides.get(source.pointer.path, None)
95+
96+
97+
def merge_dict(old: dict, new: dict) -> dict:
98+
result = deepcopy(old)
99+
for key, value in new.items():
100+
result[key] = (
101+
merge_dict(result[key], value)
102+
if isinstance(value, dict) and isinstance(result[key], dict)
103+
else value
104+
)
105+
return result
106+
107+
91108
def schema_from_source(source: Source) -> oas.Schema:
92109
data = source.data
93110
try:
111+
assert isinstance(data, dict)
112+
if overrides := get_schema_override(source):
113+
data = merge_dict(data, overrides)
94114
return parse_obj_as(oas.Schema, data)
95115
except Exception as e:
96116
raise TypeError(f"Invalid Schema from {source.uri}") from e

githubkit/rest/code_scanning.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CodeScanningSarifsStatus,
2525
CodeScanningAlertInstance,
2626
CodeScanningSarifsReceipt,
27+
CodeScanningCodeqlDatabase,
2728
CodeScanningAnalysisDeletion,
2829
CodeScanningOrganizationAlertItems,
2930
ReposOwnerRepoCodeScanningSarifsPostBody,
@@ -652,6 +653,80 @@ async def async_delete_analysis(
652653
},
653654
)
654655

656+
def list_codeql_databases(
657+
self,
658+
owner: str,
659+
repo: str,
660+
) -> "Response[List[CodeScanningCodeqlDatabase]]":
661+
url = f"/repos/{owner}/{repo}/code-scanning/codeql/databases"
662+
663+
return self._github.request(
664+
"GET",
665+
url,
666+
response_model=List[CodeScanningCodeqlDatabase],
667+
error_models={
668+
"403": BasicError,
669+
"404": BasicError,
670+
"503": EnterprisesEnterpriseCodeScanningAlertsGetResponse503,
671+
},
672+
)
673+
674+
async def async_list_codeql_databases(
675+
self,
676+
owner: str,
677+
repo: str,
678+
) -> "Response[List[CodeScanningCodeqlDatabase]]":
679+
url = f"/repos/{owner}/{repo}/code-scanning/codeql/databases"
680+
681+
return await self._github.arequest(
682+
"GET",
683+
url,
684+
response_model=List[CodeScanningCodeqlDatabase],
685+
error_models={
686+
"403": BasicError,
687+
"404": BasicError,
688+
"503": EnterprisesEnterpriseCodeScanningAlertsGetResponse503,
689+
},
690+
)
691+
692+
def get_codeql_database(
693+
self,
694+
owner: str,
695+
repo: str,
696+
language: str,
697+
) -> "Response[CodeScanningCodeqlDatabase]":
698+
url = f"/repos/{owner}/{repo}/code-scanning/codeql/databases/{language}"
699+
700+
return self._github.request(
701+
"GET",
702+
url,
703+
response_model=CodeScanningCodeqlDatabase,
704+
error_models={
705+
"403": BasicError,
706+
"404": BasicError,
707+
"503": EnterprisesEnterpriseCodeScanningAlertsGetResponse503,
708+
},
709+
)
710+
711+
async def async_get_codeql_database(
712+
self,
713+
owner: str,
714+
repo: str,
715+
language: str,
716+
) -> "Response[CodeScanningCodeqlDatabase]":
717+
url = f"/repos/{owner}/{repo}/code-scanning/codeql/databases/{language}"
718+
719+
return await self._github.arequest(
720+
"GET",
721+
url,
722+
response_model=CodeScanningCodeqlDatabase,
723+
error_models={
724+
"403": BasicError,
725+
"404": BasicError,
726+
"503": EnterprisesEnterpriseCodeScanningAlertsGetResponse503,
727+
},
728+
)
729+
655730
@overload
656731
def upload_sarif(
657732
self,

githubkit/rest/issues.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ def list_labels_on_issue(
15121512
params=exclude_unset(params),
15131513
response_model=List[Label],
15141514
error_models={
1515+
"404": BasicError,
15151516
"410": BasicError,
15161517
},
15171518
)
@@ -1537,6 +1538,7 @@ async def async_list_labels_on_issue(
15371538
params=exclude_unset(params),
15381539
response_model=List[Label],
15391540
error_models={
1541+
"404": BasicError,
15401542
"410": BasicError,
15411543
},
15421544
)
@@ -1630,6 +1632,7 @@ def set_labels(
16301632
json=exclude_unset(json),
16311633
response_model=List[Label],
16321634
error_models={
1635+
"404": BasicError,
16331636
"410": BasicError,
16341637
"422": ValidationError,
16351638
},
@@ -1724,6 +1727,7 @@ async def async_set_labels(
17241727
json=exclude_unset(json),
17251728
response_model=List[Label],
17261729
error_models={
1730+
"404": BasicError,
17271731
"410": BasicError,
17281732
"422": ValidationError,
17291733
},
@@ -1820,6 +1824,7 @@ def add_labels(
18201824
json=exclude_unset(json),
18211825
response_model=List[Label],
18221826
error_models={
1827+
"404": BasicError,
18231828
"410": BasicError,
18241829
"422": ValidationError,
18251830
},
@@ -1916,6 +1921,7 @@ async def async_add_labels(
19161921
json=exclude_unset(json),
19171922
response_model=List[Label],
19181923
error_models={
1924+
"404": BasicError,
19191925
"410": BasicError,
19201926
"422": ValidationError,
19211927
},
@@ -1933,6 +1939,7 @@ def remove_all_labels(
19331939
"DELETE",
19341940
url,
19351941
error_models={
1942+
"404": BasicError,
19361943
"410": BasicError,
19371944
},
19381945
)
@@ -1949,6 +1956,7 @@ async def async_remove_all_labels(
19491956
"DELETE",
19501957
url,
19511958
error_models={
1959+
"404": BasicError,
19521960
"410": BasicError,
19531961
},
19541962
)

0 commit comments

Comments
 (0)