Skip to content

Commit

Permalink
Minor readability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 19, 2023
1 parent 71c5775 commit 7a7449f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 74 deletions.
23 changes: 11 additions & 12 deletions services/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,32 @@ def get_user_issues( # pylint: disable=too-many-arguments
assigned: bool = True,
created: bool = True,
involved: bool = True,
closed: bool = False,
**_,
**kwargs,
) -> list[Issue] | None:
"""
Get user issues
"""
if involved:
assigned = created = True
issues: list[Issue] = []
all_issues: list[Issue] = []

def get_assigned_issues():
more = self.get_assigned(username, closed=closed)
if more is not None:
issues.extend(more)
def get_assigned_issues() -> None:
issues = self.get_assigned(username, **kwargs)
if issues is not None:
all_issues.extend(issues)

def get_created_issues():
more = self.get_created(username, closed=closed)
if more is not None:
issues.extend(more)
def get_created_issues() -> None:
issues = self.get_created(username, **kwargs)
if issues is not None:
all_issues.extend(issues)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))
return list(set(all_issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
Expand Down
37 changes: 14 additions & 23 deletions services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,37 @@ def get_user_issues( # pylint: disable=too-many-arguments
assigned: bool = False,
created: bool = False,
involved: bool = True,
state: str = "opened",
**_,
**kwargs,
) -> list[Issue] | None:
"""
Get user issues
"""
if involved:
assigned = created = True
issues: list[Issue] = []
all_issues: list[Issue] = []

def get_issues(is_pr: bool, is_assigned: bool):
def get_issues(is_pr: bool, is_assigned: bool) -> list[Issue] | None:
if is_assigned:
more = self.get_assigned(username, pull_requests=is_pr, state=state)
issues = self.get_assigned(username, pull_requests=is_pr, **kwargs)
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more
issues = self.get_created(username, pull_requests=is_pr, **kwargs)
return issues

with ThreadPoolExecutor(max_workers=4) as executor:
futures = []
if assigned:
futures.append(
executor.submit(get_issues, False, True)
) # Get assigned non-PR issues
futures.append(
executor.submit(get_issues, True, True)
) # Get assigned PR issues
futures.append(executor.submit(get_issues, False, True))
futures.append(executor.submit(get_issues, True, True))
if created:
futures.append(
executor.submit(get_issues, False, False)
) # Get created non-PR issues
futures.append(
executor.submit(get_issues, True, False)
) # Get created PR issues
futures.append(executor.submit(get_issues, False, False))
futures.append(executor.submit(get_issues, True, False))
for future in futures:
more = future.result()
if more is None:
issues = future.result()
if issues is None:
return None
issues.extend(more)
all_issues.extend(issues)

return list(set(issues))
return list(set(all_issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
Expand Down
20 changes: 10 additions & 10 deletions services/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ def get_user_issues( # pylint: disable=too-many-arguments
"""
if involved:
assigned = created = True
issues: list[Issue] = []
all_issues: list[Issue] = []

def get_assigned_issues():
more = self.get_assigned(username)
if more is not None:
issues.extend(more)
def get_assigned_issues() -> None:
issues = self.get_assigned(username)
if issues is not None:
all_issues.extend(issues)

def get_created_issues():
more = self.get_created(username)
if more is not None:
issues.extend(more)
def get_created_issues() -> None:
issues = self.get_created(username)
if issues is not None:
all_issues.extend(issues)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))
return list(set(all_issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
if not kwargs.get("repo"):
Expand Down
37 changes: 14 additions & 23 deletions services/pagure.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,37 @@ def get_user_issues( # pylint: disable=too-many-arguments
assigned: bool = False,
created: bool = False,
involved: bool = True,
state: str = "Open",
**_,
**kwargs,
) -> list[Issue] | None:
"""
Get user issues
"""
if involved:
assigned = created = True
issues: list[Issue] = []
all_issues: list[Issue] = []

def get_issues(is_pr: bool, is_assigned: bool):
def get_issues(is_pr: bool, is_assigned: bool) -> list[Issue] | None:
if is_assigned:
more = self.get_assigned(username, pull_requests=is_pr, state=state)
issues = self.get_assigned(username, pull_requests=is_pr, **kwargs)
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more
issues = self.get_created(username, pull_requests=is_pr, **kwargs)
return issues

with ThreadPoolExecutor(max_workers=4) as executor:
futures = []
if assigned:
futures.append(
executor.submit(get_issues, False, True)
) # Get assigned non-PR issues
futures.append(
executor.submit(get_issues, True, True)
) # Get assigned PR issues
futures.append(executor.submit(get_issues, False, True))
futures.append(executor.submit(get_issues, True, True))
if created:
futures.append(
executor.submit(get_issues, False, False)
) # Get created non-PR issues
futures.append(
executor.submit(get_issues, True, False)
) # Get created PR issues
futures.append(executor.submit(get_issues, False, False))
futures.append(executor.submit(get_issues, True, False))
for future in futures:
more = future.result()
if more is None:
issues = future.result()
if issues is None:
return None
issues.extend(more)
all_issues.extend(issues)

return list(set(issues))
return list(set(all_issues))

def _to_issue(self, info: Any, **kwargs) -> Issue:
repo = kwargs.get("repo", "") or info["project"]["fullname"]
Expand Down
12 changes: 6 additions & 6 deletions services/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ def get_user_issues( # pylint: disable=too-many-arguments
"""
if involved:
assigned = created = True
issues: list[Issue] = []
all_issues: list[Issue] = []

def get_assigned_issues():
def get_assigned_issues() -> None:
more = self.get_assigned(username)
if more is not None:
issues.extend(more)
all_issues.extend(more)

def get_created_issues():
def get_created_issues() -> None:
more = self.get_created(username)
if more is not None:
issues.extend(more)
all_issues.extend(more)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))
return list(set(all_issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
Expand Down

0 comments on commit 7a7449f

Please sign in to comment.