Skip to content

Commit

Permalink
jira multiple sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
yairsimantov20 committed Oct 16, 2024
1 parent 10abd14 commit 69745d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions integrations/jira/jira/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
from contextlib import asynccontextmanager
from typing import Any, AsyncGenerator

import aiohttp
Expand Down Expand Up @@ -38,8 +39,14 @@ def __init__(self, jira_url: str, jira_email: str, jira_token: str) -> None:
self.api_url = f"{self.jira_rest_url}/api/3"
self.webhooks_url = f"{self.jira_rest_url}/webhooks/1.0/webhook"

def _create_session(self):
return aiohttp.ClientSession(auth=self.jira_api_auth, timeout=ClientTimeout(30))
@asynccontextmanager
async def _create_session(self):
try:
session = aiohttp.ClientSession(auth=self.jira_api_auth, timeout=ClientTimeout(30))
yield session
finally:
await session.close()


@staticmethod
def _generate_base_req_params(
Expand All @@ -55,22 +62,19 @@ async def _get_paginated_projects(self, params: dict[str, Any]) -> dict[str, Any
async with session.get(
f"{self.api_url}/project/search", params=params
) as project_response:
await session.close()
project_response.raise_for_status()
return await project_response.json()

async def _get_paginated_issues(self, params: dict[str, Any]) -> dict[str, Any]:
async with self._create_session() as session:
async with session.get(f"{self.api_url}/search", params=params) as issue_response:
await session.close()
issue_response.raise_for_status()
return await issue_response.json()

async def create_events_webhook(self, app_host: str) -> None:
webhook_target_app_host = f"{app_host}/integration/webhook"
async with self._create_session() as session:
async with session.get(f"{self.webhooks_url}") as webhook_check_response:
await session.close()
webhook_check_response.raise_for_status()
webhook_check = await webhook_check_response.json()

Expand All @@ -87,7 +91,6 @@ async def create_events_webhook(self, app_host: str) -> None:

async with self._create_session() as session:
async with session.post(f"{self.webhooks_url}", json=body) as webhook_create_response:
await session.close()
webhook_create_response.raise_for_status()
logger.info("Ocean real time reporting webhook created")

Expand All @@ -96,7 +99,6 @@ async def get_single_project(self, project_key: str) -> dict[str, Any]:
async with session.get(
f"{self.api_url}/project/{project_key}"
) as project_response:
await session.close()
project_response.raise_for_status()
return await project_response.json()

Expand Down Expand Up @@ -126,7 +128,6 @@ async def get_paginated_projects(
async def get_single_issue(self, issue_key: str) -> dict[str, Any]:
async with self._create_session() as session:
async with session.get(f"{self.api_url}/issue/{issue_key}") as issue_response:
await session.close()
issue_response.raise_for_status()
return await issue_response.json()

Expand Down
8 changes: 4 additions & 4 deletions integrations/jira/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions integrations/jira/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poetry]
name = "jira"
version = "0.1.89-dev022"
version = "0.1.89-dev023"
description = "Integration to bring information from Jira into Port"
authors = ["Mor Paz <mor@getport.io>"]

[tool.poetry.dependencies]
python = "^3.11"
port_ocean = {version = "0.12.2-dev14", extras = ["cli"]}
port_ocean = {version = "0.12.2-dev15", extras = ["cli"]}
httpx = "^0.27.0"

[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 69745d6

Please sign in to comment.