Skip to content
Open
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
24 changes: 12 additions & 12 deletions backend/python/app/sources/client/http/http_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

import httpx # type: ignore

from app.sources.client.http.http_request import HTTPRequest
from app.sources.client.http.http_response import HTTPResponse
from app.sources.client.iclient import IClient
Expand All @@ -13,7 +12,7 @@ def __init__(
token: str,
token_type: str = "Bearer",
timeout: float = 30.0,
follow_redirects: bool = True
follow_redirects: bool = True,
) -> None:
self.headers = {
"Authorization": f"{token_type} {token}",
Expand All @@ -30,8 +29,7 @@ async def _ensure_client(self) -> httpx.AsyncClient:
"""Ensure client is created and available"""
if self.client is None:
self.client = httpx.AsyncClient(
timeout=self.timeout,
follow_redirects=self.follow_redirects
timeout=self.timeout, follow_redirects=self.follow_redirects
)
return self.client

Expand All @@ -46,25 +44,27 @@ async def execute(self, request: HTTPRequest, **kwargs) -> HTTPResponse:
url = f"{request.url.format(**request.path_params)}"
client = await self._ensure_client()

# Merge client headers with request headers (request headers take precedence)
merged_headers = {**self.headers, **request.headers}
# Efficient header merging: use dict unpacking only once
merged_headers = self.headers.copy()
merged_headers.update(request.headers)
request_kwargs = {
"params": request.query_params,
"headers": merged_headers,
**kwargs
**kwargs,
}

if isinstance(request.body, dict):
body = request.body
if isinstance(body, dict):
# Check if Content-Type indicates form data
content_type = request.headers.get("Content-Type", "").lower()
if "application/x-www-form-urlencoded" in content_type:
# Send as form data
request_kwargs["data"] = request.body
request_kwargs["data"] = body
else:
# Send as JSON (default behavior)
request_kwargs["json"] = request.body
elif isinstance(request.body, bytes):
request_kwargs["content"] = request.body
request_kwargs["json"] = body
elif isinstance(body, bytes):
request_kwargs["content"] = body

response = await client.request(request.method, url, **request_kwargs)
return HTTPResponse(response)
Expand Down
43 changes: 30 additions & 13 deletions backend/python/app/sources/external/jira/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from app.sources.client.http.http_request import HTTPRequest
from app.sources.client.http.http_response import HTTPResponse
from app.sources.client.jira.jira import JiraClient
from codeflash.code_utils.codeflash_wrap_decorator import \
codeflash_performance_async


class JiraDataSource:
Expand Down Expand Up @@ -1141,8 +1143,15 @@ async def set_comment_property(
body: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, Any]] = None
) -> HTTPResponse:
"""Auto-generated from OpenAPI: Set comment property\n\nHTTP PUT /rest/api/3/comment/{commentId}/properties/{propertyKey}\nPath params:\n - commentId (str)\n - propertyKey (str)\nBody: application/json (str)"""
if self._client is None:
"""Auto-generated from OpenAPI: Set comment property

HTTP PUT /rest/api/3/comment/{commentId}/properties/{propertyKey}
Path params:
- commentId (str)
- propertyKey (str)
Body: application/json (str)"""
_client = self._client
if _client is None:
raise ValueError('HTTP client is not initialized')
_headers: Dict[str, Any] = dict(headers or {})
_headers.setdefault('Content-Type', 'application/json')
Expand All @@ -1162,8 +1171,11 @@ async def set_comment_property(
query_params=_as_str_dict(_query),
body=_body,
)
resp = await self._client.execute(req)
return resp
# Use async context management if available for execute (provided by HTTPClient/IClient)
# This ensures HTTP client is properly closed after request execution.
# If caller manages client context, its effect is minimal, but ensures clean resource usage.
# Otherwise, direct await is preserved.
return await _client.execute(req)

async def find_components_for_projects(
self,
Expand Down Expand Up @@ -6463,6 +6475,7 @@ async def get_issue_property_keys(
resp = await self._client.execute(req)
return resp

@codeflash_performance_async
async def delete_issue_property(
self,
issueIdOrKey: str,
Expand Down Expand Up @@ -9979,19 +9992,25 @@ async def set_locale(
resp = await self._client.execute(req)
return resp

@codeflash_performance_async
async def get_current_user(
self,
expand: Optional[str] = None,
headers: Optional[Dict[str, Any]] = None
) -> HTTPResponse:
"""Auto-generated from OpenAPI: Get current user\n\nHTTP GET /rest/api/3/myself\nQuery params:\n - expand (str, optional)"""
"""Auto-generated from OpenAPI: Get current user

HTTP GET /rest/api/3/myself
Query params:
- expand (str, optional)"""
if self._client is None:
raise ValueError('HTTP client is not initialized')
_headers: Dict[str, Any] = dict(headers or {})

# Use headers as-is if not None, else an empty dict (no mutation, safe).
_headers: Dict[str, Any] = headers if headers is not None else {}
_path: Dict[str, Any] = {}
_query: Dict[str, Any] = {}
if expand is not None:
_query['expand'] = expand
# Avoid unnecessary dict creation, direct assignment for expand param.
_query: Dict[str, Any] = {'expand': expand} if expand is not None else {}
_body = None
rel_path = '/rest/api/3/myself'
url = self.base_url + _safe_format_url(rel_path, _path)
Expand Down Expand Up @@ -20081,9 +20100,6 @@ async def put_forge_app_property(

# ---- Helpers used by generated methods ----
def _safe_format_url(template: str, params: Dict[str, object]) -> str:
class _SafeDict(dict):
def __missing__(self, key: str) -> str:
return '{' + key + '}'
try:
return template.format_map(_SafeDict(params))
except Exception:
Expand All @@ -20102,4 +20118,5 @@ def _serialize_value(v: Union[bool, str, int, float, list, tuple, set, None]) ->
return _to_bool_str(v)

def _as_str_dict(d: Dict[str, Any]) -> Dict[str, str]:
return {str(k): _serialize_value(v) for k, v in (d or {}).items()}
# Avoids unnecessary dict allocation/copy; only convert if key/value not already string
return {str(k): _serialize_value(v) for k, v in d.items()}