Can't trigger pipeline or create pull request

Issue #74 resolved
Michael Delle created an issue

I get a 500 error running the code below. If I use a direct cURL call to bitbucket's API, it works.

Using bitbucket-api version 1.1.1

    $payload = json_decode(file_get_contents('php://input'));
    /*
    {
        "account": "account",
        "repo": "repo",
        "branch": "master",
        "custom_pipeline": "deploy-to-production"
    }
    */

    # Set Bitbucket credentials.
    $oauth_params = array(
        'client_id'     => getenv('BITBUCKET_KEY'),
        'client_secret' => getenv('BITBUCKET_SECRET')
    );

    $bitbucket = new Api();
    $bitbucket->getClient()->addListener(
        new OAuth2Listener($oauth_params)
    );

    $params = array(
        'type' => array(
            'ref_type' => 'branch',
            'type'     => 'pipeline_ref_target',
            'ref_name' => $payload->branch
        )
    );

    if (isset($payload->custom_pipeline)) {
        $pattern = $payload->custom_pipeline;

        $params['type']['selector'] = array(
            'type'    => 'custom',
            'pattern' => $pattern
        );
    }

    $pipeline = $bitbucket->api('Repositories\Pipelines');

    var_dump($pipeline->create($payload->account, $payload->repo, $params));

Response:

Buzz\Message\Response Object
(
    [protocolVersion:Buzz\Message\Response:private] => 
    [statusCode:Buzz\Message\Response:private] => 
    [reasonPhrase:Buzz\Message\Response:private] => 
    [headers:Buzz\Message\AbstractMessage:private] => Array
        (
            [0] => HTTP/1.1 500 Internal Server Error
            [1] => Server: nginx
            [2] => X-B3-ParentSpanId: 0000000000000000
            [3] => X-Cache: Error from cloudfront
            [4] => Content-Type: application/json; charset=utf-8
            [5] => X-B3-TraceId: 99ef738d1c35bf56
            [6] => X-OAuth-Scopes: pipeline:write, pullrequest:write
            [7] => Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
            [8] => Date: Wed, 13 Jun 2018 19:59:26 GMT
            [9] => X-Served-By: app-143
            [10] => X-B3-SpanID: 99ef738d1c35bf56
            [11] => ETag: "f5c4ad5bb25fd53724ffe120f9403f99"
            [12] => X-Static-Version: 8c65103bd86f
            [13] => X-Credential-Type: oauth2
            [14] => X-Render-Time: 0.148756027222
            [15] => Connection: close
            [16] => X-Request-Count: 752
            [17] => X-Frame-Options: SAMEORIGIN
            [18] => X-Version: 8c65103bd86f
            [19] => Content-Length: 144
        )

    [content:Buzz\Message\AbstractMessage:private] => {"arguments": {"spanId": "99ef738d1c35bf56", "parentSpanId": "0000000000000000", "traceId": "99ef738d1c35bf56"}, "key": "Internal Server Error"}
)

I get a 400 error when trying to create a pull request using the code in the example (I switch the account & repo to my own, and change the branch name.

Example: https://gentlero.bitbucket.io/bitbucket-api/1.0/examples/repositories/pull-requests.html

Creating comments on existing pull requests work fine.

Comments (10)

  1. Michael Delle reporter

    @vimishor Works with version 1.1.2. Thank you for the quick fix!

    Note: I was also making the mistake of sending the "type" param when it should be "target" ($params['target']).

    Maybe the PipelinesTest should changed to use target? https://bitbucket.org/gentlero/bitbucket-api/src/8aa84ffbe0846da6a05fc89cdfbc159c622e9a4e/test/Bitbucket/Tests/API/Repositories/PipelinesTest.php?at=develop&fileviewer=file-view-default#PipelinesTest.php-31

    Bitbucket API: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pipelines/#post

  2. Log in to comment