diff --git a/atlassian/bitbucket/__init__.py b/atlassian/bitbucket/__init__.py index 016c2a357..c7f8b3e6f 100644 --- a/atlassian/bitbucket/__init__.py +++ b/atlassian/bitbucket/__init__.py @@ -1056,7 +1056,7 @@ def repo_users_with_administrator_permissions(self, project_key, repo_key): repo_administrators = [] for user in self.repo_users(project_key, repo_key): if user["permission"] == "REPO_ADMIN": - repo_administrators.append(user['user']) + repo_administrators.append(user["user"]) for group in self.repo_groups_with_administrator_permissions(project_key, repo_key): for user in self.group_members(group): repo_administrators.append(user) diff --git a/atlassian/jira.py b/atlassian/jira.py index a87beb531..c44239dae 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -1971,6 +1971,28 @@ def issue_edit_comment( params: dict = {"notifyUsers": "true" if notify_users else "false"} return self.put(url, data=data, params=params) + def issue_pin_comment(self, issue_key: str, comment_id: T_id) -> T_resp_json: + """ + Pin a comment on a Jira issue + :param issue_key: str + :param comment_id: int or str + :return: + """ + base_url = self.resource_url("issue") + url = f"{base_url}/{issue_key}/comment/{comment_id}/pin" + return self.put(url, data=True) + + def issue_unpin_comment(self, issue_key: str, comment_id: T_id) -> T_resp_json: + """ + Unpin a comment on a Jira issue + :param issue_key: str + :param comment_id: int or str + :return: + """ + base_url = self.resource_url("issue") + url = f"{base_url}/{issue_key}/comment/{comment_id}/pin" + return self.put(url, data=False) + def scrap_regex_from_issue(self, issue: str, regex: str): """ This function scrapes the output of the given regex matches from the issue's description and comments. diff --git a/atlassian/models/jira/issues.py b/atlassian/models/jira/issues.py index 9efdf7d3d..1f43b70ec 100644 --- a/atlassian/models/jira/issues.py +++ b/atlassian/models/jira/issues.py @@ -5,7 +5,6 @@ from atlassian.models.jira.fields import IssueFields, IssueType - _ISSUE_TYPE_REGISTRY: dict[str, type[JiraIssue]] = {} diff --git a/atlassian/rest_client.py b/atlassian/rest_client.py index 834cb43d1..388cdea81 100644 --- a/atlassian/rest_client.py +++ b/atlassian/rest_client.py @@ -470,7 +470,7 @@ def request( url += ("&" if params or params_already_in_url else "") + "&".join(flags or []) json_dump = None if files is None: - data = None if not data else dumps(data) + data = None if data is None else dumps(data) json_dump = None if not json else dumps(json) headers = headers or self.default_headers diff --git a/atlassian/utils.py b/atlassian/utils.py index 24a479993..631d0111d 100644 --- a/atlassian/utils.py +++ b/atlassian/utils.py @@ -213,14 +213,12 @@ def block_code_macro_confluence(code, lang=None): """ if not lang: lang = "" - return ( - """\ + return ("""\ {lang} - """ - ).format(lang=lang, code=code) + """).format(lang=lang, code=code) def html_code__macro_confluence(text): @@ -229,13 +227,11 @@ def html_code__macro_confluence(text): :param text: :return: """ - return ( - """\ + return ("""\ - """ - ).format(text=text) + """).format(text=text) def noformat_code_macro_confluence(text, nopanel=None): @@ -247,14 +243,12 @@ def noformat_code_macro_confluence(text, nopanel=None): """ if not nopanel: nopanel = False - return ( - """\ + return ("""\ {nopanel} - """ - ).format(nopanel=nopanel, text=text) + """).format(nopanel=nopanel, text=text) def symbol_normalizer(text): diff --git a/examples/jira/jira_admins_confluence_page.py b/examples/jira/jira_admins_confluence_page.py index 5703ad0d0..0232cf1ae 100644 --- a/examples/jira/jira_admins_confluence_page.py +++ b/examples/jira/jira_admins_confluence_page.py @@ -12,15 +12,13 @@ confluence = Confluence(url="http://localhost:8090", username="admin", password="admin") -html = [ - """ +html = ["""
- """ -] + """] for data in jira.project_leaders(): log.info("{project_key} leader is {lead_name} <{lead_email}>".format(**data)) diff --git a/examples/jira/jira_project_administrators.py b/examples/jira/jira_project_administrators.py index de3af90e8..a25b248dc 100644 --- a/examples/jira/jira_project_administrators.py +++ b/examples/jira/jira_project_administrators.py @@ -17,9 +17,7 @@ - """.format( - **data - ) + """.format(**data) html += "
Project Key Project Name Leader Email
{project_name} {lead_name} {lead_email}
" diff --git a/examples/jira/jira_project_leaders.py b/examples/jira/jira_project_leaders.py index 4fdff24a4..709fcc61c 100644 --- a/examples/jira/jira_project_leaders.py +++ b/examples/jira/jira_project_leaders.py @@ -7,8 +7,7 @@ jira = Jira(url="http://localhost:8080", username="admin", password="admin") EMAIL_SUBJECT = quote("Jira access to project {project_key}") -EMAIL_BODY = quote( - """I am asking for access to the {project_key} project in Jira. +EMAIL_BODY = quote("""I am asking for access to the {project_key} project in Jira. To give me the appropriate permissions, assign me to a role on the page: http://localhost:8080/plugins/servlet/project-config/{project_key}/roles @@ -16,8 +15,7 @@ Role: Users - read-only access + commenting Developers - work on tasks, editing, etc. -Admin - Change of configuration and the possibility of starting sprints""" -) +Admin - Change of configuration and the possibility of starting sprints""") MAILTO = '{lead_name}' diff --git a/tests/responses/jira/rest/api/2/issue/FOO-123/comment/10000/pin/PUT b/tests/responses/jira/rest/api/2/issue/FOO-123/comment/10000/pin/PUT new file mode 100644 index 000000000..23048b12d --- /dev/null +++ b/tests/responses/jira/rest/api/2/issue/FOO-123/comment/10000/pin/PUT @@ -0,0 +1,2 @@ +responses['true'] = {} +responses['false'] = {} diff --git a/tests/test_jira.py b/tests/test_jira.py index 64f7a4c73..1bd1e5e7c 100644 --- a/tests/test_jira.py +++ b/tests/test_jira.py @@ -46,6 +46,14 @@ def test_get_issue_comment_not_found(self): with self.assertRaises(HTTPError): self.jira.epic_issues("BAR-11") + def test_pin_issue_comment(self): + """Can pin a comment on an issue""" + self.jira.issue_pin_comment("FOO-123", 10000) + + def test_unpin_issue_comment(self): + """Can unpin a comment on an issue""" + self.jira.issue_unpin_comment("FOO-123", 10000) + def test_post_issue_with_invalid_request(self): """Post an issue but receive a 400 error response""" with self.assertRaises(HTTPError):