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 Redmine tickets with one call #11

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_urltag(string: str) -> dict[str, str | bool] | None:
# URL
string = string if string.startswith("https://") else f"https://{string}"
url = urlparse(string)
hostname = url.hostname.removeprefix("www.") if url.hostname is not None else ""
hostname = url.hostname if url.hostname is not None else ""
path = url.path.strip("/")
repo: str = ""
is_pr: bool = False
Expand Down
1 change: 1 addition & 0 deletions services/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def guess_service(server: str) -> Any:
"progress.opensuse.org": MyRedmine,
"src.opensuse.org": MyGitea,
"src.suse.de": MyGitea,
"illumos.org": MyRedmine,
"www.illumos.org": MyRedmine,
}
for hostname, cls in servers.items():
Expand Down
26 changes: 26 additions & 0 deletions services/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ 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]:
try:
found = [
self._to_issue(info)
for info in self.client.issue.filter(
issue_id=",".join([issue["issue_id"] for issue in issues])
)
]
except (BaseRedmineError, RequestException) as exc:
logging.error("Redmine: %s: get_issues(): %s", self.url, exc)
return []
found_ids = {str(issue.raw["id"]) for issue in found}
not_found = [
self._not_found(
tag=f"{self.tag}#{issue['issue_id']}",
url=f"{self.url}/issues/{issue['issue_id']}",
)
for issue in issues
if issue["issue_id"] not in found_ids
]
# Old Redmine instances don't support fetching multiple issues at once
# so fetch them one by one in the base class calling get_issue() above
if len(found) == 1 and len(not_found) >= len(found):
return super().get_issues(issues)
return found + not_found # type: ignore

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