diff --git a/admyral/actions/integrations/cases/jira.py b/admyral/actions/integrations/cases/jira.py index 4922c296..ca4d8a28 100644 --- a/admyral/actions/integrations/cases/jira.py +++ b/admyral/actions/integrations/cases/jira.py @@ -8,6 +8,7 @@ from admyral.context import ctx from admyral.utils.collections import is_empty from admyral.secret.secret import register_secret +from admyral.exceptions import NonRetryableActionError @register_secret(secret_type="Jira") @@ -180,20 +181,38 @@ def update_jira_issue_status( description="The ID or the key of the issue", ), ], - transition_id: Annotated[ - str, + status: Annotated[ + str | None, ArgumentMetadata( - display_name="Transition ID", - description="The ID of the transition", + display_name="Status", + description="The status to set the issue to", ), ], ) -> None: # https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-post # https://community.atlassian.com/t5/Jira-questions/How-do-i-find-a-transition-ID/qaq-p/2113213 + # 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() + transitions = response.json() + transition_id = next( + ( + t["id"] + for t in transitions.get("transitions", []) + if t["name"].lower() == status.lower() + ), + None, + ) + if transition_id is None: + raise NonRetryableActionError( + f"Could not move the Jira issue into status {status} because there is no transition " + "into this status from the current status." + ) + response = client.post( f"/issue/{issue_id_or_key}/transitions", json={ @@ -359,7 +378,7 @@ def get_jira_audit_records( description="Get a Jira project", secrets_placeholders=["JIRA_SECRET"], ) -def get_project( +def get_jira_project( project_id_or_key: Annotated[ str, ArgumentMetadata( diff --git a/docs/pages/integrations/jira/apis/update_issue_status.mdx b/docs/pages/integrations/jira/apis/update_issue_status.mdx index 42ee42a4..f11b04cc 100644 --- a/docs/pages/integrations/jira/apis/update_issue_status.mdx +++ b/docs/pages/integrations/jira/apis/update_issue_status.mdx @@ -18,10 +18,10 @@ from admyral.actions import update_jira_issue_status ## Arguments: -| Arugment Name | Description | Required | -| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------: | -| **Issue ID or Key** `issue_id_or_key` | The ID or the key of the issue to transition. | Yes | -| **Transition ID** `transition_id` | The ID of the transition. See [here](https://community.atlassian.com/t5/Jira-questions/How-do-i-find-a-transition-ID/qaq-p/2113213) for finding the transition ID. | Yes | +| Arugment Name | Description | Required | +| ------------------------------------- | --------------------------------------------- | :------: | +| **Issue ID or Key** `issue_id_or_key` | The ID or the key of the issue to transition. | Yes | +| **Status** `status` | The status to set the issue to. | Yes | ## Returns @@ -38,7 +38,7 @@ Nothing. ```python update_jira_issue_status( issue_id_or_key="SJ-23", - transition_id="31", + status="31", secrets={ "JIRA_SECRET": "my_stored_jira_secret" }