mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 23:15:09 +00:00
Make parser work well for objects with unknown names
This commit is contained in:
parent
1bf7eaa932
commit
ea545e27a3
3 changed files with 2496 additions and 164 deletions
245
tools/output.py
245
tools/output.py
|
@ -30,4 +30,247 @@ class SimpleUser(TypedDict):
|
||||||
starred_at: NotRequired[str]
|
starred_at: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
GeneratedObject = List[SimpleUser]
|
class Permissions(TypedDict):
|
||||||
|
admin: NotRequired[bool]
|
||||||
|
maintain: NotRequired[bool]
|
||||||
|
push: NotRequired[bool]
|
||||||
|
triage: NotRequired[bool]
|
||||||
|
pull: NotRequired[bool]
|
||||||
|
|
||||||
|
|
||||||
|
class LicenseSimple(TypedDict):
|
||||||
|
key: str
|
||||||
|
name: str
|
||||||
|
url: Optional[str]
|
||||||
|
spdx_id: Optional[str]
|
||||||
|
node_id: str
|
||||||
|
html_url: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
|
class Repository(TypedDict):
|
||||||
|
id: int
|
||||||
|
node_id: str
|
||||||
|
name: str
|
||||||
|
full_name: str
|
||||||
|
license: Optional[LicenseSimple]
|
||||||
|
organization: NotRequired[Optional[SimpleUser]]
|
||||||
|
forks: int
|
||||||
|
permissions: NotRequired[Permissions]
|
||||||
|
owner: SimpleUser
|
||||||
|
private: bool
|
||||||
|
html_url: str
|
||||||
|
description: Optional[str]
|
||||||
|
fork: bool
|
||||||
|
url: str
|
||||||
|
archive_url: str
|
||||||
|
assignees_url: str
|
||||||
|
blobs_url: str
|
||||||
|
branches_url: str
|
||||||
|
collaborators_url: str
|
||||||
|
comments_url: str
|
||||||
|
commits_url: str
|
||||||
|
compare_url: str
|
||||||
|
contents_url: str
|
||||||
|
contributors_url: str
|
||||||
|
deployments_url: str
|
||||||
|
downloads_url: str
|
||||||
|
events_url: str
|
||||||
|
forks_url: str
|
||||||
|
git_commits_url: str
|
||||||
|
git_refs_url: str
|
||||||
|
git_tags_url: str
|
||||||
|
git_url: str
|
||||||
|
issue_comment_url: str
|
||||||
|
issue_events_url: str
|
||||||
|
issues_url: str
|
||||||
|
keys_url: str
|
||||||
|
labels_url: str
|
||||||
|
languages_url: str
|
||||||
|
merges_url: str
|
||||||
|
milestones_url: str
|
||||||
|
notifications_url: str
|
||||||
|
pulls_url: str
|
||||||
|
releases_url: str
|
||||||
|
ssh_url: str
|
||||||
|
stargazers_url: str
|
||||||
|
statuses_url: str
|
||||||
|
subscribers_url: str
|
||||||
|
subscription_url: str
|
||||||
|
tags_url: str
|
||||||
|
teams_url: str
|
||||||
|
trees_url: str
|
||||||
|
clone_url: str
|
||||||
|
mirror_url: Optional[str]
|
||||||
|
hooks_url: str
|
||||||
|
svn_url: str
|
||||||
|
homepage: Optional[str]
|
||||||
|
language: Optional[str]
|
||||||
|
forks_count: int
|
||||||
|
stargazers_count: int
|
||||||
|
watchers_count: int
|
||||||
|
size: int
|
||||||
|
default_branch: str
|
||||||
|
open_issues_count: int
|
||||||
|
is_template: NotRequired[bool]
|
||||||
|
topics: NotRequired[List[str]]
|
||||||
|
has_issues: bool
|
||||||
|
has_projects: bool
|
||||||
|
has_wiki: bool
|
||||||
|
has_pages: bool
|
||||||
|
has_downloads: bool
|
||||||
|
archived: bool
|
||||||
|
disabled: bool
|
||||||
|
visibility: NotRequired[str]
|
||||||
|
pushed_at: Optional[str]
|
||||||
|
created_at: Optional[str]
|
||||||
|
updated_at: Optional[str]
|
||||||
|
allow_rebase_merge: NotRequired[bool]
|
||||||
|
template_repository: NotRequired[Optional[dict]]
|
||||||
|
temp_clone_token: NotRequired[str]
|
||||||
|
allow_squash_merge: NotRequired[bool]
|
||||||
|
allow_auto_merge: NotRequired[bool]
|
||||||
|
delete_branch_on_merge: NotRequired[bool]
|
||||||
|
allow_update_branch: NotRequired[bool]
|
||||||
|
use_squash_pr_title_as_default: NotRequired[bool]
|
||||||
|
allow_merge_commit: NotRequired[bool]
|
||||||
|
allow_forking: NotRequired[bool]
|
||||||
|
subscribers_count: NotRequired[int]
|
||||||
|
network_count: NotRequired[int]
|
||||||
|
open_issues: int
|
||||||
|
watchers: int
|
||||||
|
master_branch: NotRequired[str]
|
||||||
|
starred_at: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
|
class CodeOfConduct(TypedDict):
|
||||||
|
key: str
|
||||||
|
name: str
|
||||||
|
url: str
|
||||||
|
body: NotRequired[str]
|
||||||
|
html_url: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
|
class MinimalRepository(TypedDict):
|
||||||
|
id: int
|
||||||
|
node_id: str
|
||||||
|
name: str
|
||||||
|
full_name: str
|
||||||
|
owner: SimpleUser
|
||||||
|
private: bool
|
||||||
|
html_url: str
|
||||||
|
description: Optional[str]
|
||||||
|
fork: bool
|
||||||
|
url: str
|
||||||
|
archive_url: str
|
||||||
|
assignees_url: str
|
||||||
|
blobs_url: str
|
||||||
|
branches_url: str
|
||||||
|
collaborators_url: str
|
||||||
|
comments_url: str
|
||||||
|
commits_url: str
|
||||||
|
compare_url: str
|
||||||
|
contents_url: str
|
||||||
|
contributors_url: str
|
||||||
|
deployments_url: str
|
||||||
|
downloads_url: str
|
||||||
|
events_url: str
|
||||||
|
forks_url: str
|
||||||
|
git_commits_url: str
|
||||||
|
git_refs_url: str
|
||||||
|
git_tags_url: str
|
||||||
|
git_url: NotRequired[str]
|
||||||
|
issue_comment_url: str
|
||||||
|
issue_events_url: str
|
||||||
|
issues_url: str
|
||||||
|
keys_url: str
|
||||||
|
labels_url: str
|
||||||
|
languages_url: str
|
||||||
|
merges_url: str
|
||||||
|
milestones_url: str
|
||||||
|
notifications_url: str
|
||||||
|
pulls_url: str
|
||||||
|
releases_url: str
|
||||||
|
ssh_url: NotRequired[str]
|
||||||
|
stargazers_url: str
|
||||||
|
statuses_url: str
|
||||||
|
subscribers_url: str
|
||||||
|
subscription_url: str
|
||||||
|
tags_url: str
|
||||||
|
teams_url: str
|
||||||
|
trees_url: str
|
||||||
|
clone_url: NotRequired[str]
|
||||||
|
mirror_url: NotRequired[Optional[str]]
|
||||||
|
hooks_url: str
|
||||||
|
svn_url: NotRequired[str]
|
||||||
|
homepage: NotRequired[Optional[str]]
|
||||||
|
language: NotRequired[Optional[str]]
|
||||||
|
forks_count: NotRequired[int]
|
||||||
|
stargazers_count: NotRequired[int]
|
||||||
|
watchers_count: NotRequired[int]
|
||||||
|
size: NotRequired[int]
|
||||||
|
default_branch: NotRequired[str]
|
||||||
|
open_issues_count: NotRequired[int]
|
||||||
|
is_template: NotRequired[bool]
|
||||||
|
topics: NotRequired[List[str]]
|
||||||
|
has_issues: NotRequired[bool]
|
||||||
|
has_projects: NotRequired[bool]
|
||||||
|
has_wiki: NotRequired[bool]
|
||||||
|
has_pages: NotRequired[bool]
|
||||||
|
has_downloads: NotRequired[bool]
|
||||||
|
archived: NotRequired[bool]
|
||||||
|
disabled: NotRequired[bool]
|
||||||
|
visibility: NotRequired[str]
|
||||||
|
pushed_at: NotRequired[Optional[str]]
|
||||||
|
created_at: NotRequired[Optional[str]]
|
||||||
|
updated_at: NotRequired[Optional[str]]
|
||||||
|
permissions: NotRequired[Permissions]
|
||||||
|
role_name: NotRequired[str]
|
||||||
|
template_repository: NotRequired[Optional[Repository]]
|
||||||
|
temp_clone_token: NotRequired[str]
|
||||||
|
delete_branch_on_merge: NotRequired[bool]
|
||||||
|
subscribers_count: NotRequired[int]
|
||||||
|
network_count: NotRequired[int]
|
||||||
|
code_of_conduct: NotRequired[CodeOfConduct]
|
||||||
|
license: NotRequired[Optional[dict]]
|
||||||
|
forks: NotRequired[int]
|
||||||
|
open_issues: NotRequired[int]
|
||||||
|
watchers: NotRequired[int]
|
||||||
|
allow_forking: NotRequired[bool]
|
||||||
|
|
||||||
|
|
||||||
|
class GeneratedObject116(TypedDict):
|
||||||
|
text: NotRequired[str]
|
||||||
|
indices: NotRequired[List[int]]
|
||||||
|
|
||||||
|
|
||||||
|
class GeneratedObject122(TypedDict):
|
||||||
|
object_url: NotRequired[str]
|
||||||
|
object_type: NotRequired[Optional[str]]
|
||||||
|
property: NotRequired[str]
|
||||||
|
fragment: NotRequired[str]
|
||||||
|
matches: NotRequired[List[GeneratedObject116]]
|
||||||
|
|
||||||
|
|
||||||
|
class CodeSearchResultItem(TypedDict):
|
||||||
|
name: str
|
||||||
|
path: str
|
||||||
|
sha: str
|
||||||
|
url: str
|
||||||
|
git_url: str
|
||||||
|
html_url: str
|
||||||
|
repository: MinimalRepository
|
||||||
|
score: float
|
||||||
|
file_size: NotRequired[int]
|
||||||
|
language: NotRequired[Optional[str]]
|
||||||
|
last_modified_at: NotRequired[str]
|
||||||
|
line_numbers: NotRequired[List[str]]
|
||||||
|
text_matches: NotRequired[List[GeneratedObject122]]
|
||||||
|
|
||||||
|
|
||||||
|
class GeneratedObject188(TypedDict):
|
||||||
|
total_count: int
|
||||||
|
incomplete_results: bool
|
||||||
|
items: List[CodeSearchResultItem]
|
||||||
|
|
||||||
|
|
||||||
|
GeneratedObject = GeneratedObject188
|
||||||
|
|
2403
tools/source.json
2403
tools/source.json
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
__all__ = ("generate",)
|
__all__ = ("generate",)
|
||||||
|
|
||||||
from typing import Tuple # , Any
|
from random import randint
|
||||||
|
from typing import Tuple, Optional # , Any
|
||||||
|
|
||||||
types = {
|
types = {
|
||||||
"string": "str",
|
"string": "str",
|
||||||
|
@ -24,7 +25,7 @@ types = {
|
||||||
|
|
||||||
|
|
||||||
def _generate(
|
def _generate(
|
||||||
obj: dict, /, *, title: str = "GeneratedObject", no_comments: bool = False
|
obj: dict, /, *, title: Optional[str] = None, no_comments: bool = False
|
||||||
) -> Tuple[str, str]: # sourcery skip: low-code-quality
|
) -> Tuple[str, str]: # sourcery skip: low-code-quality
|
||||||
"""Makes TypedDict from a JSON Schema object.
|
"""Makes TypedDict from a JSON Schema object.
|
||||||
|
|
||||||
|
@ -36,6 +37,9 @@ def _generate(
|
||||||
Returns:
|
Returns:
|
||||||
The generated TypedDicts, the result values name and the comments.
|
The generated TypedDicts, the result values name and the comments.
|
||||||
"""
|
"""
|
||||||
|
if title is None:
|
||||||
|
title = f"GeneratedObject{randint(100, 200)}"
|
||||||
|
|
||||||
# The other TypedDicts
|
# The other TypedDicts
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
@ -209,7 +213,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
def generate(
|
def generate(
|
||||||
schema: dict, /, *, object_name: str = "GeneratedObject", no_comments: bool = False
|
schema: dict, /, *, object_name: Optional[str] = None, no_comments: bool = False
|
||||||
) -> str:
|
) -> str:
|
||||||
generated = _generate(schema, title=object_name, no_comments=no_comments)
|
generated = _generate(schema, title=object_name, no_comments=no_comments)
|
||||||
return text.format(generated, object_name)
|
return text.format(generated, object_name or "GeneratedObject")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue