Skip to content
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

Fix bitbucket publish description #302

Closed
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
14 changes: 12 additions & 2 deletions pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import re
from typing import Optional, Tuple
from urllib.parse import urlparse

Expand Down Expand Up @@ -246,12 +247,21 @@ def get_commit_messages(self):
return "" # not implemented yet

# bitbucket does not support labels
def publish_description(self, pr_title: str, description: str):
def publish_description(self, pr_title: str, pr_body: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Proposed documentation

Suggested change
def publish_description(self, pr_title: str, pr_body: str):
"""
This method updates the description and title of a pull request in Bitbucket.
:param pr_title: The title of the pull request
:type pr_title: str
:param pr_body: The body of the pull request
:type pr_body: str
:return: The response from the Bitbucket API
:rtype: requests.Response
"""
def publish_description(self, pr_title: str, pr_body: str):

pattern = r"## PR Description:\s*(.*?)\n___"
match = re.search(pattern, pr_body, re.DOTALL)
okotek marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +251 to +252
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Handle the case where pr_body is None or empty, to avoid errors when trying to apply the regex.

Suggested change
pattern = r"## PR Description:\s*(.*?)\n___"
match = re.search(pattern, pr_body, re.DOTALL)
description = ""
if pr_body:
pattern = r"## PR Description:\s*(.*?)\n___"
match = re.search(pattern, pr_body, re.DOTALL)
if match:
pr_description = match.group(1).strip()
if pr_description:
description = pr_description

description = ""

if match:
pr_description = match.group(1).strip()
if pr_description:
description = pr_description

payload = json.dumps({
"description": description,
"title": pr_title

Comment on lines 260 to 263
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a check to ensure that pr_title is not None or empty before using it in the payload.

Suggested change
payload = json.dumps({
"description": description,
"title": pr_title
if pr_title:
payload = json.dumps({
"description": description,
"title": pr_title
})
else:
logging.error('PR title is empty')
return None

})
})

response = requests.request("PUT", self.bitbucket_pull_request_api_url, headers=self.headers, data=payload)
return response
Comment on lines 266 to 267
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Handle the case where the request to the bitbucket_pull_request_api_url fails.

Suggested change
response = requests.request("PUT", self.bitbucket_pull_request_api_url, headers=self.headers, data=payload)
return response
response = requests.request("PUT", self.bitbucket_pull_request_api_url, headers=self.headers, data=payload)
if response.status_code != 200:
logging.error('Failed to update PR description: %s', response.text)
return response

Expand Down
Loading