Skip to content

Commit

Permalink
Feature: Added support to enable support for sprints
Browse files Browse the repository at this point in the history
  • Loading branch information
lordsarcastic committed Jan 3, 2025
1 parent ae1abcd commit df3cb0c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
17 changes: 4 additions & 13 deletions integrations/jira/jira/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import typing
from typing import Any, AsyncGenerator, Generator

from httpx import Auth, BasicAuth, Request, Response, Timeout
from loguru import logger
from port_ocean.context.event import event
from port_ocean.context.ocean import ocean
from port_ocean.utils import http_async_client

from jira.overrides import JiraResourceConfig

PAGE_SIZE = 50
WEBHOOK_NAME = "Port-Ocean-Events-Webhook"

Expand Down Expand Up @@ -144,17 +140,12 @@ async def get_single_issue(self, issue_key: str) -> dict[str, Any]:
issue_response.raise_for_status()
return issue_response.json()

async def get_paginated_issues(self) -> AsyncGenerator[list[dict[str, Any]], None]:
async def get_paginated_issues(
self, params: dict[str, Any] = {}
) -> AsyncGenerator[list[dict[str, Any]], None]:
logger.info("Getting issues from Jira")

params = self._generate_base_req_params()

config = typing.cast(JiraResourceConfig, event.resource_config)

if config.selector.jql:
params["jql"] = config.selector.jql
logger.info(f"Found JQL filter: {config.selector.jql}")

params.update(self._generate_base_req_params())
total_issues = (await self._get_paginated_issues(params))["total"]

if total_issues == 0:
Expand Down
21 changes: 13 additions & 8 deletions integrations/jira/jira/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
from pydantic import BaseModel, Field


class JiraResourceConfig(ResourceConfig):
class Selector(BaseModel):
query: str
jql: str | None = None
class JiraIssueSelector(Selector):
query: str
jql: str | None = None
fields: str | None = Field(
description="Additional fields to be included in the API response",
default="*all",
)


selector: Selector # type: ignore
kind: Literal["issue", "user"]
class JiraIssueConfig(ResourceConfig):
selector: JiraIssueSelector
kind: Literal["issue"]


class JiraProjectSelector(Selector):
Expand All @@ -31,12 +36,12 @@ class JiraProjectResourceConfig(ResourceConfig):

JiraResourcesConfig = Annotated[
Union[
JiraResourceConfig,
JiraIssueConfig,
JiraProjectResourceConfig,
],
Field(discriminator="kind"),
]


class JiraPortAppConfig(PortAppConfig):
resources: list[JiraResourceConfig | JiraProjectResourceConfig] # type: ignore
resources: list[JiraIssueConfig | JiraProjectResourceConfig] # type: ignore
15 changes: 13 additions & 2 deletions integrations/jira/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from enum import StrEnum
from typing import Any, cast

Expand All @@ -7,7 +8,7 @@
from port_ocean.core.ocean_types import ASYNC_GENERATOR_RESYNC_TYPE

from jira.client import JiraClient
from jira.overrides import JiraProjectResourceConfig
from jira.overrides import JiraIssueConfig, JiraProjectResourceConfig


class ObjectKind(StrEnum):
Expand Down Expand Up @@ -61,7 +62,17 @@ async def on_resync_issues(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
ocean.integration_config["atlassian_user_token"],
)

async for issues in client.get_paginated_issues():
params = {}
config = typing.cast(JiraIssueConfig, event.resource_config)

if config.selector.jql:
params["jql"] = config.selector.jql
logger.info(f"Found JQL filter: {config.selector.jql}")

if config.selector.fields:
params["fields"] = config.selector.fields

async for issues in client.get_paginated_issues(params):
logger.info(f"Received issue batch with {len(issues)} issues")
yield issues

Expand Down

0 comments on commit df3cb0c

Please sign in to comment.