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

Conversation

sarbjitsinghgrewal
Copy link
Contributor

To resolve this issue, I've implemented a regular expression (regex) to extract the description from the entire body sent by the pr_description. As a result, both the description and title for pull requests are now being updated correctly.
here is the screenshot:
image

@coditamar
Copy link
Contributor

/improve --pr_code_suggestions.extra_instructions="focus on improving the robustness of the changes and managing with edge cases"

pr_agent/git_providers/bitbucket_provider.py Show resolved Hide resolved
Comment on lines 266 to 267
response = requests.request("PUT", self.bitbucket_pull_request_api_url, headers=self.headers, data=payload)
return response
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

Comment on lines +251 to +252
pattern = r"## PR Description:\s*(.*?)\n___"
match = re.search(pattern, pr_body, re.DOTALL)
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

Comment on lines 260 to 263
payload = json.dumps({
"description": description,
"title": pr_title

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

@hussam789
Copy link
Collaborator

/add_docs

@@ -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):

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Fixing the issue of incorrect pull request description update in Bitbucket.
  • 📝 PR summary: This PR addresses the issue of incorrect pull request description update in Bitbucket. The contributor has implemented a regular expression to extract the description from the entire body sent by the pr_description. As a result, both the description and title for pull requests are now being updated correctly.
  • 📌 Type of PR: Bug fix
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 2, because the changes are not complex and are limited to a single function.
  • 🔒 Security concerns: No

PR Feedback

  • 💡 General suggestions: The PR seems to be solving the issue at hand effectively. However, it would be better to handle the case where the regular expression does not match any string in the pr_body. Also, consider adding tests to ensure the functionality works as expected.

  • 🤖 Code feedback:

How to use

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants