Skip to content
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

Fetch multiple Jira tickets with one call #12

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions services/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def close(self) -> None:
pass

def _get_issues(self, filters: str) -> list[dict]:
filters = f"{filters} AND resolution IS EMPTY"
data = self.client.jql(filters)
issues = data["issues"]
while len(issues) < data["total"]:
Expand All @@ -44,7 +43,7 @@ def _get_issues(self, filters: str) -> list[dict]:
return issues

def get_user_issues(self) -> list[Issue]:
filters = "watcher = currentUser()"
filters = "watcher = currentUser() AND resolution IS EMPTY"
try:
issues = self._get_issues(filters)
except (ApiError, RequestException) as exc:
Expand All @@ -68,6 +67,24 @@ def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
return None
return self._to_issue(info)

def get_issues(self, issues: list[dict]) -> list[Issue | None]:
filters = f"key in ({','.join(issue['issue_id'] for issue in issues)})"
try:
found = [self._to_issue(info) for info in self._get_issues(filters=filters)]
except (ApiError, RequestException) as exc:
logging.error("Jira: %s: get_issues(): %s", self.url, exc)
return []
found_ids = {str(issue.raw["key"]) for issue in found}
not_found = [
self._not_found(
tag=f"{self.tag}#{issue['issue_id']}",
url=f"{self.url}/browse/{issue['issue_id']}",
)
for issue in issues
if issue["issue_id"] not in found_ids
]
return found + not_found # type: ignore

def _to_issue(self, info: Any) -> Issue:
return Issue(
tag=f"{self.tag}#{info['key']}",
Expand Down
Loading