atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 643 forks source link

query parameter not supported on Pipelines.each() #1248

Open m0nt3cr1st0 opened 9 months ago

m0nt3cr1st0 commented 9 months ago

Hi,

I'm trying to use the q parameter to filter the list of pipelines that Pipelines.each() generates but that doesn't seem to work:

p = r.pipelines.each(q="target.ref_name=\"master\"", sort="-created_on")
>>> print(next(p))
{   'build_number': 401,
    'build_seconds_used': 193,
    'completed_on': '2023-09-07T06:32:41.924947Z',
    'created_on': '2023-09-07T06:29:17.922672Z',
     ...
    'target': {
     ...
                  'ref_name': 'feature/XXXXX,
                  'ref_type': 'branch',
                  'selector': {'type': 'default'},
                  'type': 'pipeline_ref_target'},
}

Did someone experience something similar? On the Atlassian docs, it is not clarified if the pipelines endpoint supports query filtering or not. I can confirm that the sort parameter works as a charm.

Spacetown commented 9 months ago

Can you check with debugging active if the data is send correct in the request?

m0nt3cr1st0 commented 9 months ago

Good question, I would say it is not. From the Atlassian docs, I can see that they add a + symbol between each URL:

Atlassian Docs: /2.0/repositories/{username}/{slug}/refs/tags?q=name+%7E+%222015%22 Debugger output for my request: /2.0/repositories/XXXXXX/XXXXX/pipelines/?sort=-created_on&q=target.ref_name%3D%22master%22&page=1

Full output:

>>> p = r.pipelines.each(q="target.ref_name=\"master\"", sort="-created_on")
>>> next(p)
[2023-09-16 12:50:08] [DEBUG] curl --silent -X GET -H 'Content-Type: application/json' -H 'Accept: application/json'  'https://api.bitbucket.org/2.0/repositories/XXX/XX/pipelines/?sort=-created_on&q=target.ref_name%3D%22master%22&page=1'
[2023-09-16 12:50:08] [DEBUG] Resetting dropped connection: api.bitbucket.org
[2023-09-16 12:50:09] [DEBUG] https://api.bitbucket.org:443 "GET /2.0/repositories/XXXX/XXXX/pipelines/?sort=-created_on&q=target.ref_name%3D%22master%22&page=1 HTTP/1.1" 200 None
...
>>> print(next(p))
{   'build_number': 401,
    'build_seconds_used': 193,
    'completed_on': '2023-09-07T06:32:41.924947Z',
    'created_on': '2023-09-07T06:29:17.922672Z',
     ...
    'target': {
     ...
                  'ref_name': 'feature/XXXXX,
                  'ref_type': 'branch',
                  'selector': {'type': 'default'},
                  'type': 'pipeline_ref_target'},
}
m0nt3cr1st0 commented 9 months ago

Out of curiosity I tested a similar request directly with CURL and it seems that the problem is that the repositories endpoint of Atlassian's API completely ignores the query parameter:

grubio@grubio-XPS-13-9360:~$ curl -u XXXX:XXXXX -X GET -H 'Content-Type: application/json' -H 'Accept: application/json'  'https://api.bitbucket.org/2.0/repositories/XXXXX/XXXXX/pipelines/?sort=-created_on&q=build_number+%3D+401&page=1'

{"page": 1, "values": [{"uuid": "{08fb8516-cd79-43e0-ac69-7600376bbafb}", "repository": {"type": "repository", "full_name": "XXXX/XXXXX", "links": {"self": {"href": "https://api.bitbucket.org/2.0/XXXX/XXXX/database"}, "state": {"name": "COMPLETED", "type": "pipeline_state_completed", "result": {"name": "SUCCESSFUL", "type": "pipeline_state_completed_successful"}}, "build_number": 402, 
...
}

Can you confirm that it doesn't work for you either? Then maybe we should contact Atlassian directly

Spacetown commented 9 months ago

Sorry, I can't che3ck this because I'm not using a cloud instance.