Skip to content

Commit

Permalink
[Integration][Jira] Upgrade Jira integration to export issues by spri…
Browse files Browse the repository at this point in the history
…nt (#1296)
  • Loading branch information
lordsarcastic authored Jan 7, 2025
1 parent f05d5d4 commit 2e5b8cd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
8 changes: 4 additions & 4 deletions integrations/jira/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ resources:
status: .fields.status.name
issueType: .fields.issuetype.name
components: .fields.components
creator: .fields.creator.emailAddress
creator: .fields.creator.emailAddress // ""
priority: .fields.priority.name
labels: .fields.labels
created: .fields.created
updated: .fields.updated
resolutionDate: .fields.resolutiondate
resolutionDate: .fields.resolutiondate // ""
relations:
project: .fields.project.key
parentIssue: .fields.parent.key
parentIssue: .fields.parent.key // ""
subtasks: .fields.subtasks | map(.key)
assignee: .fields.assignee.accountId
assignee: .fields.assignee.accountId // ""
reporter: .fields.reporter.accountId
8 changes: 8 additions & 0 deletions integrations/jira/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

## 0.2.16 (2025-01-07)


### Features

- Added support for ingesting other fields apart from the default fields (Jira Sprint support)


## 0.2.15 (2025-01-07)


Expand Down
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
25 changes: 13 additions & 12 deletions integrations/jira/jira/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
ResourceConfig,
Selector,
)
from pydantic import BaseModel, Field
from pydantic import Field


class JiraResourceConfig(ResourceConfig):
class Selector(BaseModel):
query: str
jql: str | None = None
class JiraIssueSelector(Selector):
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 @@ -30,13 +34,10 @@ class JiraProjectResourceConfig(ResourceConfig):


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


class JiraPortAppConfig(PortAppConfig):
resources: list[JiraResourceConfig | JiraProjectResourceConfig] # type: ignore
resources: list[JiraIssueConfig | JiraProjectResourceConfig | ResourceConfig]
17 changes: 15 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,19 @@ 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}... Adding to request param"
)

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
2 changes: 1 addition & 1 deletion integrations/jira/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jira"
version = "0.2.15"
version = "0.2.16"
description = "Integration to bring information from Jira into Port"
authors = ["Mor Paz <mor@getport.io>"]

Expand Down

0 comments on commit 2e5b8cd

Please sign in to comment.