From 165286b4c292f269b8e60034955f56c4b0f45933 Mon Sep 17 00:00:00 2001 From: Sky Moore Date: Sat, 1 Apr 2023 20:08:58 -0500 Subject: [PATCH] feat: label and unlabel issues (#1147) --- atlassian/jira.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/atlassian/jira.py b/atlassian/jira.py index b82a0a4d7..83af2c4cc 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -1191,6 +1191,33 @@ def get_issue_labels(self, issue_key): return self.get(url) return (self.get(url) or {}).get("fields").get("labels") + def update_issue(self, issue_key, update): + """ + :param issue: the issue to update + :param update: the update to make + :return: True if successful, False if not + """ + endpoint = "/rest/api/2/issue/{issue_key}".format(issue_key=issue_key) + return self.put(endpoint, data=update) + + def label_issue(self, issue_key, labels): + """ + :param issue: the issue to update + :param labels: the labels to add + :return: True if successful, False if not + """ + labels = [{"add": label} for label in labels] + return self.update_issue(issue_key, {"update": {"labels": labels}}) + + def unlabel_issue(self, issue_key, labels): + """ + :param issue: the issue to update + :param labels: the labels to remove + :return: True if successful, False if not + """ + labels = [{"remove": label} for label in labels] + return self.update_issue(issue_key, {"update": {"labels": labels}}) + def add_attachment(self, issue_key, filename): """ Add attachment to Issue