Skip to content

fix: delete Bitbucket Server comments - #3376

Merged
IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
utsab345:fix/bitbucket-server-remove-comment
Sep 14, 2026
Merged

IsmaelMartinez merged 1 commit into
The-PR-Agent:mainfrom
utsab345:fix/bitbucket-server-remove-comment

Conversation

@utsab345

Copy link
Copy Markdown
Contributor

Summary

Implement comment deletion for the Bitbucket Server provider.

The provider now validates the comment ID and version, calls the Bitbucket Server client deletion API, and reports failures instead of silently doing nothing.

Tests

  • PYTHONPATH=. pytest tests/unittest/test_bitbucket_provider.py -q --color=no
  • ruff check pr_agent/git_providers/bitbucket_server_provider.py tests/unittest/test_bitbucket_provider.py
  • pre-commit run --files pr_agent/git_providers/bitbucket_server_provider.py tests/unittest/test_bitbucket_provider.py

The focused test suite passed with 98 tests.

Fixes #3375

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Delete Bitbucket Server comments through provider API

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Implement Bitbucket Server comment deletion using comment IDs and versions.
• Reject malformed comment metadata and report deletion failures.
• Cover successful deletion and missing-version validation.
Diagram

sequenceDiagram
    actor Caller
    participant Provider as Server Provider
    participant Client as Bitbucket Client
    participant Server as Bitbucket Server
    Caller->>Provider: Remove comment
    alt Invalid metadata
        Provider-->>Caller: False
    else Valid metadata
        Provider->>Client: Delete comment
        Client->>Server: DELETE comment
        Server-->>Client: Result
        alt Delete succeeds
            Client-->>Provider: Success
            Provider-->>Caller: True
        else Delete fails
            Client--xProvider: Exception
            Provider-->>Caller: False
        end
    end
Loading
High-Level Assessment

The current approach is appropriate: it uses the existing Bitbucket client abstraction, supplies the API-required optimistic-lock version, and preserves provider-level error handling. Direct REST calls or internal version lookups would add coupling and network overhead without improving this focused fix.

Files changed (2) +38 / -1

Bug fix (1) +20 / -1
bitbucket_server_provider.pyImplement validated Bitbucket Server comment deletion +20/-1

Implement validated Bitbucket Server comment deletion

• Extracts comment IDs and versions from mapping or object representations and rejects invalid metadata. Calls the Bitbucket client deletion API and returns explicit success or failure results while logging errors.

pr_agent/git_providers/bitbucket_server_provider.py

Tests (1) +18 / -0
test_bitbucket_provider.pyTest Bitbucket Server comment deletion behavior +18/-0

Test Bitbucket Server comment deletion behavior

• Verifies that valid comment metadata reaches the deletion client with repository and pull-request context. Confirms comments missing a version are rejected without invoking the API.

tests/unittest/test_bitbucket_provider.py

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Recently edited comments stay undeleted 🐞 Bug ☼ Reliability
Description
remove_comment sends the caller's stored comment_version and handles every deletion exception as
a final failure instead of refreshing the version on a conflict. If the comment is edited after it
was fetched—or the provider's own edit_comment is called on that object—the version becomes stale
and cleanup returns False without retrying the deletion.
Code

pr_agent/git_providers/bitbucket_server_provider.py[R431-433]

+        except Exception as e:
+            get_logger().exception(f"Failed to remove comment, error: {e}")
+            return False
Evidence
Deletion explicitly supplies the stored version, while the adjacent edit implementation establishes
that Bitbucket Server rejects stale comment versions with HTTP 409 and must be retried using the
version returned by get_pull_request_comment. edit_comment does not update the passed object's
version after a successful edit, and the shared persistent-comment flow returns that same object,
providing a repository-visible way for a later deletion to receive a stale version.

pr_agent/git_providers/bitbucket_server_provider.py[363-399]
pr_agent/git_providers/bitbucket_server_provider.py[422-433]
pr_agent/git_providers/git_provider.py[682-716]
tests/unittest/test_bitbucket_provider.py[935-947]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Bitbucket Server comment deletion requires the current comment version, but `remove_comment` treats a stale-version conflict as a final failure. The provider already refreshes the version and retries when the same conflict occurs during comment editing.
## Fix Focus Areas
- pr_agent/git_providers/bitbucket_server_provider.py[422-433]
- pr_agent/git_providers/bitbucket_server_provider.py[374-399]
## Recommended Fix
Handle an `HTTPError` with status 409 separately in `remove_comment`: fetch the current comment using `get_pull_request_comment`, validate its returned version, and retry deletion once with that version. Preserve the existing logging and `False` return for refresh failures and all non-conflict exceptions, and add tests covering successful conflict recovery and an invalid refreshed version.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for wiring remove_comment to delete_pull_request_comment with the version parameter, plus the two tests. Deletion holds; a 404 is logged and swallowed like the GitHub and GitLab providers, and both tests go red on revert. Approving.

For the record, not an ask: publish_comment(is_temporary=True) returns None on this provider and temp_comments stays empty, so no tool reaches remove_comment yet. Showing the progress comment on Bitbucket Server is the natural follow-up now that deletion exists.

@IsmaelMartinez
IsmaelMartinez merged commit b06126f into The-PR-Agent:main Sep 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bitbucket Server remove_comment silently does nothing

2 participants