perf: bound My Work authorization requests (#171)
This commit is contained in:
1 parent
5ce29fbe7d
commit
484c0d4aeb
2 files changed
+85
-47
No files matched your search
+34
-18
@@ -544,25 +544,29 @@ async def issue_detail(repository: str, number: int) -> dict:
|
||||
}
|
||||
|
||||
|
||||
async def _work_contains(stream: str, repository: str, number: int) -> bool:
|
||||
page = 1
|
||||
while page <= 100:
|
||||
result = await work_page(stream, page)
|
||||
if any(
|
||||
item.get("number") == number
|
||||
and isinstance(item.get("repository"), dict)
|
||||
and item["repository"].get("full_name") == repository
|
||||
for item in result["items"]
|
||||
):
|
||||
return True
|
||||
if not result["has_more"]:
|
||||
return False
|
||||
page += 1
|
||||
return False
|
||||
async def _current_login_and_target(path: str) -> tuple[str, dict]:
|
||||
user, target = await asyncio.gather(current_user(), fetch(path))
|
||||
login = user.get("login") if isinstance(user, dict) else None
|
||||
if not isinstance(login, str) or not login or not isinstance(target, dict):
|
||||
return "", {}
|
||||
return login, target
|
||||
|
||||
|
||||
def _login_in_users(login: str, value: object) -> bool:
|
||||
return isinstance(value, list) and any(
|
||||
isinstance(user, dict) and user.get("login") == login for user in value
|
||||
)
|
||||
|
||||
|
||||
async def is_assigned_issue(repository: str, number: int) -> bool:
|
||||
return await _work_contains("issue", repository, number)
|
||||
login, issue = await _current_login_and_target(
|
||||
f"repos/{repository}/issues/{number}"
|
||||
)
|
||||
return (
|
||||
issue.get("state") == "open"
|
||||
and not isinstance(issue.get("pull_request"), dict)
|
||||
and _login_in_users(login, issue.get("assignees"))
|
||||
)
|
||||
|
||||
|
||||
async def pull_requests() -> WorkItems:
|
||||
@@ -592,11 +596,23 @@ async def pull_requests() -> WorkItems:
|
||||
|
||||
|
||||
async def is_requested_review(repository: str, number: int) -> bool:
|
||||
return await _work_contains("review", repository, number)
|
||||
login, pull = await _current_login_and_target(
|
||||
f"repos/{repository}/pulls/{number}"
|
||||
)
|
||||
return (
|
||||
pull.get("state") == "open"
|
||||
and _login_in_users(login, pull.get("requested_reviewers"))
|
||||
)
|
||||
|
||||
|
||||
async def is_assigned_pull(repository: str, number: int) -> bool:
|
||||
return await _work_contains("pull", repository, number)
|
||||
login, pull = await _current_login_and_target(
|
||||
f"repos/{repository}/pulls/{number}"
|
||||
)
|
||||
return (
|
||||
pull.get("state") == "open"
|
||||
and _login_in_users(login, pull.get("assignees"))
|
||||
)
|
||||
|
||||
|
||||
async def pull_completion_detail(repository: str, number: int) -> dict:
|
||||
|
||||
Reference in new issue
Block a user