Skip to content

Commit

Permalink
feat: improve jira update issue status action
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrittner committed Nov 8, 2024
1 parent 78038a5 commit 9e938bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
29 changes: 24 additions & 5 deletions admyral/actions/integrations/cases/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/integrations/jira/apis/update_issue_status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
}
Expand Down

0 comments on commit 9e938bb

Please sign in to comment.