Skip to content

[BitBucket Cloud] PullRequests.comments property does not properly handle query parameters #1100

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
markarce opened this issue Dec 16, 2022 · 0 comments · Fixed by #1101
Closed

Comments

@markarce
Copy link
Contributor

markarce commented Dec 16, 2022

When using _get_paged with the pullrequest.comments property, query parameters are not supported.

Desired query: https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPOSITORY/pullrequests/PR_ID/comments?q=deleted=false
Actual query: https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPOSITORY/pullrequests/PR_ID/comments

Desired result: All Comment objects where deleted == False
Actual result: All Comment objects.

Steps to reproduce:

# set up initial state

cloud = Cloud(username=USERNAME, password=APP_PASSWORD, cloud=True)
workspace = cloud.workspaces.get(WORKSPACE)
repository = cloud.repositories.get(WORKSPACE, REPOSITORY)
pull_request = repository.pullrequests.get(id=PULL_REQUEST_ID)

# add 6 comments to target PR, delete 3 comments

(steps TBA; I did this manually inside the PR)

# call the original function and save the result

comments = list(pull_request.comments())

# print status of found comments. Should be mix of "True" and "False," 3 of each

[print(comment.data["deleted"]) for comment in comments]
True
True
True
False
False
False

### adding the feature and verifying functionality

# patch atlassian.bitbucket.cloud.repositories.pullRequests.PullRequest:comments to properly handle query parameters
# code changes follow the implementation of PullRequests.each, which already supports a query string

def comments(q=None):
    params = {}
    if q is not None:
        params["q"] = q
    for comment in pull_request._get_paged("comments", params=params):
        yield Comment(comment, **pull_request._new_session_args)

# reimport module and run the same function again, passing in a value for q:

comments = list(pull_request.comments(q="deleted=false"))

# Final output:

[print(comment.data["deleted"]) for comment in comments]
False
False
False
@markarce markarce changed the title AtlassianRestAPI: request.get does not properly handle query parameters [BitBucket Cloud] PullRequests.comments property does not properly handle query parameters Dec 17, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
1 participant