-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Cleanup - Github source #295
Changes from 2 commits
fc312a9
326f1c4
59b16c0
0a28547
c7583fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,15 @@ def _get_auth_header(access_token: str) -> StrAny: | |
# | ||
# Rest API helpers | ||
# | ||
def get_rest_pages(access_token: str, query: str) -> Iterator[List[StrAny]]: | ||
url = REST_API_BASE_URL + query | ||
while True: | ||
def _get_rest_pages(access_token: str, query: str) -> Iterator[List[StrAny]]: | ||
def _request(url: str) -> requests.Response: | ||
r = requests.get(url, headers=_get_auth_header(access_token)) | ||
print(f"got page {url}, requests left: " + r.headers["x-ratelimit-remaining"]) | ||
return r | ||
|
||
url = "https://api.github.com" + query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use REST_API_BASE_URL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
while True: | ||
r: requests.Response = _request(url) | ||
page_items = r.json() | ||
if len(page_items) == 0: | ||
break | ||
|
@@ -38,13 +43,14 @@ def get_rest_pages(access_token: str, query: str) -> Iterator[List[StrAny]]: | |
# | ||
# GraphQL API helpers | ||
# | ||
def get_reactions_data( | ||
def _get_reactions_data( | ||
node_type: str, | ||
owner: str, | ||
name: str, | ||
access_token: str, | ||
items_per_page: int, | ||
max_items: int, | ||
max_item_age_seconds: float = None, | ||
) -> Iterator[Iterator[StrAny]]: | ||
variables = { | ||
"owner": owner, | ||
|
@@ -104,11 +110,15 @@ def _extract_nested_nodes(item: DictStrAny) -> DictStrAny: | |
def _run_graphql_query( | ||
access_token: str, query: str, variables: DictStrAny | ||
) -> Tuple[StrAny, StrAny]: | ||
data = requests.post( | ||
GRAPHQL_API_BASE_URL, | ||
json={"query": query, "variables": variables}, | ||
headers=_get_auth_header(access_token), | ||
).json() | ||
def _request() -> requests.Response: | ||
r = requests.post( | ||
"https://api.github.com/graphql", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use GRAPHQL_API_BASE_URL instead of "https://api.github.com/graphql" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
json={"query": query, "variables": variables}, | ||
headers=_get_auth_header(access_token), | ||
) | ||
return r | ||
|
||
data = _request().json() | ||
if "errors" in data: | ||
raise ValueError(data) | ||
data = data["data"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you import this function to another script, so imo prefix "_", which means "private function", doesn't make sense.
you can keep it like
get_rest_pages
.same for
get_reactions_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.