Can't paginate Pipelines

Issue #75 on hold
Michael Delle created an issue

This is also an issue I'll bring up on Bitbucket.

Bitbuckets API response doesn't return "next" when getting pipelines, even though their documentation says it does.

Bitbucket endpoint: https://api.bitbucket.org/2.0/repositories/<account>/<repo>/pipelines/

I have 435 builds, it's returning the first 10. If I add "?page=44" to the end of the URL, then it returns the last 5.

There is no "next" or "previous" in the response. This also means Pager doesn't work.

Proposed Solution: Add the page param to the URL: https://bitbucket.org/gentlero/bitbucket-api/src/8aa84ffbe0846da6a05fc89cdfbc159c622e9a4e/lib/Bitbucket/API/Repositories/Pipelines.php?at=develop&fileviewer=file-view-default#Pipelines.php-35

By adding this I can then add some logic to determine what the last page number will be.

Comments (3)

  1. Alexandru Guzinschi

    ref BB-16511

    As long as the documentation says that those params should exists, we can safely assume that there is a bug in the API server, so I would not yet make any changes to the library.

    I will leave this issue on-hold until the upstream ticket receives some feedback from BB team.

  2. Michael Delle reporter

    Sounds good. Thanks for adding the reference. I meant to add that.

    Temporary Solution: I am saving the Uuid from the response after triggering a pipeline to a local file (up to 10 Uuid's).

    I loop through the list of Uuid and run stopPipeline()

        $file = '.triggered_pipelines.txt';
    
        # Get array of triggered pipelines from file.
        $triggeredPipelines = (array)json_decode(utf8_encode(file_get_contents($file)), true);
    
        if (!empty($triggeredPipelines)) {
            # If there are more then 10 triggered pipelines, remove the oldest one.
            if (count($triggeredPipelines) >= 10) {
                array_pop($triggeredPipelines);
            }
    
            # Stop the last 10 pipelines.
            foreach ($triggeredPipelines as $triggeredPipelineUuid) {
                $pipelines->stopPipeline($payload->account, $payload->repo, $triggeredPipelineUuid);
            }
        }
    
        $pipelinesUuid = json_decode($pipelines->create($payload->account, $payload->repo, $params)->getContent())->uuid;
    
        # Add current triggered pipeline to the list of triggered pipelines.
        array_unshift($triggeredPipelines, $pipelinesUuid);
    
        # Add new list of triggered pipelines to file.
        #   Throw Sentry error if writing to file failed.
        if (!file_put_contents($file, json_encode($triggeredPipelines))) {
            throw new Raven_Exception('Failed to write to ' . $file);
        }
    
  3. Log in to comment