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 307f45d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 91 deletions.
31 changes: 16 additions & 15 deletions services/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,34 @@ 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() -> list[Issue] | None:
return self.get_assigned(username, **kwargs)

def get_created_issues():
more = self.get_created(username, closed=closed)
if more is not None:
issues.extend(more)
def get_created_issues() -> list[Issue] | None:
return self.get_created(username, **kwargs)

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

return list(set(issues))
futures.append(executor.submit(get_created_issues))
for future in futures:
issues = future.result()
if issues is None:
return None
all_issues.extend(issues)

return list(set(all_issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
Expand Down
41 changes: 15 additions & 26 deletions services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __del__(self):
pass

def get_assigned(
self, username: str = "", pull_requests: bool = False, state: str = "Open", **_
self, username: str = "", pull_requests: bool = False, state: str = "opened", **_
) -> list[Issue] | None:
"""
Get assigned issues
Expand All @@ -74,7 +74,7 @@ def get_assigned(
return [self._to_issue(issue) for issue in issues]

def get_created(
self, username: str = "", pull_requests: bool = False, state: str = "Open", **_
self, username: str = "", pull_requests: bool = False, state: str = "opened", **_
) -> list[Issue] | None:
"""
Get created issues
Expand Down Expand Up @@ -104,46 +104,35 @@ 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)
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more
return self.get_assigned(username, pull_requests=is_pr, **kwargs)
return self.get_created(username, pull_requests=is_pr, **kwargs)

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
28 changes: 15 additions & 13 deletions services/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,27 @@ 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() -> list[Issue] | None:
return self.get_assigned(username)

def get_created_issues():
more = self.get_created(username)
if more is not None:
issues.extend(more)
def get_created_issues() -> list[Issue] | None:
return self.get_created(username)

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

return list(set(issues))
futures.append(executor.submit(get_created_issues))
for future in futures:
issues = future.result()
if issues is None:
return None
all_issues.extend(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: 13 additions & 24 deletions services/pagure.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,35 @@ 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)
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more
return self.get_assigned(username, pull_requests=is_pr, **kwargs)
return self.get_created(username, pull_requests=is_pr, **kwargs)

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
28 changes: 15 additions & 13 deletions services/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,27 @@ 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() -> list[Issue] | None:
return self.get_assigned(username)

def get_created_issues():
more = self.get_created(username)
if more is not None:
issues.extend(more)
def get_created_issues() -> list[Issue] | None:
return self.get_created(username)

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

return list(set(issues))
futures.append(executor.submit(get_created_issues))
for future in futures:
issues = future.result()
if issues is None:
return None
all_issues.extend(issues)

return list(set(all_issues))

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

0 comments on commit 307f45d

Please sign in to comment.