Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Integration][Jira] Add totalIssues field to project kind #1266

Merged
merged 9 commits into from
Dec 24, 2024
Merged
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
5 changes: 5 additions & 0 deletions integrations/jira/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"type": "string",
"format": "url",
"description": "URL to the project in Jira"
},
"totalIssues": {
"title": "Total Issues",
"type": "number",
"description": "The total number of issues in the project"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions integrations/jira/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resources:
blueprint: '"jiraProject"'
properties:
url: (.self | split("/") | .[:3] | join("/")) + "/projects/" + .key
totalIssues: .insight.totalIssueCount

- kind: user
selector:
Expand Down
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.8 (2024-12-24)


### Features

- Added a field to display total issues in a project


## 0.2.7 (2024-12-24)


Expand Down
10 changes: 5 additions & 5 deletions integrations/jira/jira/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import typing
from typing import Any, AsyncGenerator, Generator

from httpx import Timeout, Auth, BasicAuth, Request, Response
from jira.overrides import JiraResourceConfig
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 @@ -117,11 +117,11 @@ async def get_single_project(self, project_key: str) -> dict[str, Any]:
return project_response.json()

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

params = self._generate_base_req_params()
params.update(self._generate_base_req_params())

total_projects = (await self._get_paginated_projects(params))["total"]

Expand Down
29 changes: 27 additions & 2 deletions integrations/jira/jira/overrides.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Annotated, Literal, Union

from port_ocean.core.handlers.port_app_config.models import (
PortAppConfig,
ResourceConfig,
Selector,
)
from pydantic import BaseModel
from pydantic import BaseModel, Field


class JiraResourceConfig(ResourceConfig):
Expand All @@ -11,7 +14,29 @@ class Selector(BaseModel):
jql: str | None = None

selector: Selector # type: ignore
kind: Literal["issue", "user"]


class JiraProjectSelector(Selector):
expand: str = Field(
description="A comma-separated list of the parameters to expand.",
default="insight",
)


class JiraProjectResourceConfig(ResourceConfig):
selector: JiraProjectSelector
kind: Literal["project"]


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


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

from jira.client import JiraClient
from loguru import logger
from port_ocean.context.event import event
from port_ocean.context.ocean import ocean
from port_ocean.core.ocean_types import ASYNC_GENERATOR_RESYNC_TYPE

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


class ObjectKind(StrEnum):
PROJECT = "project"
Expand Down Expand Up @@ -42,7 +45,10 @@ async def on_resync_projects(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
ocean.integration_config["atlassian_user_token"],
)

async for projects in client.get_paginated_projects():
selector = cast(JiraProjectResourceConfig, event.resource_config).selector
params = {"expand": selector.expand}

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

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.7"
version = "0.2.8"
description = "Integration to bring information from Jira into Port"
authors = ["Mor Paz <[email protected]>"]

Expand Down
Loading