Skip to content

Commit

Permalink
Introduce get_assigned() & get_created()
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 19, 2023
1 parent 0aa8f5a commit 3132929
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
3 changes: 3 additions & 0 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def __exit__(self, exc_type, exc_value, traceback):
def __repr__(self) -> str:
return f"{self.__class__.__name__}(url='{self.url}')"

def __hash__(self) -> int:
return hash(self.url)

def _not_found(self, url: str, tag: str) -> Issue:
now = datetime.now(tz=utc)
return Issue(
Expand Down
60 changes: 42 additions & 18 deletions services/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ def __del__(self):
except AttributeError:
pass

def get_assigned(
self,
username: str = "me",
) -> list[Issue] | None:
"""
Get assigned issues
"""
try:
user = self.client.user.get(username)
issues = self.client.issue.filter(assigned_to_id=user.id)
except (BaseRedmineError, RequestException) as exc:
logging.error("Redmine: %s: get_assigned(%s): %s", self.url, username, exc)
return None
return [self._to_issue(issue) for issue in issues]

def get_created(
self,
username: str = "me",
) -> list[Issue] | None:
"""
Get created issues
"""
try:
user = self.client.user.get(username)
issues = self.client.issue.filter(author=user.id)
except (BaseRedmineError, RequestException) as exc:
logging.error("Redmine: %s: get_created(%s): %s", self.url, username, exc)
return None
return [self._to_issue(issue) for issue in issues]

def get_user_issues( # pylint: disable=too-many-arguments
self,
username: str = "me",
Expand All @@ -49,24 +79,18 @@ def get_user_issues( # pylint: disable=too-many-arguments
"""
if involved:
assigned = created = True
issues = []
try:
user = self.client.user.get(username)
if assigned:
issues = list(self.client.issue.filter(assigned_to_id=user.id))
found_ids = {i.id for i in issues}
if created:
issues.extend(
issue
for issue in self.client.issue.filter(author_id=user.id)
if issue.id not in found_ids
)
except (BaseRedmineError, RequestException) as exc:
logging.error(
"Redmine: %s: get_user_issues(%s): %s", self.url, username, exc
)
return None
return [self._to_issue(issue) for issue in issues]
issues: list[Issue] = []
if assigned:
more = self.get_assigned(username)
if more is None:
return None
issues.extend(more)
if created:
more = self.get_created(username)
if more is None:
return None
issues.extend(more)
return list(set(issues))

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

0 comments on commit 3132929

Please sign in to comment.