mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +02:00
jira-connector: update get_issues_by_date_range method
This commit is contained in:
parent
abf017eabb
commit
107f013ff9
1 changed files with 28 additions and 27 deletions
|
|
@ -6,7 +6,6 @@ Allows fetching issue lists and their comments, projects and more.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import re
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
@ -221,7 +220,7 @@ class JiraConnector:
|
||||||
project_key: str | None = None,
|
project_key: str | None = None,
|
||||||
) -> tuple[list[dict[str, Any]], str | None]:
|
) -> tuple[list[dict[str, Any]], str | None]:
|
||||||
"""
|
"""
|
||||||
Fetch issues created OR updated within a date range using /search/jql.
|
Fetch issues within a date range.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
start_date: Start date in YYYY-MM-DD format
|
start_date: Start date in YYYY-MM-DD format
|
||||||
|
|
@ -233,20 +232,20 @@ class JiraConnector:
|
||||||
Tuple containing (issues list, error message or None)
|
Tuple containing (issues list, error message or None)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Validate date format (simple YYYY-MM-DD check)
|
# Build JQL query for date range
|
||||||
for d in (start_date, end_date):
|
# Query issues that were either created OR updated within the date range
|
||||||
if not re.match(r"^\d{4}-\d{2}-\d{2}$", d):
|
date_filter = (
|
||||||
return [], f"Invalid date format: {d}. Expected YYYY-MM-DD."
|
f"(createdDate >= '{start_date}' AND createdDate <= '{end_date}')"
|
||||||
|
|
||||||
# Build JQL: issues created OR updated within date range
|
|
||||||
date_jql = (
|
|
||||||
f'(created >= "{start_date}" AND created <= "{end_date}") '
|
|
||||||
f'OR (updated >= "{start_date}" AND updated <= "{end_date}")'
|
|
||||||
)
|
)
|
||||||
jql = f"({date_jql}) ORDER BY created DESC"
|
# TODO : This JQL needs some improvement to work as expected
|
||||||
if project_key:
|
|
||||||
jql = f'project = "{project_key}" AND {jql}'
|
|
||||||
|
|
||||||
|
_jql = f"{date_filter}"
|
||||||
|
if project_key:
|
||||||
|
_jql = (
|
||||||
|
f'project = "{project_key}" AND {date_filter} ORDER BY created DESC'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Define fields to retrieve
|
||||||
fields = [
|
fields = [
|
||||||
"summary",
|
"summary",
|
||||||
"description",
|
"description",
|
||||||
|
|
@ -259,25 +258,26 @@ class JiraConnector:
|
||||||
"issuetype",
|
"issuetype",
|
||||||
"project",
|
"project",
|
||||||
]
|
]
|
||||||
|
|
||||||
if include_comments:
|
if include_comments:
|
||||||
fields.append("comment")
|
fields.append("comment")
|
||||||
|
|
||||||
all_issues: list[dict[str, Any]] = []
|
print(f"JQL query: {_jql}")
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"jql": _jql,
|
||||||
|
"fields": ",".join(fields),
|
||||||
|
"maxResults": 100,
|
||||||
|
"startAt": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
all_issues = []
|
||||||
start_at = 0
|
start_at = 0
|
||||||
max_results = 100
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
json_payload = {
|
params["startAt"] = start_at
|
||||||
"jql": jql,
|
|
||||||
"fields": fields, # pass as list
|
|
||||||
"maxResults": max_results,
|
|
||||||
"startAt": start_at,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Call new endpoint with POST
|
result = self.make_api_request("search/jql", params)
|
||||||
result = self.make_api_request(
|
|
||||||
"search/jql", json_payload=json_payload, method="POST"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not isinstance(result, dict) or "issues" not in result:
|
if not isinstance(result, dict) or "issues" not in result:
|
||||||
return [], "Invalid response from Jira API"
|
return [], "Invalid response from Jira API"
|
||||||
|
|
@ -285,8 +285,9 @@ class JiraConnector:
|
||||||
issues = result["issues"]
|
issues = result["issues"]
|
||||||
all_issues.extend(issues)
|
all_issues.extend(issues)
|
||||||
|
|
||||||
|
# Check if there are more issues to fetch
|
||||||
total = result.get("total", 0)
|
total = result.get("total", 0)
|
||||||
if start_at + len(issues) >= total or len(issues) == 0:
|
if start_at + len(issues) >= total:
|
||||||
break
|
break
|
||||||
|
|
||||||
start_at += len(issues)
|
start_at += len(issues)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue