Skip to content

Commit f6e38c3

Browse files
committed
Jira: Add workflow association for projects
1 parent eb4f5b7 commit f6e38c3

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

atlassian/jira/jira_cloud.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ def enhanced_jql_get_list_of_tickets(
9494
break
9595
return results
9696

97+
def get_project_workflow_scheme_associations(self, project_ids):
98+
"""Return workflow-scheme associations for one or more project IDs.
99+
100+
Team-managed and non-existent projects are omitted by Jira Cloud. The
101+
caller requires the Administer Jira global permission.
102+
103+
:param project_ids: Project ID or iterable of project IDs.
104+
:return: Jira's workflow-scheme association container.
105+
"""
106+
if isinstance(project_ids, (str, int)):
107+
project_ids = [project_ids]
108+
else:
109+
project_ids = list(project_ids)
110+
if not project_ids:
111+
raise ValueError("project_ids must contain at least one project ID")
112+
return self.get(self.endpoint("workflowscheme/project", api_version=3), params={"projectId": project_ids})
113+
114+
def assign_project_workflow_scheme(self, project_id, workflow_scheme_id):
115+
"""Assign a workflow scheme to a classic Jira Cloud project.
116+
117+
Jira only permits this operation when the project has no issues. The
118+
caller requires the Administer Jira global permission.
119+
120+
:param project_id: Numeric Jira project ID.
121+
:param workflow_scheme_id: Workflow scheme ID.
122+
:return: Jira response (normally ``None`` for HTTP 204).
123+
"""
124+
data = {"projectId": str(project_id), "workflowSchemeId": str(workflow_scheme_id)}
125+
return self.put(self.endpoint("workflowscheme/project", api_version=3), data=data)
126+
97127

98128
class JiraSoftware(JiraSoftwareMethods, AtlassianRestAPI):
99129
"""Jira Software Cloud REST APIs.

docs/jira_cloud.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,18 @@ Core generated operations use the selected ``JiraCloud(api_version=2|3)``
105105
version in their route. Existing snake_case ``Jira`` and ``ServiceDesk``
106106
methods retain their endpoint selection and behavior; they are neither renamed
107107
nor overwritten by the generated Cloud surface.
108+
Workflow scheme project associations
109+
------------------------------------
110+
111+
Use :class:`atlassian.jira.JiraCloud` to inspect or assign classic-project
112+
workflow schemes. Team-managed projects are not returned by Jira for this
113+
endpoint. Both operations require the Administer Jira global permission.
114+
115+
.. code-block:: python
116+
117+
from atlassian.jira import JiraCloud
118+
119+
jira = JiraCloud("https://your-domain.atlassian.net", username=email, password=api_token)
120+
121+
associations = jira.get_project_workflow_scheme_associations(["10001", "10002"])
122+
jira.assign_project_workflow_scheme(project_id="10001", workflow_scheme_id="10032")

tests/test_jira_cloud_clients.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ def test_legacy_clients_keep_their_defaults(self):
1616
self.assertIs(Jira, JiraServer)
1717
self.assertIs(PackageJira, JiraServer)
1818

19+
def test_jira_cloud_workflow_scheme_association_helpers_use_v3(self):
20+
jira = JiraCloud("https://example.atlassian.net")
21+
22+
with patch.object(jira, "get", return_value={"values": []}) as get:
23+
result = jira.get_project_workflow_scheme_associations(["10001", 10002])
24+
25+
self.assertEqual(result, {"values": []})
26+
get.assert_called_once_with("rest/api/3/workflowscheme/project", params={"projectId": ["10001", 10002]})
27+
28+
with patch.object(jira, "put", return_value=None) as put:
29+
jira.assign_project_workflow_scheme("10001", 10032)
30+
31+
put.assert_called_once_with(
32+
"rest/api/3/workflowscheme/project", data={"projectId": "10001", "workflowSchemeId": "10032"}
33+
)
34+
1935
def test_core_client_defaults_to_v3_and_forces_cloud_mode(self):
2036
jira = JiraCloud("https://example.atlassian.net", cloud=False)
2137

0 commit comments

Comments
 (0)