Skip to content

JIRA issue properties #1292

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

Merged
merged 7 commits into from
Jan 17, 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
32 changes: 32 additions & 0 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,38 @@ def get_issue_transitions_full(self, issue_key, transition_id=None, expand=None)
params["expand"] = expand
return self.get(url, params=params)

def get_issue_property_keys(self, issue_key):
"""
Get Property Keys on an Issue.
:param issue_key: Issue KEY
:raises: requests.exceptions.HTTPError
:return:
"""
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}/properties".format(base_url=base_url, issue_key=issue_key)
return self.get(url)

def set_issue_property(self, issue_key, property_key, data):
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
base_url=base_url, issue_key=issue_key, propertyKey=property_key
)
return self.put(url, data=data)

def get_issue_property(self, issue_key, property_key):
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
base_url=base_url, issue_key=issue_key, propertyKey=property_key
)
return self.get(url)

def delete_issue_property(self, issue_key, property_key):
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
base_url=base_url, issue_key=issue_key, propertyKey=property_key
)
return self.delete(url)

def get_updated_worklogs(self, since, expand=None):
"""
Returns a list of IDs and update timestamps for worklogs updated after a date and time.
Expand Down
14 changes: 14 additions & 0 deletions docs/jira.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ Manage issues
# Get change history for an issue
jira.get_issue_changelog(issue_key)

# Get property keys from an issue
jira.get_issue_property_keys(issue_key)

# Set issue property
data = { "Foo": "Bar" }
jira.set_issue_property(issue_key, property_key, data)

# Get issue property
jira.get_issue_property(issue_key, property_key)

# Delete issue property
jira.delete_issue_property(issue_key, property_key)

# Get worklog for an issue
jira.issue_get_worklog(issue_key)

Expand All @@ -339,6 +352,7 @@ Manage issues
jira.issue_worklog(issue_key, started, time_in_sec)



Epic Issues
-------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
responses[None] = {
"status_code": 204
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
responses[None] = {"key": "Bar1", "value": {"test.id": "123", "test.time": "1m"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
responses['{"test.id": "123456", "test.mem": "250M"}'] = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
responses['{"test.id": "123456", "test.mem": "250M"}'] = {}
3 changes: 3 additions & 0 deletions tests/responses/jira/rest/api/2/issue/FOO-123/properties/GET
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
responses[None] = {
"keys": [{"key": "Bar1", "self": "https://sample.atlassian.net/rest/api/2/issue/FOO-123/properties/Bar1"}]
}
38 changes: 38 additions & 0 deletions tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,41 @@ def test_post_issue_expect_failed_authentication(self):
"""Post an issue but receive a 401 error response"""
with self.assertRaises(HTTPError):
self.jira.create_issue(fields={"issuetype": "fail", "summary": "authentication", "project": "project"})

def test_get_issue_property_keys(self):
"""Can retrieve issue property keys"""
resp = self.jira.get_issue_property_keys("FOO-123")
self.assertEqual(resp["keys"][0]["key"], "Bar1")
self.assertEqual(
resp["keys"][0]["self"], "https://sample.atlassian.net/rest/api/2/issue/FOO-123/properties/Bar1"
)

def test_get_issue_property_keys_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property_keys("BAR-11")

def test_set_issue_property_create(self):
self.jira.set_issue_property("FOO-123", "Bar2New", data={"test.id": "123456", "test.mem": "250M"})

def test_set_issue_property_update(self):
self.jira.set_issue_property("FOO-123", "Bar1", data={"test.id": "123456", "test.mem": "250M"})

def test_get_issue_property(self):
resp = self.jira.get_issue_property("FOO-123", "Bar1")
self.assertEqual(resp["value"]["test.id"], "123")
self.assertEqual(resp["value"]["test.time"], "1m")

def test_get_issue_property_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")

def test_delete_issue_property(self):
self.jira.delete_issue_property("FOO-123", "Bar1")

def test_delete_issue_property_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")