From 84ebceda9e01333d6e25da255335ba056e18b469 Mon Sep 17 00:00:00 2001 From: Daniel Grittner Date: Fri, 8 Nov 2024 16:32:19 +0100 Subject: [PATCH] feat: add get Jira issue transitions action --- admyral/actions/__init__.py | 4 ++ .../actions/integrations/cases/__init__.py | 4 ++ admyral/actions/integrations/cases/jira.py | 25 +++++++++++ .../jira/apis/get_transitions.mdx | 41 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 docs/pages/integrations/jira/apis/get_transitions.mdx diff --git a/admyral/actions/__init__.py b/admyral/actions/__init__.py index dbe6aa83..22e38286 100644 --- a/admyral/actions/__init__.py +++ b/admyral/actions/__init__.py @@ -40,6 +40,8 @@ get_jira_audit_records, create_opsgenie_alert, create_pagerduty_incident, + get_jira_project, + get_jira_transitions, ) from admyral.actions.integrations.vulnerability_management import ( list_snyk_vulnerabilities, @@ -189,4 +191,6 @@ "list_groups_and_apps_per_user", "list_used_groups_and_apps_per_user", "list_google_drive_files_with_link_sharing_enabled", + "get_jira_project", + "get_jira_transitions", ] diff --git a/admyral/actions/integrations/cases/__init__.py b/admyral/actions/integrations/cases/__init__.py index 9160b358..21ab69fa 100644 --- a/admyral/actions/integrations/cases/__init__.py +++ b/admyral/actions/integrations/cases/__init__.py @@ -4,6 +4,8 @@ comment_jira_issue_status, search_jira_issues, get_jira_audit_records, + get_jira_project, + get_jira_transitions, ) from admyral.actions.integrations.cases.opsgenie import create_opsgenie_alert from admyral.actions.integrations.cases.pagerduty import create_pagerduty_incident @@ -16,4 +18,6 @@ "get_jira_audit_records", "create_opsgenie_alert", "create_pagerduty_incident", + "get_jira_project", + "get_jira_transitions", ] diff --git a/admyral/actions/integrations/cases/jira.py b/admyral/actions/integrations/cases/jira.py index 66ca9606..4922c296 100644 --- a/admyral/actions/integrations/cases/jira.py +++ b/admyral/actions/integrations/cases/jira.py @@ -376,3 +376,28 @@ def get_project( response = client.get(f"/project/{project_id_or_key}") response.raise_for_status() return response.json() + + +@action( + display_name="Get Transitions", + display_namespace="Jira", + description="Get a Jira transition", + secrets_placeholders=["JIRA_SECRET"], +) +def get_jira_transitions( + issue_id_or_key: Annotated[ + str, + ArgumentMetadata( + display_name="Issue ID or Key", + description="The ID or the key of the issue", + ), + ], +) -> list[dict[str, JsonValue]]: + # https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-get + secret = ctx.get().secrets.get("JIRA_SECRET") + secret = JiraSecret.model_validate(secret) + + with get_jira_client(secret) as client: + response = client.get(f"/issue/{issue_id_or_key}/transitions") + response.raise_for_status() + return response.json() diff --git a/docs/pages/integrations/jira/apis/get_transitions.mdx b/docs/pages/integrations/jira/apis/get_transitions.mdx new file mode 100644 index 00000000..793e1ac9 --- /dev/null +++ b/docs/pages/integrations/jira/apis/get_transitions.mdx @@ -0,0 +1,41 @@ +import { Callout } from "nextra/components"; + +# Get Transitions + +Get transitions for a Jira issue. **This is useful for updating the issue status.** + + + For more information on the API, see [Get + Transitions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-get). + + +**SDK Import:** + +```python +from admyral.actions import get_jira_transitions +``` + +## Arguments: + +| Argument Name | Description | Required | +| ------------------------------------- | ------------------------------- | :------: | +| **Issue ID or Key** `issue_id_or_key` | The ID or the key of the issue. | Yes | + +## Returns + +A JSON object. + +## Required Secrets + +| Secret Placeholder | Description | +| ------------------ | ------------------------------------------------------ | +| `JIRA_SECRET` | Jira secret. See [Jira setup](/integrations/jira/jira) | + +## SDK Example + +```python +get_jira_transitions( + issue_id_or_key="SJ-1", + secrets={"JIRA_SECRET": "my_stored_jira_secret"} +) +```